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 |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 111 | private static final int VERSION = 142 + (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 | |
| 153 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 154 | public MyHandler(Looper looper) { |
| 155 | super(looper, null, true); |
| 156 | } |
| 157 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 158 | @Override |
| 159 | public void handleMessage(Message msg) { |
| 160 | BatteryCallback cb = mCallback; |
| 161 | switch (msg.what) { |
| 162 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 163 | synchronized (BatteryStatsImpl.this) { |
| 164 | updateCpuTimeLocked(); |
| 165 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 166 | if (cb != null) { |
| 167 | cb.batteryNeedsCpuUpdate(); |
| 168 | } |
| 169 | break; |
| 170 | case MSG_REPORT_POWER_CHANGE: |
| 171 | if (cb != null) { |
| 172 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 173 | } |
| 174 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 175 | case MSG_REPORT_CHARGING: |
| 176 | if (cb != null) { |
| 177 | final String action; |
| 178 | synchronized (BatteryStatsImpl.this) { |
| 179 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 180 | : BatteryManager.ACTION_DISCHARGING; |
| 181 | } |
| 182 | Intent intent = new Intent(action); |
| 183 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 184 | cb.batterySendBroadcast(intent); |
| 185 | } |
| 186 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 191 | public interface Clocks { |
| 192 | public long elapsedRealtime(); |
| 193 | public long uptimeMillis(); |
| 194 | } |
| 195 | |
| 196 | public static class SystemClocks implements Clocks { |
| 197 | public long elapsedRealtime() { |
| 198 | return SystemClock.elapsedRealtime(); |
| 199 | } |
| 200 | |
| 201 | public long uptimeMillis() { |
| 202 | return SystemClock.uptimeMillis(); |
| 203 | } |
| 204 | } |
| 205 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 206 | public interface ExternalStatsSync { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 207 | public static final int UPDATE_CPU = 0x01; |
| 208 | public static final int UPDATE_WIFI = 0x02; |
| 209 | public static final int UPDATE_RADIO = 0x04; |
| 210 | public static final int UPDATE_BT = 0x08; |
| 211 | public static final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT; |
| 212 | |
| 213 | void scheduleSync(String reason, int flags); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 214 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 217 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 218 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 219 | |
| 220 | private BatteryCallback mCallback; |
| 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 223 | * Mapping isolated uids to the actual owning app uid. |
| 224 | */ |
| 225 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 226 | |
| 227 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | * The statistics we have collected organized by uids. |
| 229 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 230 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
| 232 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 233 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 234 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 235 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 236 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 237 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 238 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 239 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 240 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 241 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 242 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 243 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 244 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 245 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 246 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 247 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 248 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 249 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 250 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 252 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 253 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | // These are the objects that will want to do something when the device |
| 256 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 257 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 258 | |
| 259 | // These are the objects that will want to do something when the device |
| 260 | // is unplugged from power *and* the screen is off. |
| 261 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 262 | |
| 263 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 264 | // CPU update, even if we aren't currently running wake locks. |
| 265 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 266 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 267 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 268 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 269 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 270 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 271 | long mHistoryBaseTime; |
| 272 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 273 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 274 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 275 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 276 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 277 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 278 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 279 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 280 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 281 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 282 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 283 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 284 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 285 | int[] mReadHistoryUids; |
| 286 | int mReadHistoryChars; |
| 287 | int mNextHistoryTagIdx = 0; |
| 288 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 289 | int mHistoryBufferLastPos = -1; |
| 290 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 291 | int mActiveHistoryStates = 0xffffffff; |
| 292 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 293 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 294 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 295 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 296 | |
| 297 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 298 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 299 | HistoryItem mHistory; |
| 300 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 301 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 302 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 303 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 304 | // Used by computeHistoryStepDetails |
| 305 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 306 | byte mLastHistoryStepLevel = 0; |
| 307 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 308 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 309 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 310 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 311 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 312 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 313 | */ |
| 314 | long mLastStepCpuUserTime; |
| 315 | long mCurStepCpuUserTime; |
| 316 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 317 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 318 | */ |
| 319 | long mLastStepCpuSystemTime; |
| 320 | long mCurStepCpuSystemTime; |
| 321 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 322 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 323 | */ |
| 324 | long mLastStepStatUserTime; |
| 325 | long mLastStepStatSystemTime; |
| 326 | long mLastStepStatIOWaitTime; |
| 327 | long mLastStepStatIrqTime; |
| 328 | long mLastStepStatSoftIrqTime; |
| 329 | long mLastStepStatIdleTime; |
| 330 | long mCurStepStatUserTime; |
| 331 | long mCurStepStatSystemTime; |
| 332 | long mCurStepStatIOWaitTime; |
| 333 | long mCurStepStatIrqTime; |
| 334 | long mCurStepStatSoftIrqTime; |
| 335 | long mCurStepStatIdleTime; |
| 336 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 337 | private HistoryItem mHistoryIterator; |
| 338 | private boolean mReadOverflow; |
| 339 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | int mStartCount; |
| 342 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 343 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 344 | String mStartPlatformVersion; |
| 345 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | long mUptime; |
| 348 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | long mRealtime; |
| 350 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 351 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 352 | int mWakeLockNesting; |
| 353 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 354 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 355 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 356 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 357 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 358 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 359 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 360 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 361 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 362 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 363 | boolean mInteractive; |
| 364 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 365 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 366 | boolean mPowerSaveModeEnabled; |
| 367 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 368 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 369 | boolean mDeviceIdling; |
| 370 | StopwatchTimer mDeviceIdlingTimer; |
| 371 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 372 | boolean mDeviceLightIdling; |
| 373 | StopwatchTimer mDeviceLightIdlingTimer; |
| 374 | |
| 375 | int mDeviceIdleMode; |
| 376 | long mLastIdleTimeStart; |
| 377 | long mLongestLightIdleTime; |
| 378 | long mLongestFullIdleTime; |
| 379 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 380 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 383 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 384 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 385 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 386 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 387 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 388 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 389 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 390 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 391 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 392 | StopwatchTimer mFlashlightOnTimer; |
| 393 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 394 | int mCameraOnNesting; |
| 395 | StopwatchTimer mCameraOnTimer; |
| 396 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 397 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 398 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 399 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 400 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 401 | |
| 402 | StopwatchTimer mPhoneSignalScanningTimer; |
| 403 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 404 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 405 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 406 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 407 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 408 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 409 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 410 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 411 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 412 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 413 | /** |
| 414 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 415 | */ |
| 416 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 417 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 418 | /** |
| 419 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 420 | */ |
| 421 | ControllerActivityCounterImpl mBluetoothActivity; |
| 422 | |
| 423 | /** |
| 424 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 425 | */ |
| 426 | ControllerActivityCounterImpl mModemActivity; |
| 427 | |
| 428 | /** |
| 429 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 430 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 431 | */ |
| 432 | boolean mHasWifiReporting = false; |
| 433 | |
| 434 | /** |
| 435 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 436 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 437 | */ |
| 438 | boolean mHasBluetoothReporting = false; |
| 439 | |
| 440 | /** |
| 441 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 442 | * the first Modem energy report. See {@link #mModemActivity}. |
| 443 | */ |
| 444 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 445 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 446 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 447 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 448 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 449 | boolean mGlobalWifiRunning; |
| 450 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 451 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 452 | int mWifiState = -1; |
| 453 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 454 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 455 | int mWifiSupplState = -1; |
| 456 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 457 | |
| 458 | int mWifiSignalStrengthBin = -1; |
| 459 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 460 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 461 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 462 | int mBluetoothScanNesting; |
| 463 | StopwatchTimer mBluetoothScanTimer; |
| 464 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 465 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 466 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 467 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 468 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 469 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 470 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 471 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 472 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 473 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | /** |
| 476 | * These provide time bases that discount the time the device is plugged |
| 477 | * in to power. |
| 478 | */ |
| 479 | boolean mOnBattery; |
| 480 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 481 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 482 | /** |
| 483 | * External reporting of whether the device is actually charging. |
| 484 | */ |
| 485 | boolean mCharging = true; |
| 486 | int mLastChargingStateLevel; |
| 487 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 488 | /* |
| 489 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 490 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 491 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 492 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 493 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 494 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 495 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 496 | int mLowDischargeAmountSinceCharge; |
| 497 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 498 | int mDischargeScreenOnUnplugLevel; |
| 499 | int mDischargeScreenOffUnplugLevel; |
| 500 | int mDischargeAmountScreenOn; |
| 501 | int mDischargeAmountScreenOnSinceCharge; |
| 502 | int mDischargeAmountScreenOff; |
| 503 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 504 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 505 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 506 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 507 | int mInitStepMode = 0; |
| 508 | int mCurStepMode = 0; |
| 509 | int mModStepMode = 0; |
| 510 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 511 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 512 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 513 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 514 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 515 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 516 | |
| 517 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 518 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 519 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 520 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 521 | |
| 522 | static final int MAX_DAILY_ITEMS = 10; |
| 523 | |
| 524 | long mDailyStartTime = 0; |
| 525 | long mNextMinDailyDeadline = 0; |
| 526 | long mNextMaxDailyDeadline = 0; |
| 527 | |
| 528 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 531 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 532 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 533 | private int mPhoneServiceStateRaw = -1; |
| 534 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 535 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 536 | private int mNumConnectivityChange; |
| 537 | private int mLoadedNumConnectivityChange; |
| 538 | private int mUnpluggedNumConnectivityChange; |
| 539 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 540 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 541 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 542 | private PowerProfile mPowerProfile; |
| 543 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 544 | /* |
| 545 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 546 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 547 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 548 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 549 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 550 | return mKernelWakelockStats; |
| 551 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 552 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 553 | String mLastWakeupReason = null; |
| 554 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 555 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 556 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 557 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 558 | return mWakeupReasonStats; |
| 559 | } |
| 560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 562 | this(new SystemClocks()); |
| 563 | } |
| 564 | |
| 565 | public BatteryStatsImpl(Clocks clocks) { |
| 566 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 567 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 568 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 569 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 570 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 571 | mExternalSync = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 572 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 575 | private void init(Clocks clocks) { |
| 576 | mClocks = clocks; |
| 577 | mMobileNetworkStats = new NetworkStats[] { |
| 578 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 579 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 580 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 581 | }; |
| 582 | mWifiNetworkStats = new NetworkStats[] { |
| 583 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 584 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 585 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 586 | }; |
| 587 | } |
| 588 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 589 | public static interface TimeBaseObs { |
| 590 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 591 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 592 | } |
| 593 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 594 | // methods are protected not private to be VisibleForTesting |
| 595 | public static class TimeBase { |
| 596 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 597 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 598 | protected long mUptime; |
| 599 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 600 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 601 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 602 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 603 | protected long mPastUptime; |
| 604 | protected long mUptimeStart; |
| 605 | protected long mPastRealtime; |
| 606 | protected long mRealtimeStart; |
| 607 | protected long mUnpluggedUptime; |
| 608 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 609 | |
| 610 | public void dump(PrintWriter pw, String prefix) { |
| 611 | StringBuilder sb = new StringBuilder(128); |
| 612 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 613 | sb.setLength(0); |
| 614 | sb.append(prefix); |
| 615 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 616 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 617 | pw.println(sb.toString()); |
| 618 | sb.setLength(0); |
| 619 | sb.append(prefix); |
| 620 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 621 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 622 | pw.println(sb.toString()); |
| 623 | sb.setLength(0); |
| 624 | sb.append(prefix); |
| 625 | sb.append("mPastUptime="); |
| 626 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 627 | formatTimeMs(sb, mUptimeStart / 1000); |
| 628 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 629 | pw.println(sb.toString()); |
| 630 | sb.setLength(0); |
| 631 | sb.append(prefix); |
| 632 | sb.append("mPastRealtime="); |
| 633 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 634 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 635 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 636 | pw.println(sb.toString()); |
| 637 | } |
| 638 | |
| 639 | public void add(TimeBaseObs observer) { |
| 640 | mObservers.add(observer); |
| 641 | } |
| 642 | |
| 643 | public void remove(TimeBaseObs observer) { |
| 644 | if (!mObservers.remove(observer)) { |
| 645 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 646 | } |
| 647 | } |
| 648 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 649 | public boolean hasObserver(TimeBaseObs observer) { |
| 650 | return mObservers.contains(observer); |
| 651 | } |
| 652 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 653 | public void init(long uptime, long realtime) { |
| 654 | mRealtime = 0; |
| 655 | mUptime = 0; |
| 656 | mPastUptime = 0; |
| 657 | mPastRealtime = 0; |
| 658 | mUptimeStart = uptime; |
| 659 | mRealtimeStart = realtime; |
| 660 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 661 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 662 | } |
| 663 | |
| 664 | public void reset(long uptime, long realtime) { |
| 665 | if (!mRunning) { |
| 666 | mPastUptime = 0; |
| 667 | mPastRealtime = 0; |
| 668 | } else { |
| 669 | mUptimeStart = uptime; |
| 670 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 671 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 672 | // 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] | 673 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 674 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 675 | mUnpluggedRealtime = getRealtime(realtime); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | public long computeUptime(long curTime, int which) { |
| 680 | switch (which) { |
| 681 | case STATS_SINCE_CHARGED: |
| 682 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 683 | case STATS_CURRENT: |
| 684 | return getUptime(curTime); |
| 685 | case STATS_SINCE_UNPLUGGED: |
| 686 | return getUptime(curTime) - mUnpluggedUptime; |
| 687 | } |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | public long computeRealtime(long curTime, int which) { |
| 692 | switch (which) { |
| 693 | case STATS_SINCE_CHARGED: |
| 694 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 695 | case STATS_CURRENT: |
| 696 | return getRealtime(curTime); |
| 697 | case STATS_SINCE_UNPLUGGED: |
| 698 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 699 | } |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | public long getUptime(long curTime) { |
| 704 | long time = mPastUptime; |
| 705 | if (mRunning) { |
| 706 | time += curTime - mUptimeStart; |
| 707 | } |
| 708 | return time; |
| 709 | } |
| 710 | |
| 711 | public long getRealtime(long curTime) { |
| 712 | long time = mPastRealtime; |
| 713 | if (mRunning) { |
| 714 | time += curTime - mRealtimeStart; |
| 715 | } |
| 716 | return time; |
| 717 | } |
| 718 | |
| 719 | public long getUptimeStart() { |
| 720 | return mUptimeStart; |
| 721 | } |
| 722 | |
| 723 | public long getRealtimeStart() { |
| 724 | return mRealtimeStart; |
| 725 | } |
| 726 | |
| 727 | public boolean isRunning() { |
| 728 | return mRunning; |
| 729 | } |
| 730 | |
| 731 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 732 | if (mRunning != running) { |
| 733 | mRunning = running; |
| 734 | if (running) { |
| 735 | mUptimeStart = uptime; |
| 736 | mRealtimeStart = realtime; |
| 737 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 738 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 739 | |
| 740 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 741 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 742 | } |
| 743 | } else { |
| 744 | mPastUptime += uptime - mUptimeStart; |
| 745 | mPastRealtime += realtime - mRealtimeStart; |
| 746 | |
| 747 | long batteryUptime = getUptime(uptime); |
| 748 | long batteryRealtime = getRealtime(realtime); |
| 749 | |
| 750 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 751 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 752 | } |
| 753 | } |
| 754 | return true; |
| 755 | } |
| 756 | return false; |
| 757 | } |
| 758 | |
| 759 | public void readSummaryFromParcel(Parcel in) { |
| 760 | mUptime = in.readLong(); |
| 761 | mRealtime = in.readLong(); |
| 762 | } |
| 763 | |
| 764 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 765 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 766 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 767 | } |
| 768 | |
| 769 | public void readFromParcel(Parcel in) { |
| 770 | mRunning = false; |
| 771 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 772 | mPastUptime = in.readLong(); |
| 773 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 774 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 775 | mPastRealtime = in.readLong(); |
| 776 | mRealtimeStart = in.readLong(); |
| 777 | mUnpluggedUptime = in.readLong(); |
| 778 | mUnpluggedRealtime = in.readLong(); |
| 779 | } |
| 780 | |
| 781 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 782 | final long runningUptime = getUptime(uptime); |
| 783 | final long runningRealtime = getRealtime(realtime); |
| 784 | out.writeLong(mUptime); |
| 785 | out.writeLong(runningUptime); |
| 786 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 787 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 788 | out.writeLong(runningRealtime); |
| 789 | out.writeLong(mRealtimeStart); |
| 790 | out.writeLong(mUnpluggedUptime); |
| 791 | out.writeLong(mUnpluggedRealtime); |
| 792 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 796 | * State for keeping track of counting information. |
| 797 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 798 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 799 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 800 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 801 | int mLoadedCount; |
| 802 | int mLastCount; |
| 803 | int mUnpluggedCount; |
| 804 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 805 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 806 | Counter(TimeBase timeBase, Parcel in) { |
| 807 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 808 | mPluggedCount = in.readInt(); |
| 809 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 810 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 811 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 812 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 813 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 816 | Counter(TimeBase timeBase) { |
| 817 | mTimeBase = timeBase; |
| 818 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 819 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 820 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 821 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 822 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 823 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 824 | out.writeInt(mUnpluggedCount); |
| 825 | } |
| 826 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 827 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 828 | mUnpluggedCount = mPluggedCount; |
| 829 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 832 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 833 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 834 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 835 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 836 | /** |
| 837 | * Writes a possibly null Counter to a Parcel. |
| 838 | * |
| 839 | * @param out the Parcel to be written to. |
| 840 | * @param counter a Counter, or null. |
| 841 | */ |
| 842 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 843 | if (counter == null) { |
| 844 | out.writeInt(0); // indicates null |
| 845 | return; |
| 846 | } |
| 847 | out.writeInt(1); // indicates non-null |
| 848 | |
| 849 | counter.writeToParcel(out); |
| 850 | } |
| 851 | |
| 852 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 853 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 854 | int val = mCount.get(); |
| 855 | if (which == STATS_SINCE_UNPLUGGED) { |
| 856 | val -= mUnpluggedCount; |
| 857 | } else if (which != STATS_SINCE_CHARGED) { |
| 858 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | return val; |
| 862 | } |
| 863 | |
| 864 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 865 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 866 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 867 | + " mUnpluggedCount=" + mUnpluggedCount |
| 868 | + " mPluggedCount=" + mPluggedCount); |
| 869 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 870 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 871 | void stepAtomic() { |
| 872 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 875 | /** |
| 876 | * Clear state of this counter. |
| 877 | */ |
| 878 | void reset(boolean detachIfReset) { |
| 879 | mCount.set(0); |
| 880 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 881 | if (detachIfReset) { |
| 882 | detach(); |
| 883 | } |
| 884 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 885 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 886 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 887 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 888 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 889 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 890 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 891 | int count = mCount.get(); |
| 892 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 896 | mLoadedCount = in.readInt(); |
| 897 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 898 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 899 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 900 | } |
| 901 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 902 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 903 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 904 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 905 | long mCount; |
| 906 | long mLoadedCount; |
| 907 | long mLastCount; |
| 908 | long mUnpluggedCount; |
| 909 | long mPluggedCount; |
| 910 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 911 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 912 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 913 | mPluggedCount = in.readLong(); |
| 914 | mCount = mPluggedCount; |
| 915 | mLoadedCount = in.readLong(); |
| 916 | mLastCount = 0; |
| 917 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 918 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 921 | LongSamplingCounter(TimeBase timeBase) { |
| 922 | mTimeBase = timeBase; |
| 923 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | public void writeToParcel(Parcel out) { |
| 927 | out.writeLong(mCount); |
| 928 | out.writeLong(mLoadedCount); |
| 929 | out.writeLong(mUnpluggedCount); |
| 930 | } |
| 931 | |
| 932 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 933 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 934 | mUnpluggedCount = mPluggedCount; |
| 935 | mCount = mPluggedCount; |
| 936 | } |
| 937 | |
| 938 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 939 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 940 | mPluggedCount = mCount; |
| 941 | } |
| 942 | |
| 943 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 944 | long val = mCount; |
| 945 | if (which == STATS_SINCE_UNPLUGGED) { |
| 946 | val -= mUnpluggedCount; |
| 947 | } else if (which != STATS_SINCE_CHARGED) { |
| 948 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | return val; |
| 952 | } |
| 953 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 954 | @Override |
| 955 | public void logState(Printer pw, String prefix) { |
| 956 | pw.println(prefix + "mCount=" + mCount |
| 957 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 958 | + " mUnpluggedCount=" + mUnpluggedCount |
| 959 | + " mPluggedCount=" + mPluggedCount); |
| 960 | } |
| 961 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 962 | void addCountLocked(long count) { |
| 963 | mCount += count; |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Clear state of this counter. |
| 968 | */ |
| 969 | void reset(boolean detachIfReset) { |
| 970 | mCount = 0; |
| 971 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 972 | if (detachIfReset) { |
| 973 | detach(); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 978 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | void writeSummaryFromParcelLocked(Parcel out) { |
| 982 | out.writeLong(mCount); |
| 983 | } |
| 984 | |
| 985 | void readSummaryFromParcelLocked(Parcel in) { |
| 986 | mLoadedCount = in.readLong(); |
| 987 | mCount = mLoadedCount; |
| 988 | mLastCount = 0; |
| 989 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 990 | } |
| 991 | } |
| 992 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 993 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | * State for keeping track of timing information. |
| 995 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 996 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 997 | protected final Clocks mClocks; |
| 998 | protected final int mType; |
| 999 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1000 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1001 | protected int mCount; |
| 1002 | protected int mLoadedCount; |
| 1003 | protected int mLastCount; |
| 1004 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | // Times are in microseconds for better accuracy when dividing by the |
| 1007 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | /** |
| 1010 | * The total time we have accumulated since the start of the original |
| 1011 | * boot, to the last time something interesting happened in the |
| 1012 | * current run. |
| 1013 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1014 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | /** |
| 1017 | * The total time we loaded for the previous runs. Subtract this from |
| 1018 | * mTotalTime to find the time for the current run of the system. |
| 1019 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1020 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | /** |
| 1023 | * The run time of the last run of the system, as loaded from the |
| 1024 | * saved data. |
| 1025 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1026 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | /** |
| 1029 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1030 | * this from mTotalTime to find the time since the last unplug from |
| 1031 | * power. |
| 1032 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1033 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1034 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1035 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1036 | * The total time this timer has been running until the latest mark has been set. |
| 1037 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1038 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1039 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1040 | |
| 1041 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1042 | * Constructs from a parcel. |
| 1043 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1044 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1045 | * @param in |
| 1046 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1047 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1048 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1050 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | mCount = in.readInt(); |
| 1053 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1054 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | mUnpluggedCount = in.readInt(); |
| 1056 | mTotalTime = in.readLong(); |
| 1057 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1058 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1060 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1061 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1062 | 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] | 1063 | } |
| 1064 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1065 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1066 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1068 | mTimeBase = timeBase; |
| 1069 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1071 | |
| 1072 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1073 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1074 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1075 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1076 | /** |
| 1077 | * Clear state of this timer. Returns true if the timer is inactive |
| 1078 | * so can be completely dropped. |
| 1079 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1080 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1081 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1082 | mCount = mLoadedCount = mLastCount = 0; |
| 1083 | if (detachIfReset) { |
| 1084 | detach(); |
| 1085 | } |
| 1086 | return true; |
| 1087 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1088 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1089 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1090 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1091 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1092 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1093 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1094 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1095 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1096 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1099 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1102 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | } |
| 1104 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1105 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1106 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1108 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1110 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1111 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1112 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1113 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | if (DEBUG && mType < 0) { |
| 1115 | Log.v(TAG, "unplug #" + mType |
| 1116 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1117 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1118 | } |
| 1119 | } |
| 1120 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1121 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1122 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1123 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1124 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1125 | + " old mTotalTime=" + mTotalTime); |
| 1126 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1127 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1128 | mCount = computeCurrentCountLocked(); |
| 1129 | if (DEBUG && mType < 0) { |
| 1130 | Log.v(TAG, "plug #" + mType |
| 1131 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | } |
| 1133 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | /** |
| 1136 | * Writes a possibly null Timer to a Parcel. |
| 1137 | * |
| 1138 | * @param out the Parcel to be written to. |
| 1139 | * @param timer a Timer, or null. |
| 1140 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1141 | 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] | 1142 | if (timer == null) { |
| 1143 | out.writeInt(0); // indicates null |
| 1144 | return; |
| 1145 | } |
| 1146 | out.writeInt(1); // indicates non-null |
| 1147 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1148 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1152 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1153 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1154 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1155 | val -= mUnpluggedTime; |
| 1156 | } else if (which != STATS_SINCE_CHARGED) { |
| 1157 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | return val; |
| 1161 | } |
| 1162 | |
| 1163 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1164 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1165 | int val = computeCurrentCountLocked(); |
| 1166 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1167 | val -= mUnpluggedCount; |
| 1168 | } else if (which != STATS_SINCE_CHARGED) { |
| 1169 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | return val; |
| 1173 | } |
| 1174 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1175 | @Override |
| 1176 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1177 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1178 | return val - mTimeBeforeMark; |
| 1179 | } |
| 1180 | |
| 1181 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1182 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1183 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1185 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1186 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1188 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1190 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1191 | |
| 1192 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1193 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1194 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1195 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1196 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1199 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1200 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1201 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1202 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1203 | mUnpluggedTime = mTotalTime; |
| 1204 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1205 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1206 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1207 | |
| 1208 | // When reading the summary, we set the mark to be the latest information. |
| 1209 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1212 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1213 | /** |
| 1214 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1215 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1216 | * of the value is recorded. |
| 1217 | * |
| 1218 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1219 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1220 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1221 | * expected to increase monotonically from that point on. |
| 1222 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1223 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1224 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1225 | /** |
| 1226 | * The most recent reported count from /proc/wakelocks. |
| 1227 | */ |
| 1228 | int mCurrentReportedCount; |
| 1229 | |
| 1230 | /** |
| 1231 | * The reported count from /proc/wakelocks when unplug() was last |
| 1232 | * called. |
| 1233 | */ |
| 1234 | int mUnpluggedReportedCount; |
| 1235 | |
| 1236 | /** |
| 1237 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1238 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1239 | long mCurrentReportedTotalTime; |
| 1240 | |
| 1241 | |
| 1242 | /** |
| 1243 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1244 | * called. |
| 1245 | */ |
| 1246 | long mUnpluggedReportedTotalTime; |
| 1247 | |
| 1248 | /** |
| 1249 | * Whether we are currently in a discharge cycle. |
| 1250 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1251 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1252 | |
| 1253 | /** |
| 1254 | * Whether we are currently recording reported values. |
| 1255 | */ |
| 1256 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1257 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1258 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1259 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1260 | */ |
| 1261 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1262 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1263 | @VisibleForTesting |
| 1264 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1265 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1266 | mCurrentReportedCount = in.readInt(); |
| 1267 | mUnpluggedReportedCount = in.readInt(); |
| 1268 | mCurrentReportedTotalTime = in.readLong(); |
| 1269 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1270 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1271 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1272 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1273 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1274 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1275 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1276 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1277 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1278 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1279 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1280 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1281 | /** |
| 1282 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1283 | * be less than the values used for a previous invocation. |
| 1284 | */ |
| 1285 | public void endSample() { |
| 1286 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1287 | mCount = computeCurrentCountLocked(); |
| 1288 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1289 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1290 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1291 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1292 | public void setUpdateVersion(int version) { |
| 1293 | mUpdateVersion = version; |
| 1294 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1295 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1296 | public int getUpdateVersion() { |
| 1297 | return mUpdateVersion; |
| 1298 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1299 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1300 | /** |
| 1301 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1302 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1303 | * |
| 1304 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1305 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1306 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1307 | * increasing sample. |
| 1308 | * |
| 1309 | * @param totalTime total time of sample in microseconds. |
| 1310 | * @param count total number of times the event being sampled occurred. |
| 1311 | */ |
| 1312 | public void update(long totalTime, int count) { |
| 1313 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1314 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1315 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1316 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1317 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1318 | |
| 1319 | mTrackingReportedValues = true; |
| 1320 | |
| 1321 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1322 | endSample(); |
| 1323 | } |
| 1324 | |
| 1325 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1326 | mCurrentReportedCount = count; |
| 1327 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1328 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1329 | /** |
| 1330 | * Adds deltaTime and deltaCount to the current sample. |
| 1331 | * |
| 1332 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1333 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1334 | */ |
| 1335 | public void add(long deltaTime, int deltaCount) { |
| 1336 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1339 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1340 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1341 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1342 | if (mTrackingReportedValues) { |
| 1343 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1344 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1345 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1346 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1349 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1350 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1351 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1352 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1353 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1354 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1355 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1356 | public void logState(Printer pw, String prefix) { |
| 1357 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1358 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1359 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1360 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1361 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1362 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1363 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1364 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1365 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1366 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1367 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1368 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1369 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1370 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1371 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1372 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1373 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1374 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1375 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1376 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1377 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1378 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1379 | out.writeInt(mCurrentReportedCount); |
| 1380 | out.writeInt(mUnpluggedReportedCount); |
| 1381 | out.writeLong(mCurrentReportedTotalTime); |
| 1382 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1383 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1384 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1385 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1386 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1387 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1388 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1389 | mTrackingReportedValues = false; |
| 1390 | mUnpluggedReportedTotalTime = 0; |
| 1391 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1392 | return true; |
| 1393 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1394 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 1395 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1396 | public void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1397 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1398 | out.writeLong(mCurrentReportedTotalTime); |
| 1399 | out.writeInt(mCurrentReportedCount); |
| 1400 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1401 | } |
| 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 readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1405 | super.readSummaryFromParcelLocked(in); |
| 1406 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1407 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1408 | mTrackingReportedValues = in.readInt() == 1; |
| 1409 | } |
| 1410 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1411 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1412 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1413 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1414 | * for a pre-determined amount. |
| 1415 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1416 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1417 | final Uid mUid; |
| 1418 | |
| 1419 | /** |
| 1420 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1421 | */ |
| 1422 | long mLastAddedTime; |
| 1423 | |
| 1424 | /** |
| 1425 | * The last duration that we added to the timer. This is in microseconds. |
| 1426 | */ |
| 1427 | long mLastAddedDuration; |
| 1428 | |
| 1429 | /** |
| 1430 | * Whether we are currently in a discharge cycle. |
| 1431 | */ |
| 1432 | boolean mInDischarge; |
| 1433 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1434 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1435 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1436 | mUid = uid; |
| 1437 | mLastAddedTime = in.readLong(); |
| 1438 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1439 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1440 | } |
| 1441 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1442 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1443 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1444 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1445 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1449 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1450 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1451 | out.writeLong(mLastAddedTime); |
| 1452 | out.writeLong(mLastAddedDuration); |
| 1453 | } |
| 1454 | |
| 1455 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1456 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1457 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1458 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1459 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1463 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1464 | recomputeLastDuration(elapsedRealtime, false); |
| 1465 | mInDischarge = true; |
| 1466 | // If we are still within the last added duration, then re-added whatever remains. |
| 1467 | if (mLastAddedTime == elapsedRealtime) { |
| 1468 | mTotalTime += mLastAddedDuration; |
| 1469 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1470 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | @Override |
| 1474 | public void logState(Printer pw, String prefix) { |
| 1475 | super.logState(pw, prefix); |
| 1476 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1477 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1478 | } |
| 1479 | |
| 1480 | private long computeOverage(long curTime) { |
| 1481 | if (mLastAddedTime > 0) { |
| 1482 | return mLastTime + mLastAddedDuration - curTime; |
| 1483 | } |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
| 1487 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1488 | final long overage = computeOverage(curTime); |
| 1489 | if (overage > 0) { |
| 1490 | // Aborting before the duration ran out -- roll back the remaining |
| 1491 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1492 | // actually add the time. |
| 1493 | if (mInDischarge) { |
| 1494 | mTotalTime -= overage; |
| 1495 | } |
| 1496 | if (abort) { |
| 1497 | mLastAddedTime = 0; |
| 1498 | } else { |
| 1499 | mLastAddedTime = curTime; |
| 1500 | mLastAddedDuration -= overage; |
| 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1506 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1507 | recomputeLastDuration(now, true); |
| 1508 | mLastAddedTime = now; |
| 1509 | mLastAddedDuration = durationMillis * 1000; |
| 1510 | if (mInDischarge) { |
| 1511 | mTotalTime += mLastAddedDuration; |
| 1512 | mCount++; |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1517 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1518 | recomputeLastDuration(now, true); |
| 1519 | } |
| 1520 | |
| 1521 | @Override |
| 1522 | protected int computeCurrentCountLocked() { |
| 1523 | return mCount; |
| 1524 | } |
| 1525 | |
| 1526 | @Override |
| 1527 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1528 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1529 | if (overage > 0) { |
| 1530 | return mTotalTime = overage; |
| 1531 | } |
| 1532 | return mTotalTime; |
| 1533 | } |
| 1534 | |
| 1535 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1536 | public boolean reset(boolean detachIfReset) { |
| 1537 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1538 | recomputeLastDuration(now, true); |
| 1539 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1540 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1541 | return !stillActive; |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1546 | * State for keeping track of timing information. |
| 1547 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1548 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1549 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1550 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1551 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1552 | int mNesting; |
| 1553 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1554 | /** |
| 1555 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1556 | * subtract this from the current battery time to find the amount of |
| 1557 | * time we have been running since we last computed an update. |
| 1558 | */ |
| 1559 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1560 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1561 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1562 | * 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] | 1563 | * was actually held for an interesting duration. |
| 1564 | */ |
| 1565 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1566 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1567 | long mTimeout; |
| 1568 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1569 | /** |
| 1570 | * For partial wake locks, keep track of whether we are in the list |
| 1571 | * to consume CPU cycles. |
| 1572 | */ |
| 1573 | boolean mInList; |
| 1574 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1575 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1576 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1577 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1578 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1579 | mTimerPool = timerPool; |
| 1580 | mUpdateTime = in.readLong(); |
| 1581 | } |
| 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) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1585 | super(clocks, type, timeBase); |
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 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1589 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1590 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1591 | mTimeout = timeout; |
| 1592 | } |
| 1593 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1594 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1595 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1596 | out.writeLong(mUpdateTime); |
| 1597 | } |
| 1598 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1599 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1600 | if (mNesting > 0) { |
| 1601 | if (DEBUG && mType < 0) { |
| 1602 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1603 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1604 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1605 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1606 | if (DEBUG && mType < 0) { |
| 1607 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | public void logState(Printer pw, String prefix) { |
| 1613 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1614 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | + " mAcquireTime=" + mAcquireTime); |
| 1616 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1617 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1618 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1620 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1621 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | if (mTimerPool != null) { |
| 1623 | // Accumulate time to all currently active timers before adding |
| 1624 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1625 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | // Add this timer to the active pool |
| 1627 | mTimerPool.add(this); |
| 1628 | } |
| 1629 | // Increment the count |
| 1630 | mCount++; |
| 1631 | mAcquireTime = mTotalTime; |
| 1632 | if (DEBUG && mType < 0) { |
| 1633 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1634 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1635 | + " mAcquireTime=" + mAcquireTime); |
| 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1640 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1641 | return mNesting > 0; |
| 1642 | } |
| 1643 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1644 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | // Ignore attempt to stop a timer that isn't running |
| 1646 | if (mNesting == 0) { |
| 1647 | return; |
| 1648 | } |
| 1649 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1650 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | if (mTimerPool != null) { |
| 1652 | // Accumulate time to all active counters, scaled by the total |
| 1653 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1654 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | // Remove this timer from the active pool |
| 1656 | mTimerPool.remove(this); |
| 1657 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | mNesting = 1; |
| 1659 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1660 | mNesting = 0; |
| 1661 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | if (DEBUG && mType < 0) { |
| 1664 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1665 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1666 | + " mAcquireTime=" + mAcquireTime); |
| 1667 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | if (mTotalTime == mAcquireTime) { |
| 1670 | // If there was no change in the time, then discard this |
| 1671 | // count. A somewhat cheezy strategy, but hey. |
| 1672 | mCount--; |
| 1673 | } |
| 1674 | } |
| 1675 | } |
| 1676 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1677 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1678 | if (mNesting > 0) { |
| 1679 | mNesting = 1; |
| 1680 | stopRunningLocked(elapsedRealtimeMs); |
| 1681 | } |
| 1682 | } |
| 1683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | // Update the total time for all other running Timers with the same type as this Timer |
| 1685 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1686 | private static long refreshTimersLocked(long batteryRealtime, |
| 1687 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1688 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | final int N = pool.size(); |
| 1690 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1691 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1693 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1694 | final long myTime = heldTime / N; |
| 1695 | if (t == self) { |
| 1696 | selfTime = myTime; |
| 1697 | } |
| 1698 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | } |
| 1700 | t.mUpdateTime = batteryRealtime; |
| 1701 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1702 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | } |
| 1704 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1705 | @Override |
| 1706 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1707 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1708 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1709 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | return mTotalTime + (mNesting > 0 |
| 1711 | ? (curBatteryRealtime - mUpdateTime) |
| 1712 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1713 | : 0); |
| 1714 | } |
| 1715 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1716 | @Override |
| 1717 | protected int computeCurrentCountLocked() { |
| 1718 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1719 | } |
| 1720 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1721 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1722 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1723 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1724 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1725 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1726 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1727 | } |
| 1728 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1729 | return canDetach; |
| 1730 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1731 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1732 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1733 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1734 | super.detach(); |
| 1735 | if (mTimerPool != null) { |
| 1736 | mTimerPool.remove(this); |
| 1737 | } |
| 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 readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1742 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | mNesting = 0; |
| 1744 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1745 | |
| 1746 | /** |
| 1747 | * Set the mark so that we can query later for the total time the timer has |
| 1748 | * accumulated since this point. The timer can be running or not. |
| 1749 | * |
| 1750 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1751 | */ |
| 1752 | public void setMark(long elapsedRealtimeMs) { |
| 1753 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1754 | if (mNesting > 0) { |
| 1755 | // We are running. |
| 1756 | if (mTimerPool != null) { |
| 1757 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1758 | } else { |
| 1759 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1760 | mUpdateTime = batteryRealtime; |
| 1761 | } |
| 1762 | } |
| 1763 | mTimeBeforeMark = mTotalTime; |
| 1764 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1766 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1767 | public abstract class OverflowArrayMap<T> { |
| 1768 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1769 | |
| 1770 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1771 | T mCurOverflow; |
| 1772 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1773 | |
| 1774 | public OverflowArrayMap() { |
| 1775 | } |
| 1776 | |
| 1777 | public ArrayMap<String, T> getMap() { |
| 1778 | return mMap; |
| 1779 | } |
| 1780 | |
| 1781 | public void clear() { |
| 1782 | mMap.clear(); |
| 1783 | mCurOverflow = null; |
| 1784 | mActiveOverflow = null; |
| 1785 | } |
| 1786 | |
| 1787 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1788 | if (name == null) { |
| 1789 | name = ""; |
| 1790 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1791 | mMap.put(name, obj); |
| 1792 | if (OVERFLOW_NAME.equals(name)) { |
| 1793 | mCurOverflow = obj; |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | public void cleanup() { |
| 1798 | if (mActiveOverflow != null) { |
| 1799 | if (mActiveOverflow.size() == 0) { |
| 1800 | mActiveOverflow = null; |
| 1801 | } |
| 1802 | } |
| 1803 | if (mActiveOverflow == null) { |
| 1804 | // There is no currently active overflow, so we should no longer have |
| 1805 | // an overflow entry. |
| 1806 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1807 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1808 | + mMap.get(OVERFLOW_NAME)); |
| 1809 | mMap.remove(OVERFLOW_NAME); |
| 1810 | } |
| 1811 | mCurOverflow = null; |
| 1812 | } else { |
| 1813 | // There is currently active overflow, so we should still have an overflow entry. |
| 1814 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1815 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1816 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1822 | if (name == null) { |
| 1823 | name = ""; |
| 1824 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1825 | T obj = mMap.get(name); |
| 1826 | if (obj != null) { |
| 1827 | return obj; |
| 1828 | } |
| 1829 | |
| 1830 | // No object exists for the given name, but do we currently have it |
| 1831 | // running as part of the overflow? |
| 1832 | if (mActiveOverflow != null) { |
| 1833 | MutableInt over = mActiveOverflow.get(name); |
| 1834 | if (over != null) { |
| 1835 | // We are already actively counting this name in the overflow object. |
| 1836 | obj = mCurOverflow; |
| 1837 | if (obj == null) { |
| 1838 | // Shouldn't be here, but we'll try to recover. |
| 1839 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1840 | obj = mCurOverflow = instantiateObject(); |
| 1841 | mMap.put(OVERFLOW_NAME, obj); |
| 1842 | } |
| 1843 | over.value++; |
| 1844 | return obj; |
| 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | // No object exists for given name nor in the overflow; we need to make |
| 1849 | // a new one. |
| 1850 | final int N = mMap.size(); |
| 1851 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1852 | // Went over the limit on number of objects to track; this one goes |
| 1853 | // in to the overflow. |
| 1854 | obj = mCurOverflow; |
| 1855 | if (obj == null) { |
| 1856 | // Need to start overflow now... |
| 1857 | obj = mCurOverflow = instantiateObject(); |
| 1858 | mMap.put(OVERFLOW_NAME, obj); |
| 1859 | } |
| 1860 | if (mActiveOverflow == null) { |
| 1861 | mActiveOverflow = new ArrayMap<>(); |
| 1862 | } |
| 1863 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1864 | return obj; |
| 1865 | } |
| 1866 | |
| 1867 | // Normal case where we just need to make a new object. |
| 1868 | obj = instantiateObject(); |
| 1869 | mMap.put(name, obj); |
| 1870 | return obj; |
| 1871 | } |
| 1872 | |
| 1873 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1874 | if (name == null) { |
| 1875 | name = ""; |
| 1876 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1877 | T obj = mMap.get(name); |
| 1878 | if (obj != null) { |
| 1879 | return obj; |
| 1880 | } |
| 1881 | |
| 1882 | // No object exists for the given name, but do we currently have it |
| 1883 | // running as part of the overflow? |
| 1884 | if (mActiveOverflow != null) { |
| 1885 | MutableInt over = mActiveOverflow.get(name); |
| 1886 | if (over != null) { |
| 1887 | // We are already actively counting this name in the overflow object. |
| 1888 | obj = mCurOverflow; |
| 1889 | if (obj != null) { |
| 1890 | over.value--; |
| 1891 | if (over.value <= 0) { |
| 1892 | mActiveOverflow.remove(name); |
| 1893 | } |
| 1894 | return obj; |
| 1895 | } |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | // Huh, they are stopping an active operation but we can't find one! |
| 1900 | // That's not good. |
| 1901 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1902 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1903 | + " curoverflow=" + mCurOverflow); |
| 1904 | return null; |
| 1905 | } |
| 1906 | |
| 1907 | public abstract T instantiateObject(); |
| 1908 | } |
| 1909 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 1910 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 1911 | implements Parcelable { |
| 1912 | private final LongSamplingCounter mIdleTimeMillis; |
| 1913 | private final LongSamplingCounter mRxTimeMillis; |
| 1914 | private final LongSamplingCounter[] mTxTimeMillis; |
| 1915 | private final LongSamplingCounter mPowerDrainMaMs; |
| 1916 | |
| 1917 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 1918 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 1919 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 1920 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1921 | for (int i = 0; i < numTxStates; i++) { |
| 1922 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 1923 | } |
| 1924 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 1925 | } |
| 1926 | |
| 1927 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 1928 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1929 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1930 | final int recordedTxStates = in.readInt(); |
| 1931 | if (recordedTxStates != numTxStates) { |
| 1932 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1933 | } |
| 1934 | |
| 1935 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1936 | for (int i = 0; i < numTxStates; i++) { |
| 1937 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 1938 | } |
| 1939 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 1940 | } |
| 1941 | |
| 1942 | public void readSummaryFromParcel(Parcel in) { |
| 1943 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 1944 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 1945 | final int recordedTxStates = in.readInt(); |
| 1946 | if (recordedTxStates != mTxTimeMillis.length) { |
| 1947 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1948 | } |
| 1949 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1950 | counter.readSummaryFromParcelLocked(in); |
| 1951 | } |
| 1952 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 1953 | } |
| 1954 | |
| 1955 | @Override |
| 1956 | public int describeContents() { |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
| 1960 | public void writeSummaryToParcel(Parcel dest) { |
| 1961 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 1962 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 1963 | dest.writeInt(mTxTimeMillis.length); |
| 1964 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1965 | counter.writeSummaryFromParcelLocked(dest); |
| 1966 | } |
| 1967 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 1968 | } |
| 1969 | |
| 1970 | @Override |
| 1971 | public void writeToParcel(Parcel dest, int flags) { |
| 1972 | mIdleTimeMillis.writeToParcel(dest); |
| 1973 | mRxTimeMillis.writeToParcel(dest); |
| 1974 | dest.writeInt(mTxTimeMillis.length); |
| 1975 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1976 | counter.writeToParcel(dest); |
| 1977 | } |
| 1978 | mPowerDrainMaMs.writeToParcel(dest); |
| 1979 | } |
| 1980 | |
| 1981 | public void reset(boolean detachIfReset) { |
| 1982 | mIdleTimeMillis.reset(detachIfReset); |
| 1983 | mRxTimeMillis.reset(detachIfReset); |
| 1984 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1985 | counter.reset(detachIfReset); |
| 1986 | } |
| 1987 | mPowerDrainMaMs.reset(detachIfReset); |
| 1988 | } |
| 1989 | |
| 1990 | public void detach() { |
| 1991 | mIdleTimeMillis.detach(); |
| 1992 | mRxTimeMillis.detach(); |
| 1993 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1994 | counter.detach(); |
| 1995 | } |
| 1996 | mPowerDrainMaMs.detach(); |
| 1997 | } |
| 1998 | |
| 1999 | /** |
| 2000 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2001 | * milliseconds. |
| 2002 | */ |
| 2003 | @Override |
| 2004 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2005 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /** |
| 2009 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2010 | * milliseconds. |
| 2011 | */ |
| 2012 | @Override |
| 2013 | public LongSamplingCounter getRxTimeCounter() { |
| 2014 | return mRxTimeMillis; |
| 2015 | } |
| 2016 | |
| 2017 | /** |
| 2018 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2019 | * milliseconds. |
| 2020 | */ |
| 2021 | @Override |
| 2022 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2023 | return mTxTimeMillis; |
| 2024 | } |
| 2025 | |
| 2026 | /** |
| 2027 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2028 | */ |
| 2029 | @Override |
| 2030 | public LongSamplingCounter getPowerCounter() { |
| 2031 | return mPowerDrainMaMs; |
| 2032 | } |
| 2033 | } |
| 2034 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2035 | /* |
| 2036 | * Get the wakeup reason counter, and create a new one if one |
| 2037 | * doesn't already exist. |
| 2038 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2039 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2040 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2041 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 2042 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2043 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2044 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2045 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2048 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2049 | * 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] | 2050 | * doesn't already exist. |
| 2051 | */ |
| 2052 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2053 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2054 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 2055 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2056 | mKernelWakelockStats.put(name, kwlt); |
| 2057 | } |
| 2058 | return kwlt; |
| 2059 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2060 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2061 | private int writeHistoryTag(HistoryTag tag) { |
| 2062 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2063 | int idx; |
| 2064 | if (idxObj != null) { |
| 2065 | idx = idxObj; |
| 2066 | } else { |
| 2067 | idx = mNextHistoryTagIdx; |
| 2068 | HistoryTag key = new HistoryTag(); |
| 2069 | key.setTo(tag); |
| 2070 | tag.poolIdx = idx; |
| 2071 | mHistoryTagPool.put(key, idx); |
| 2072 | mNextHistoryTagIdx++; |
| 2073 | mNumHistoryTagChars += key.string.length() + 1; |
| 2074 | } |
| 2075 | return idx; |
| 2076 | } |
| 2077 | |
| 2078 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2079 | tag.string = mReadHistoryStrings[index]; |
| 2080 | tag.uid = mReadHistoryUids[index]; |
| 2081 | tag.poolIdx = index; |
| 2082 | } |
| 2083 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2084 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2085 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2086 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2087 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2088 | 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] | 2089 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2090 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2091 | // Flag in delta int: a new full state and battery status int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2092 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 2093 | // Flag in delta int: a new full state2 int follows. |
| 2094 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2095 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2096 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2097 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2098 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2099 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2100 | static final int DELTA_STATE_MASK = 0xff000000; |
| 2101 | |
| 2102 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2103 | // the state int that have been packed in to the first delta int. They must fit |
| 2104 | // in DELTA_STATE_MASK. |
| 2105 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2106 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2107 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2108 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2109 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2110 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2111 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2112 | // We use the low bit of the battery state int to indicate that we have full details |
| 2113 | // from a battery level change. |
| 2114 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2115 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2116 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2117 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2118 | dest.writeInt(DELTA_TIME_ABS); |
| 2119 | cur.writeToParcel(dest, 0); |
| 2120 | return; |
| 2121 | } |
| 2122 | |
| 2123 | final long deltaTime = cur.time - last.time; |
| 2124 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2125 | final int lastStateInt = buildStateInt(last); |
| 2126 | |
| 2127 | int deltaTimeToken; |
| 2128 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2129 | deltaTimeToken = DELTA_TIME_LONG; |
| 2130 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2131 | deltaTimeToken = DELTA_TIME_INT; |
| 2132 | } else { |
| 2133 | deltaTimeToken = (int)deltaTime; |
| 2134 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2135 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2136 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2137 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2138 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2139 | || mLastHistoryStepDetails == null; |
| 2140 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2141 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2142 | if (batteryLevelIntChanged) { |
| 2143 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2144 | } |
| 2145 | final int stateInt = buildStateInt(cur); |
| 2146 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2147 | if (stateIntChanged) { |
| 2148 | firstToken |= DELTA_STATE_FLAG; |
| 2149 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2150 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2151 | if (state2IntChanged) { |
| 2152 | firstToken |= DELTA_STATE2_FLAG; |
| 2153 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2154 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2155 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2156 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2157 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2158 | firstToken |= DELTA_EVENT_FLAG; |
| 2159 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2160 | dest.writeInt(firstToken); |
| 2161 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2162 | + " deltaTime=" + deltaTime); |
| 2163 | |
| 2164 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2165 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2166 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2167 | dest.writeInt((int)deltaTime); |
| 2168 | } else { |
| 2169 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2170 | dest.writeLong(deltaTime); |
| 2171 | } |
| 2172 | } |
| 2173 | if (batteryLevelIntChanged) { |
| 2174 | dest.writeInt(batteryLevelInt); |
| 2175 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2176 | + Integer.toHexString(batteryLevelInt) |
| 2177 | + " batteryLevel=" + cur.batteryLevel |
| 2178 | + " batteryTemp=" + cur.batteryTemperature |
| 2179 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2180 | } |
| 2181 | if (stateIntChanged) { |
| 2182 | dest.writeInt(stateInt); |
| 2183 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2184 | + Integer.toHexString(stateInt) |
| 2185 | + " batteryStatus=" + cur.batteryStatus |
| 2186 | + " batteryHealth=" + cur.batteryHealth |
| 2187 | + " batteryPlugType=" + cur.batteryPlugType |
| 2188 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2189 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2190 | if (state2IntChanged) { |
| 2191 | dest.writeInt(cur.states2); |
| 2192 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2193 | + Integer.toHexString(cur.states2)); |
| 2194 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2195 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2196 | int wakeLockIndex; |
| 2197 | int wakeReasonIndex; |
| 2198 | if (cur.wakelockTag != null) { |
| 2199 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2200 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2201 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2202 | } else { |
| 2203 | wakeLockIndex = 0xffff; |
| 2204 | } |
| 2205 | if (cur.wakeReasonTag != null) { |
| 2206 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2207 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2208 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2209 | } else { |
| 2210 | wakeReasonIndex = 0xffff; |
| 2211 | } |
| 2212 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2213 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2214 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2215 | int index = writeHistoryTag(cur.eventTag); |
| 2216 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2217 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2218 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2219 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2220 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2221 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2222 | if (computeStepDetails) { |
| 2223 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2224 | if (includeStepDetails != 0) { |
| 2225 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2226 | } |
| 2227 | cur.stepDetails = mCurHistoryStepDetails; |
| 2228 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2229 | } else { |
| 2230 | cur.stepDetails = null; |
| 2231 | } |
| 2232 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2233 | mLastHistoryStepDetails = null; |
| 2234 | } |
| 2235 | mLastHistoryStepLevel = cur.batteryLevel; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2239 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2240 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2241 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2242 | } |
| 2243 | |
| 2244 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2245 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2246 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2247 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2251 | int plugType = 0; |
| 2252 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2253 | plugType = 1; |
| 2254 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2255 | plugType = 2; |
| 2256 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2257 | plugType = 3; |
| 2258 | } |
| 2259 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2260 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2261 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2262 | | (h.states&(~DELTA_STATE_MASK)); |
| 2263 | } |
| 2264 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2265 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2266 | final HistoryStepDetails last) { |
| 2267 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2268 | |
| 2269 | // Perform a CPU update right after we do this collection, so we have started |
| 2270 | // collecting good data for the next step. |
| 2271 | requestImmediateCpuUpdate(); |
| 2272 | |
| 2273 | if (last == null) { |
| 2274 | // We are not generating a delta, so all we need to do is reset the stats |
| 2275 | // we will later be doing a delta from. |
| 2276 | final int NU = mUidStats.size(); |
| 2277 | for (int i=0; i<NU; i++) { |
| 2278 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2279 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2280 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2281 | } |
| 2282 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2283 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2284 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2285 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2286 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2287 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2288 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2289 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2290 | tmp.clear(); |
| 2291 | return; |
| 2292 | } |
| 2293 | if (DEBUG) { |
| 2294 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2295 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2296 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2297 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2298 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2299 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2300 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2301 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2302 | } |
| 2303 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2304 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2305 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2306 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2307 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2308 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2309 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2310 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2311 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2312 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2313 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2314 | final int NU = mUidStats.size(); |
| 2315 | for (int i=0; i<NU; i++) { |
| 2316 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2317 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2318 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2319 | final int totalTime = totalUTime + totalSTime; |
| 2320 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2321 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2322 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2323 | continue; |
| 2324 | } |
| 2325 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2326 | out.appCpuUid3 = uid.mUid; |
| 2327 | out.appCpuUTime3 = totalUTime; |
| 2328 | out.appCpuSTime3 = totalSTime; |
| 2329 | } else { |
| 2330 | out.appCpuUid3 = out.appCpuUid2; |
| 2331 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2332 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2333 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2334 | out.appCpuUid2 = uid.mUid; |
| 2335 | out.appCpuUTime2 = totalUTime; |
| 2336 | out.appCpuSTime2 = totalSTime; |
| 2337 | } else { |
| 2338 | out.appCpuUid2 = out.appCpuUid1; |
| 2339 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2340 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2341 | out.appCpuUid1 = uid.mUid; |
| 2342 | out.appCpuUTime1 = totalUTime; |
| 2343 | out.appCpuSTime1 = totalSTime; |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2348 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2349 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2350 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2351 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2352 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2353 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2354 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2355 | } |
| 2356 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2357 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2358 | int firstToken = src.readInt(); |
| 2359 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2360 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2361 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2362 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2363 | + " deltaTimeToken=" + deltaTimeToken); |
| 2364 | |
| 2365 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2366 | cur.time += deltaTimeToken; |
| 2367 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2368 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2369 | cur.numReadInts += 2; |
| 2370 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2371 | cur.readFromParcel(src); |
| 2372 | return; |
| 2373 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2374 | int delta = src.readInt(); |
| 2375 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2376 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2377 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2378 | } else { |
| 2379 | long delta = src.readLong(); |
| 2380 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2381 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2382 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2383 | } |
| 2384 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2385 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2386 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2387 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2388 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2389 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2390 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2391 | + Integer.toHexString(batteryLevelInt) |
| 2392 | + " batteryLevel=" + cur.batteryLevel |
| 2393 | + " batteryTemp=" + cur.batteryTemperature |
| 2394 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2395 | } else { |
| 2396 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2400 | int stateInt = src.readInt(); |
| 2401 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2402 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2403 | & STATE_BATTERY_STATUS_MASK); |
| 2404 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2405 | & STATE_BATTERY_HEALTH_MASK); |
| 2406 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2407 | & STATE_BATTERY_PLUG_MASK); |
| 2408 | switch (cur.batteryPlugType) { |
| 2409 | case 1: |
| 2410 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2411 | break; |
| 2412 | case 2: |
| 2413 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2414 | break; |
| 2415 | case 3: |
| 2416 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2417 | break; |
| 2418 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2419 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2420 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2421 | + Integer.toHexString(stateInt) |
| 2422 | + " batteryStatus=" + cur.batteryStatus |
| 2423 | + " batteryHealth=" + cur.batteryHealth |
| 2424 | + " batteryPlugType=" + cur.batteryPlugType |
| 2425 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2426 | } else { |
| 2427 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 2428 | } |
| 2429 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2430 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2431 | cur.states2 = src.readInt(); |
| 2432 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2433 | + Integer.toHexString(cur.states2)); |
| 2434 | } |
| 2435 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2436 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2437 | int indexes = src.readInt(); |
| 2438 | int wakeLockIndex = indexes&0xffff; |
| 2439 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2440 | if (wakeLockIndex != 0xffff) { |
| 2441 | cur.wakelockTag = cur.localWakelockTag; |
| 2442 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2443 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2444 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2445 | } else { |
| 2446 | cur.wakelockTag = null; |
| 2447 | } |
| 2448 | if (wakeReasonIndex != 0xffff) { |
| 2449 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2450 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2451 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2452 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2453 | } else { |
| 2454 | cur.wakeReasonTag = null; |
| 2455 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2456 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2457 | } else { |
| 2458 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2459 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2460 | } |
| 2461 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2462 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2463 | cur.eventTag = cur.localEventTag; |
| 2464 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2465 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2466 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2467 | readHistoryTag(index, cur.eventTag); |
| 2468 | cur.numReadInts += 1; |
| 2469 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2470 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2471 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2472 | } else { |
| 2473 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2474 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2475 | |
| 2476 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2477 | cur.stepDetails = mReadHistoryStepDetails; |
| 2478 | cur.stepDetails.readFromParcel(src); |
| 2479 | } else { |
| 2480 | cur.stepDetails = null; |
| 2481 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2482 | } |
| 2483 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2484 | @Override |
| 2485 | public void commitCurrentHistoryBatchLocked() { |
| 2486 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2487 | } |
| 2488 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2489 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2490 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2491 | return; |
| 2492 | } |
| 2493 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2494 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2495 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2496 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2497 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2498 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2499 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2500 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2501 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2502 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2503 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2504 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2505 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2506 | && (diffStates2&lastDiffStates2) == 0 |
| 2507 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2508 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2509 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2510 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2511 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2512 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2513 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2514 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2515 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2516 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2517 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2518 | // 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] | 2519 | // 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] | 2520 | // as long as no bit has changed both between now and the last entry, as |
| 2521 | // well as the last entry and the one before it (so we capture any toggles). |
| 2522 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2523 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2524 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2525 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2526 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2527 | // If the last written history had a wakelock tag, we need to retain it. |
| 2528 | // Note that the condition above made sure that we aren't in a case where |
| 2529 | // both it and the current history item have a wakelock tag. |
| 2530 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2531 | cur.wakelockTag = cur.localWakelockTag; |
| 2532 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2533 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2534 | // If the last written history had a wake reason tag, we need to retain it. |
| 2535 | // Note that the condition above made sure that we aren't in a case where |
| 2536 | // both it and the current history item have a wakelock tag. |
| 2537 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2538 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2539 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2540 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2541 | // If the last written history had an event, we need to retain it. |
| 2542 | // Note that the condition above made sure that we aren't in a case where |
| 2543 | // both it and the current history item have an event. |
| 2544 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2545 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2546 | cur.eventTag = cur.localEventTag; |
| 2547 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2548 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2549 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2553 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2554 | if (!mHistoryOverflow) { |
| 2555 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2556 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2557 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2558 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2561 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2562 | boolean writeAnyway = false; |
| 2563 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2564 | & mActiveHistoryStates; |
| 2565 | if (mHistoryLastWritten.states != curStates) { |
| 2566 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2567 | // forced to 0. |
| 2568 | int old = mActiveHistoryStates; |
| 2569 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2570 | writeAnyway |= old != mActiveHistoryStates; |
| 2571 | } |
| 2572 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2573 | & mActiveHistoryStates2; |
| 2574 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2575 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2576 | // forced to 0. |
| 2577 | int old = mActiveHistoryStates2; |
| 2578 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2579 | writeAnyway |= old != mActiveHistoryStates2; |
| 2580 | } |
| 2581 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2582 | // Once we've reached the maximum number of items, we only |
| 2583 | // record changes to the battery level and the most interesting states. |
| 2584 | // Once we've reached the maximum maximum number of items, we only |
| 2585 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2586 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2587 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2588 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2589 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2590 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2591 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2592 | return; |
| 2593 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2594 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2595 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2596 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2599 | if (dataSize == 0) { |
| 2600 | // The history is currently empty; we need it to start with a time stamp. |
| 2601 | cur.currentTime = System.currentTimeMillis(); |
| 2602 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2603 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2604 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2607 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2608 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2609 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2610 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2611 | } |
| 2612 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2613 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2614 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2615 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2616 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2617 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2618 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2619 | cur.wakelockTag = null; |
| 2620 | cur.wakeReasonTag = null; |
| 2621 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2622 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2623 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2624 | + " now " + mHistoryBuffer.dataPosition() |
| 2625 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2628 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2629 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2630 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2631 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2632 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2633 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2634 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2635 | if (diffUptime < (diffElapsed-20)) { |
| 2636 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2637 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2638 | mHistoryAddTmp.wakelockTag = null; |
| 2639 | mHistoryAddTmp.wakeReasonTag = null; |
| 2640 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2641 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2642 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2643 | } |
| 2644 | } |
| 2645 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2646 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2647 | mTrackRunningHistoryUptime = uptimeMs; |
| 2648 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2649 | } |
| 2650 | |
| 2651 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2652 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2653 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2654 | if (!USE_OLD_HISTORY) { |
| 2655 | return; |
| 2656 | } |
| 2657 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2658 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2659 | return; |
| 2660 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2661 | |
| 2662 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2663 | // and no states have since the last recorded entry changed and |
| 2664 | // are now resetting back to their original value, then just collapse |
| 2665 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2666 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2667 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2668 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2669 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2670 | // If the current is the same as the one before, then we no |
| 2671 | // longer need the entry. |
| 2672 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2673 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2674 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2675 | mHistoryLastEnd.next = null; |
| 2676 | mHistoryEnd.next = mHistoryCache; |
| 2677 | mHistoryCache = mHistoryEnd; |
| 2678 | mHistoryEnd = mHistoryLastEnd; |
| 2679 | mHistoryLastEnd = null; |
| 2680 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2681 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2682 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2683 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2684 | } |
| 2685 | return; |
| 2686 | } |
| 2687 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2688 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2689 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2690 | |
| 2691 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2692 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2693 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2696 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2697 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2698 | // record changes to the battery level and the most interesting states. |
| 2699 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2700 | // record changes to the battery level. |
| 2701 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2702 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2703 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2704 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2705 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2706 | return; |
| 2707 | } |
| 2708 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2709 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2710 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2711 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2712 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2713 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2714 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2715 | mHistoryCur.eventCode = code; |
| 2716 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2717 | mHistoryCur.eventTag.string = name; |
| 2718 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2719 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2720 | } |
| 2721 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2722 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2723 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2724 | if (rec != null) { |
| 2725 | mHistoryCache = rec.next; |
| 2726 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2727 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2728 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2729 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2730 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2731 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2732 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2733 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2734 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2735 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2736 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2737 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2738 | if (mHistoryEnd != null) { |
| 2739 | mHistoryEnd.next = rec; |
| 2740 | mHistoryEnd = rec; |
| 2741 | } else { |
| 2742 | mHistory = mHistoryEnd = rec; |
| 2743 | } |
| 2744 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2745 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2746 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2747 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2748 | if (USE_OLD_HISTORY) { |
| 2749 | if (mHistory != null) { |
| 2750 | mHistoryEnd.next = mHistoryCache; |
| 2751 | mHistoryCache = mHistory; |
| 2752 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2753 | } |
| 2754 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2755 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2756 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2757 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2758 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2759 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2760 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2761 | |
| 2762 | mHistoryBuffer.setDataSize(0); |
| 2763 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2764 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2765 | mHistoryLastLastWritten.clear(); |
| 2766 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2767 | mHistoryTagPool.clear(); |
| 2768 | mNextHistoryTagIdx = 0; |
| 2769 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2770 | mHistoryBufferLastPos = -1; |
| 2771 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2772 | mActiveHistoryStates = 0xffffffff; |
| 2773 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2774 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2775 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2776 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2777 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2778 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2779 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2780 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2781 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2782 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2783 | if (DEBUG_ENERGY_CPU) { |
| 2784 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 2785 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2786 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2787 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2788 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | } |
| 2790 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2791 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2792 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2793 | mIsolatedUids.put(isolatedUid, appUid); |
| 2794 | } |
| 2795 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2796 | /** |
| 2797 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 2798 | * @see #removeIsolatedUidLocked(int) |
| 2799 | */ |
| 2800 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2801 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2802 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2803 | if (mExternalSync != null) { |
| 2804 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 2805 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2809 | /** |
| 2810 | * This should only be called after the cpu times have been read. |
| 2811 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 2812 | */ |
| 2813 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 2814 | mIsolatedUids.delete(isolatedUid); |
| 2815 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 2816 | } |
| 2817 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2818 | public int mapUid(int uid) { |
| 2819 | int isolated = mIsolatedUids.get(uid, -1); |
| 2820 | return isolated > 0 ? isolated : uid; |
| 2821 | } |
| 2822 | |
| 2823 | public void noteEventLocked(int code, String name, int uid) { |
| 2824 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2825 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2826 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2827 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2828 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2829 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2830 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2831 | } |
| 2832 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2833 | boolean ensureStartClockTime(final long currentTime) { |
| 2834 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 2835 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 2836 | // If the start clock time has changed by more than a year, then presumably |
| 2837 | // the previous time was completely bogus. So we are going to figure out a |
| 2838 | // 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] | 2839 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2840 | return true; |
| 2841 | } |
| 2842 | return false; |
| 2843 | } |
| 2844 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2845 | public void noteCurrentTimeChangedLocked() { |
| 2846 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2847 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2848 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2849 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2850 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2853 | public void noteProcessStartLocked(String name, int uid) { |
| 2854 | uid = mapUid(uid); |
| 2855 | if (isOnBattery()) { |
| 2856 | Uid u = getUidStatsLocked(uid); |
| 2857 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2858 | } |
| 2859 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2860 | return; |
| 2861 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2862 | if (!mRecordAllHistory) { |
| 2863 | return; |
| 2864 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2865 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2866 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2867 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2868 | } |
| 2869 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2870 | public void noteProcessCrashLocked(String name, int uid) { |
| 2871 | uid = mapUid(uid); |
| 2872 | if (isOnBattery()) { |
| 2873 | Uid u = getUidStatsLocked(uid); |
| 2874 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2875 | } |
| 2876 | } |
| 2877 | |
| 2878 | public void noteProcessAnrLocked(String name, int uid) { |
| 2879 | uid = mapUid(uid); |
| 2880 | if (isOnBattery()) { |
| 2881 | Uid u = getUidStatsLocked(uid); |
| 2882 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2883 | } |
| 2884 | } |
| 2885 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 2886 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2887 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 2888 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | public void noteProcessFinishLocked(String name, int uid) { |
| 2892 | uid = mapUid(uid); |
| 2893 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2894 | return; |
| 2895 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2896 | if (!mRecordAllHistory) { |
| 2897 | return; |
| 2898 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2899 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2900 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2901 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2904 | public void noteSyncStartLocked(String name, int uid) { |
| 2905 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2906 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2907 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2908 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2909 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2910 | return; |
| 2911 | } |
| 2912 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2913 | } |
| 2914 | |
| 2915 | public void noteSyncFinishLocked(String name, int uid) { |
| 2916 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2917 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2918 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2919 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2920 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2921 | return; |
| 2922 | } |
| 2923 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2924 | } |
| 2925 | |
| 2926 | public void noteJobStartLocked(String name, int uid) { |
| 2927 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2928 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2929 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2930 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2931 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2932 | return; |
| 2933 | } |
| 2934 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2935 | } |
| 2936 | |
| 2937 | public void noteJobFinishLocked(String name, int uid) { |
| 2938 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2939 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2940 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2941 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2942 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2943 | return; |
| 2944 | } |
| 2945 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2946 | } |
| 2947 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2948 | public void noteAlarmStartLocked(String name, int uid) { |
| 2949 | if (!mRecordAllHistory) { |
| 2950 | return; |
| 2951 | } |
| 2952 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2953 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2954 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2955 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 2956 | return; |
| 2957 | } |
| 2958 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 2959 | } |
| 2960 | |
| 2961 | public void noteAlarmFinishLocked(String name, int uid) { |
| 2962 | if (!mRecordAllHistory) { |
| 2963 | return; |
| 2964 | } |
| 2965 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2966 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2967 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2968 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 2969 | return; |
| 2970 | } |
| 2971 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 2972 | } |
| 2973 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2974 | private void requestWakelockCpuUpdate() { |
| 2975 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2976 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2977 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2978 | } |
| 2979 | } |
| 2980 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2981 | private void requestImmediateCpuUpdate() { |
| 2982 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2983 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 2984 | } |
| 2985 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2986 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 2987 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2988 | if (!enabled) { |
| 2989 | // Clear out any existing state. |
| 2990 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2991 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2992 | // Record the currently running processes as stopping, now that we are no |
| 2993 | // longer tracking them. |
| 2994 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2995 | HistoryItem.EVENT_PROC); |
| 2996 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2997 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 2998 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2999 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3000 | SparseIntArray uids = ent.getValue(); |
| 3001 | for (int j=0; j<uids.size(); j++) { |
| 3002 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3003 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3004 | } |
| 3005 | } |
| 3006 | } |
| 3007 | } else { |
| 3008 | // Record the currently running processes as starting, now that we are tracking them. |
| 3009 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3010 | HistoryItem.EVENT_PROC); |
| 3011 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3012 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3013 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3014 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3015 | SparseIntArray uids = ent.getValue(); |
| 3016 | for (int j=0; j<uids.size(); j++) { |
| 3017 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3018 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3019 | } |
| 3020 | } |
| 3021 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3025 | public void setNoAutoReset(boolean enabled) { |
| 3026 | mNoAutoReset = enabled; |
| 3027 | } |
| 3028 | |
| 3029 | private String mInitialAcquireWakeName; |
| 3030 | private int mInitialAcquireWakeUid = -1; |
| 3031 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3032 | 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] | 3033 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3034 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3035 | if (type == WAKE_TYPE_PARTIAL) { |
| 3036 | // Only care about partial wake locks, since full wake locks |
| 3037 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3038 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3039 | if (historyName == null) { |
| 3040 | historyName = name; |
| 3041 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3042 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3043 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3044 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3045 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3046 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3047 | } |
| 3048 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3049 | if (mWakeLockNesting == 0) { |
| 3050 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3051 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3052 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3053 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3054 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3055 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3056 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3057 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3058 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3059 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3060 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3061 | // We'll try to update the last tag. |
| 3062 | mHistoryLastWritten.wakelockTag = null; |
| 3063 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3064 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3065 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3066 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3067 | } |
| 3068 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3069 | } |
| 3070 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3071 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3072 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3073 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3074 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3075 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3076 | if (DEBUG_ENERGY_CPU) { |
| 3077 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3078 | } |
| 3079 | requestWakelockCpuUpdate(); |
| 3080 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3081 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3082 | } |
| 3083 | } |
| 3084 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3085 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3086 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3087 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3088 | if (type == WAKE_TYPE_PARTIAL) { |
| 3089 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3090 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3091 | if (historyName == null) { |
| 3092 | historyName = name; |
| 3093 | } |
| 3094 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3095 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3096 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3097 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3098 | } |
| 3099 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3100 | if (mWakeLockNesting == 0) { |
| 3101 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3102 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3103 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3104 | mInitialAcquireWakeName = null; |
| 3105 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3106 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3107 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3108 | } |
| 3109 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3110 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3111 | if (DEBUG_ENERGY_CPU) { |
| 3112 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3113 | } |
| 3114 | requestWakelockCpuUpdate(); |
| 3115 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3116 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3117 | } |
| 3118 | } |
| 3119 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3120 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3121 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3122 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3123 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3124 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3125 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3126 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3127 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3131 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3132 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3133 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3134 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3135 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3136 | // For correct semantics, we start the need worksources first, so that we won't |
| 3137 | // make inappropriate history items as if all wake locks went away and new ones |
| 3138 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3139 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3140 | for (int i=0; i<NN; i++) { |
| 3141 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3142 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3143 | } |
| 3144 | final int NO = ws.size(); |
| 3145 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3146 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3150 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3151 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3152 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3153 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3154 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3155 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3156 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3157 | } |
| 3158 | } |
| 3159 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3160 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3161 | if (mLastWakeupReason != null) { |
| 3162 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3163 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 3164 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3165 | mLastWakeupReason = null; |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3170 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3171 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3172 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3173 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3174 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3175 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3176 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3177 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3178 | mLastWakeupReason = reason; |
| 3179 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3180 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3181 | } |
| 3182 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3183 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3184 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3185 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3188 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3189 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3190 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3191 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3192 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3193 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3194 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3195 | mCurStepCpuUserTime += totalUTime; |
| 3196 | mCurStepCpuSystemTime += totalSTime; |
| 3197 | mCurStepStatUserTime += statUserTime; |
| 3198 | mCurStepStatSystemTime += statSystemTime; |
| 3199 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3200 | mCurStepStatIrqTime += statIrqTime; |
| 3201 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3202 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3205 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3206 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3207 | Uid u = mUidStats.get(uid); |
| 3208 | if (u != null) { |
| 3209 | u.mPids.remove(pid); |
| 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3214 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3215 | Uid u = mUidStats.get(uid); |
| 3216 | if (u != null) { |
| 3217 | Uid.Pid p = u.mPids.get(pid); |
| 3218 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3219 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | return 0; |
| 3223 | } |
| 3224 | |
| 3225 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3226 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3227 | Uid u = mUidStats.get(uid); |
| 3228 | if (u != null) { |
| 3229 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3230 | } |
| 3231 | } |
| 3232 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3233 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3234 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3235 | Uid u = mUidStats.get(uid); |
| 3236 | if (u != null) { |
| 3237 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3238 | } |
| 3239 | } |
| 3240 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3241 | int mSensorNesting; |
| 3242 | |
| 3243 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3244 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3245 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3246 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3247 | if (mSensorNesting == 0) { |
| 3248 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3249 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3250 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3251 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3252 | } |
| 3253 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3254 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3258 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3259 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3260 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3261 | mSensorNesting--; |
| 3262 | if (mSensorNesting == 0) { |
| 3263 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3264 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3265 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3266 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3267 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3268 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3271 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3272 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3273 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3274 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3275 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3276 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3277 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3278 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3279 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3280 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3281 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3282 | } |
| 3283 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3284 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3286 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3287 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3288 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3289 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3290 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3291 | mGpsNesting--; |
| 3292 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3293 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3294 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3295 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3296 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3297 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3298 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3299 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3300 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3301 | public void noteScreenStateLocked(int state) { |
| 3302 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3303 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3304 | final int oldState = mScreenState; |
| 3305 | mScreenState = state; |
| 3306 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3307 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3308 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3309 | if (state != Display.STATE_UNKNOWN) { |
| 3310 | int stepState = state-1; |
| 3311 | if (stepState < 4) { |
| 3312 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3313 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3314 | } else { |
| 3315 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3316 | } |
| 3317 | } |
| 3318 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3319 | if (state == Display.STATE_ON) { |
| 3320 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3321 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3322 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3323 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3324 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3325 | + Integer.toHexString(mHistoryCur.states)); |
| 3326 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3327 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3328 | if (mScreenBrightnessBin >= 0) { |
| 3329 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3330 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3331 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3332 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3333 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3334 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3335 | // Fake a wake lock, so we consider the device waked as long |
| 3336 | // as the screen is on. |
| 3337 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3338 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3339 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3340 | // Update discharge amounts. |
| 3341 | if (mOnBatteryInternal) { |
| 3342 | updateDischargeScreenLevelsLocked(false, true); |
| 3343 | } |
| 3344 | } else if (oldState == Display.STATE_ON) { |
| 3345 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3346 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3347 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3348 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3349 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3350 | + Integer.toHexString(mHistoryCur.states)); |
| 3351 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3352 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3353 | if (mScreenBrightnessBin >= 0) { |
| 3354 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3355 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3356 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3357 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3358 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3359 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3360 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3361 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3362 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3363 | // Update discharge amounts. |
| 3364 | if (mOnBatteryInternal) { |
| 3365 | updateDischargeScreenLevelsLocked(true, false); |
| 3366 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3367 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3368 | } |
| 3369 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3370 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3371 | public void noteScreenBrightnessLocked(int brightness) { |
| 3372 | // Bin the brightness. |
| 3373 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3374 | if (bin < 0) bin = 0; |
| 3375 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3376 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3377 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3378 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3379 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3380 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3381 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3382 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3383 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3384 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3385 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3386 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3387 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3388 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3389 | } |
| 3390 | mScreenBrightnessBin = bin; |
| 3391 | } |
| 3392 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3393 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3394 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3395 | if (mOnBatteryInternal) { |
| 3396 | uid = mapUid(uid); |
| 3397 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3400 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3401 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3402 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3403 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3404 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3405 | reason, reasonUid); |
| 3406 | } |
| 3407 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3408 | public void noteInteractiveLocked(boolean interactive) { |
| 3409 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3410 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3411 | mInteractive = interactive; |
| 3412 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3413 | if (interactive) { |
| 3414 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3415 | } else { |
| 3416 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3421 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3422 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3423 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3424 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3425 | extra, type); |
| 3426 | mNumConnectivityChange++; |
| 3427 | } |
| 3428 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3429 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3430 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3431 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3432 | if (mMobileRadioPowerState != powerState) { |
| 3433 | long realElapsedRealtimeMs; |
| 3434 | final boolean active = |
| 3435 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3436 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3437 | if (active) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3438 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3439 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3440 | } else { |
| 3441 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3442 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3443 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3444 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3445 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3446 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3447 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3448 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3449 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3450 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3451 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3452 | } |
| 3453 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3454 | + Integer.toHexString(mHistoryCur.states)); |
| 3455 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3456 | mMobileRadioPowerState = powerState; |
| 3457 | if (active) { |
| 3458 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3459 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3460 | } else { |
| 3461 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3462 | updateMobileRadioStateLocked(realElapsedRealtimeMs, null); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3463 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3464 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3465 | } |
| 3466 | } |
| 3467 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3468 | public void notePowerSaveMode(boolean enabled) { |
| 3469 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3470 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3471 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3472 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3473 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3474 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3475 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3476 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3477 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3478 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3479 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3480 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3481 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3482 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3483 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3484 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3485 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3486 | } |
| 3487 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3488 | } |
| 3489 | } |
| 3490 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3491 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3492 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3493 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3494 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3495 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3496 | // We don't go out of general idling mode until explicitly taken out of |
| 3497 | // device idle through going active or significant motion. |
| 3498 | nowIdling = true; |
| 3499 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3500 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 3501 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 3502 | // We don't go out of general light idling mode until explicitly taken out of |
| 3503 | // device idle through going active or significant motion. |
| 3504 | nowLightIdling = true; |
| 3505 | } |
| 3506 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 3507 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3508 | activeReason, activeUid); |
| 3509 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3510 | if (mDeviceIdling != nowIdling) { |
| 3511 | mDeviceIdling = nowIdling; |
| 3512 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3513 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3514 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3515 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3516 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3517 | } else { |
| 3518 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3519 | } |
| 3520 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3521 | if (mDeviceLightIdling != nowLightIdling) { |
| 3522 | mDeviceLightIdling = nowLightIdling; |
| 3523 | if (nowLightIdling) { |
| 3524 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3525 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3526 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3527 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3528 | } |
| 3529 | if (mDeviceIdleMode != mode) { |
| 3530 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 3531 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 3532 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 3533 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3534 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3535 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 3536 | mLastIdleTimeStart = elapsedRealtime; |
| 3537 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 3538 | if (lastDuration > mLongestLightIdleTime) { |
| 3539 | mLongestLightIdleTime = lastDuration; |
| 3540 | } |
| 3541 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3542 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3543 | if (lastDuration > mLongestFullIdleTime) { |
| 3544 | mLongestFullIdleTime = lastDuration; |
| 3545 | } |
| 3546 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 3547 | } |
| 3548 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 3549 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3550 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3551 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 3552 | } |
| 3553 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3554 | } |
| 3555 | } |
| 3556 | |
| 3557 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3558 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3559 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3560 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3561 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3562 | PackageChange pc = new PackageChange(); |
| 3563 | pc.mPackageName = pkgName; |
| 3564 | pc.mUpdate = true; |
| 3565 | pc.mVersionCode = versionCode; |
| 3566 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3570 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3571 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3572 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3573 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3574 | PackageChange pc = new PackageChange(); |
| 3575 | pc.mPackageName = pkgName; |
| 3576 | pc.mUpdate = true; |
| 3577 | addPackageChange(pc); |
| 3578 | } |
| 3579 | |
| 3580 | private void addPackageChange(PackageChange pc) { |
| 3581 | if (mDailyPackageChanges == null) { |
| 3582 | mDailyPackageChanges = new ArrayList<>(); |
| 3583 | } |
| 3584 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | public void notePhoneOnLocked() { |
| 3588 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3589 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3590 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3591 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3592 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3593 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3594 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3596 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | } |
| 3598 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | public void notePhoneOffLocked() { |
| 3601 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3602 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3603 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3604 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3605 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3606 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3607 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3609 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | } |
| 3611 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3612 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3613 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3614 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3615 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3616 | if (i == except) { |
| 3617 | continue; |
| 3618 | } |
| 3619 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3620 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | } |
| 3624 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3625 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3626 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3627 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3628 | // to infer that we are scanning from other data. |
| 3629 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3630 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3631 | state = ServiceState.STATE_IN_SERVICE; |
| 3632 | } |
| 3633 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3634 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3635 | return state; |
| 3636 | } |
| 3637 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3638 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3639 | boolean scanning = false; |
| 3640 | boolean newHistory = false; |
| 3641 | |
| 3642 | mPhoneServiceStateRaw = state; |
| 3643 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3644 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3645 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3646 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3647 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3648 | |
| 3649 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3650 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3651 | // to infer that we are scanning from other data. |
| 3652 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3653 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3654 | state = ServiceState.STATE_IN_SERVICE; |
| 3655 | } |
| 3656 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3657 | |
| 3658 | // If the phone is powered off, stop all timers. |
| 3659 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3660 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3661 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3662 | // If we are in service, make sure the correct signal string timer is running. |
| 3663 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3664 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3665 | |
| 3666 | // If we're out of service, we are in the lowest signal strength |
| 3667 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3668 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3669 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3670 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3671 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3672 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3673 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3674 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3675 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3676 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3677 | } |
| 3678 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3679 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3680 | if (!scanning) { |
| 3681 | // If we are no longer scanning, then stop the scanning timer. |
| 3682 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3683 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3684 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3685 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3686 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3687 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3688 | } |
| 3689 | } |
| 3690 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3691 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3692 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3693 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3694 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3695 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3696 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3697 | mPhoneServiceState = state; |
| 3698 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3699 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3700 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3701 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3702 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3703 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3704 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3705 | if (strengthBin >= 0) { |
| 3706 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3707 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3708 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3709 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3710 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3711 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3712 | + Integer.toHexString(mHistoryCur.states)); |
| 3713 | newHistory = true; |
| 3714 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3715 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3716 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3717 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3721 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | /** |
| 3726 | * Telephony stack updates the phone state. |
| 3727 | * @param state phone state from ServiceState.getState() |
| 3728 | */ |
| 3729 | public void notePhoneStateLocked(int state, int simState) { |
| 3730 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3733 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3734 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3735 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3736 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3737 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3738 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3739 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3740 | int bin = DATA_CONNECTION_NONE; |
| 3741 | if (hasData) { |
| 3742 | switch (dataType) { |
| 3743 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3744 | bin = DATA_CONNECTION_EDGE; |
| 3745 | break; |
| 3746 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3747 | bin = DATA_CONNECTION_GPRS; |
| 3748 | break; |
| 3749 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3750 | bin = DATA_CONNECTION_UMTS; |
| 3751 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3752 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3753 | bin = DATA_CONNECTION_CDMA; |
| 3754 | break; |
| 3755 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3756 | bin = DATA_CONNECTION_EVDO_0; |
| 3757 | break; |
| 3758 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3759 | bin = DATA_CONNECTION_EVDO_A; |
| 3760 | break; |
| 3761 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3762 | bin = DATA_CONNECTION_1xRTT; |
| 3763 | break; |
| 3764 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3765 | bin = DATA_CONNECTION_HSDPA; |
| 3766 | break; |
| 3767 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3768 | bin = DATA_CONNECTION_HSUPA; |
| 3769 | break; |
| 3770 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3771 | bin = DATA_CONNECTION_HSPA; |
| 3772 | break; |
| 3773 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3774 | bin = DATA_CONNECTION_IDEN; |
| 3775 | break; |
| 3776 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3777 | bin = DATA_CONNECTION_EVDO_B; |
| 3778 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3779 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3780 | bin = DATA_CONNECTION_LTE; |
| 3781 | break; |
| 3782 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3783 | bin = DATA_CONNECTION_EHRPD; |
| 3784 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3785 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3786 | bin = DATA_CONNECTION_HSPAP; |
| 3787 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3788 | default: |
| 3789 | bin = DATA_CONNECTION_OTHER; |
| 3790 | break; |
| 3791 | } |
| 3792 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3793 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3794 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3795 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3796 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3797 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3798 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3799 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3800 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3801 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3802 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3803 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3804 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3805 | } |
| 3806 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3807 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3810 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3811 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3812 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3813 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3814 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3815 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3816 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3817 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3818 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3819 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3820 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3821 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3822 | } |
| 3823 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3824 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3825 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3826 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3827 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3828 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3829 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3830 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3831 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3832 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3833 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3834 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3835 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3836 | } |
| 3837 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3838 | |
| 3839 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3840 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3841 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3842 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3843 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3844 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3845 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3846 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3847 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3848 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3849 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3850 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3851 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3852 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3853 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3854 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3855 | if (mAudioOnNesting == 0) { |
| 3856 | return; |
| 3857 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3858 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3859 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3860 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3861 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3862 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3863 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3864 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3865 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3866 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3867 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3868 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3872 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3873 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3874 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3875 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3876 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3877 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3878 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3879 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3880 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3881 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3882 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3883 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3884 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3885 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3886 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3887 | if (mVideoOnNesting == 0) { |
| 3888 | return; |
| 3889 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3890 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3891 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3892 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3893 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3894 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3895 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3896 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3897 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3898 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3899 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3900 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3903 | public void noteResetAudioLocked() { |
| 3904 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3905 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3906 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3907 | mAudioOnNesting = 0; |
| 3908 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3909 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3910 | + Integer.toHexString(mHistoryCur.states)); |
| 3911 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3912 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3913 | for (int i=0; i<mUidStats.size(); i++) { |
| 3914 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3915 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3916 | } |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | public void noteResetVideoLocked() { |
| 3921 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3922 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3923 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3924 | mAudioOnNesting = 0; |
| 3925 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3926 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3927 | + Integer.toHexString(mHistoryCur.states)); |
| 3928 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3929 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3930 | for (int i=0; i<mUidStats.size(); i++) { |
| 3931 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3932 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3937 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3938 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3939 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3943 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3944 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3947 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3948 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3949 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3950 | } |
| 3951 | |
| 3952 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3953 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3954 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3955 | } |
| 3956 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3957 | public void noteFlashlightOnLocked(int uid) { |
| 3958 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3959 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3960 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3961 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3962 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3963 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3964 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3965 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3966 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3967 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3968 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 3969 | } |
| 3970 | |
| 3971 | public void noteFlashlightOffLocked(int uid) { |
| 3972 | if (mFlashlightOnNesting == 0) { |
| 3973 | return; |
| 3974 | } |
| 3975 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3976 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3977 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3978 | if (--mFlashlightOnNesting == 0) { |
| 3979 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3980 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3981 | + Integer.toHexString(mHistoryCur.states2)); |
| 3982 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3983 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3984 | } |
| 3985 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 3986 | } |
| 3987 | |
| 3988 | public void noteCameraOnLocked(int uid) { |
| 3989 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3990 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3991 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3992 | if (mCameraOnNesting++ == 0) { |
| 3993 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 3994 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 3995 | + Integer.toHexString(mHistoryCur.states2)); |
| 3996 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3997 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 3998 | } |
| 3999 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4000 | } |
| 4001 | |
| 4002 | public void noteCameraOffLocked(int uid) { |
| 4003 | if (mCameraOnNesting == 0) { |
| 4004 | return; |
| 4005 | } |
| 4006 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4007 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4008 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4009 | if (--mCameraOnNesting == 0) { |
| 4010 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4011 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4012 | + Integer.toHexString(mHistoryCur.states2)); |
| 4013 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4014 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4015 | } |
| 4016 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4017 | } |
| 4018 | |
| 4019 | public void noteResetCameraLocked() { |
| 4020 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4021 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4022 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4023 | mCameraOnNesting = 0; |
| 4024 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4025 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4026 | + Integer.toHexString(mHistoryCur.states2)); |
| 4027 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4028 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4029 | for (int i=0; i<mUidStats.size(); i++) { |
| 4030 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4031 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4032 | } |
| 4033 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4036 | public void noteResetFlashlightLocked() { |
| 4037 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4038 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4039 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4040 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4041 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4042 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4043 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4044 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4045 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4046 | for (int i=0; i<mUidStats.size(); i++) { |
| 4047 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4048 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4049 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4050 | } |
| 4051 | } |
| 4052 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4053 | private void noteBluetoothScanStartedLocked(int uid) { |
| 4054 | uid = mapUid(uid); |
| 4055 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4056 | final long uptime = SystemClock.uptimeMillis(); |
| 4057 | if (mBluetoothScanNesting == 0) { |
| 4058 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4059 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4060 | + Integer.toHexString(mHistoryCur.states2)); |
| 4061 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4062 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4063 | } |
| 4064 | mBluetoothScanNesting++; |
| 4065 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime); |
| 4066 | } |
| 4067 | |
| 4068 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) { |
| 4069 | final int N = ws.size(); |
| 4070 | for (int i = 0; i < N; i++) { |
| 4071 | noteBluetoothScanStartedLocked(ws.get(i)); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | private void noteBluetoothScanStoppedLocked(int uid) { |
| 4076 | uid = mapUid(uid); |
| 4077 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4078 | final long uptime = SystemClock.uptimeMillis(); |
| 4079 | mBluetoothScanNesting--; |
| 4080 | if (mBluetoothScanNesting == 0) { |
| 4081 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4082 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4083 | + Integer.toHexString(mHistoryCur.states2)); |
| 4084 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4085 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4086 | } |
| 4087 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime); |
| 4088 | } |
| 4089 | |
| 4090 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) { |
| 4091 | final int N = ws.size(); |
| 4092 | for (int i = 0; i < N; i++) { |
| 4093 | noteBluetoothScanStoppedLocked(ws.get(i)); |
| 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | public void noteResetBluetoothScanLocked() { |
| 4098 | if (mBluetoothScanNesting > 0) { |
| 4099 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4100 | final long uptime = SystemClock.uptimeMillis(); |
| 4101 | mBluetoothScanNesting = 0; |
| 4102 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4103 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4104 | + Integer.toHexString(mHistoryCur.states2)); |
| 4105 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4106 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4107 | for (int i=0; i<mUidStats.size(); i++) { |
| 4108 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4109 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4114 | public void noteWifiRadioPowerState(int powerState, long timestampNs) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4115 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4116 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4117 | if (mWifiRadioPowerState != powerState) { |
| 4118 | final boolean active = |
| 4119 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4120 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4121 | if (active) { |
| 4122 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4123 | } else { |
| 4124 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4125 | } |
| 4126 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4127 | + Integer.toHexString(mHistoryCur.states)); |
| 4128 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4129 | mWifiRadioPowerState = powerState; |
| 4130 | } |
| 4131 | } |
| 4132 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4133 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4134 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4135 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4136 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4137 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4138 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4139 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4140 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4141 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4142 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4143 | int N = ws.size(); |
| 4144 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4145 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4146 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4147 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4148 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4149 | } else { |
| 4150 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4151 | } |
| 4152 | } |
| 4153 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4154 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4155 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4156 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4157 | int N = oldWs.size(); |
| 4158 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4159 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4160 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4161 | } |
| 4162 | N = newWs.size(); |
| 4163 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4164 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4165 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4166 | } |
| 4167 | } else { |
| 4168 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4169 | } |
| 4170 | } |
| 4171 | |
| 4172 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4173 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4174 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4175 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4176 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4177 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4178 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4179 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4180 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4181 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4182 | int N = ws.size(); |
| 4183 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4184 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4185 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4186 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4187 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4188 | } else { |
| 4189 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4190 | } |
| 4191 | } |
| 4192 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4193 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4194 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4195 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4196 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4197 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4198 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4199 | } |
| 4200 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4201 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4202 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4206 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4207 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 4208 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4209 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4210 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4211 | if (mWifiSupplState >= 0) { |
| 4212 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 4213 | } |
| 4214 | mWifiSupplState = supplState; |
| 4215 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 4216 | mHistoryCur.states2 = |
| 4217 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 4218 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 4219 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 4220 | + Integer.toHexString(mHistoryCur.states2)); |
| 4221 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4226 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4227 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4228 | if (i == except) { |
| 4229 | continue; |
| 4230 | } |
| 4231 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 4232 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 4233 | } |
| 4234 | } |
| 4235 | } |
| 4236 | |
| 4237 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 4238 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 4239 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 4240 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4241 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4242 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4243 | if (mWifiSignalStrengthBin >= 0) { |
| 4244 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 4245 | elapsedRealtime); |
| 4246 | } |
| 4247 | if (strengthBin >= 0) { |
| 4248 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 4249 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 4250 | } |
| 4251 | mHistoryCur.states2 = |
| 4252 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 4253 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 4254 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 4255 | + Integer.toHexString(mHistoryCur.states2)); |
| 4256 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4257 | } else { |
| 4258 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 4259 | } |
| 4260 | mWifiSignalStrengthBin = strengthBin; |
| 4261 | } |
| 4262 | } |
| 4263 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4264 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4265 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4266 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4267 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4268 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4269 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4270 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4271 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4272 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 4273 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4274 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4275 | } |
| 4276 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4277 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4281 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4282 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4283 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4284 | mWifiFullLockNesting--; |
| 4285 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4286 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4287 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 4288 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4289 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4290 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4291 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4294 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4295 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4296 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4297 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4298 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4299 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4300 | if (mWifiScanNesting == 0) { |
| 4301 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4302 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4303 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4304 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4305 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4306 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4307 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4310 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4311 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4312 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4313 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4314 | mWifiScanNesting--; |
| 4315 | if (mWifiScanNesting == 0) { |
| 4316 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4317 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4318 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4319 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4320 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4321 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4322 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4323 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4324 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4325 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4326 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4327 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4331 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4332 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4333 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4336 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4337 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4338 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4339 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4340 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4341 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4342 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4343 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4344 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4345 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4346 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4347 | } |
| 4348 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4349 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4353 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4354 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4355 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4356 | mWifiMulticastNesting--; |
| 4357 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4358 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4359 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4360 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4361 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4362 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4363 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4364 | } |
| 4365 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4366 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4367 | int N = ws.size(); |
| 4368 | for (int i=0; i<N; i++) { |
| 4369 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4370 | } |
| 4371 | } |
| 4372 | |
| 4373 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4374 | int N = ws.size(); |
| 4375 | for (int i=0; i<N; i++) { |
| 4376 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4377 | } |
| 4378 | } |
| 4379 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4380 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4381 | int N = ws.size(); |
| 4382 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4383 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4387 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4388 | int N = ws.size(); |
| 4389 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4390 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4391 | } |
| 4392 | } |
| 4393 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4394 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4395 | int N = ws.size(); |
| 4396 | for (int i=0; i<N; i++) { |
| 4397 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4402 | int N = ws.size(); |
| 4403 | for (int i=0; i<N; i++) { |
| 4404 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4405 | } |
| 4406 | } |
| 4407 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4408 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4409 | int N = ws.size(); |
| 4410 | for (int i=0; i<N; i++) { |
| 4411 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4416 | int N = ws.size(); |
| 4417 | for (int i=0; i<N; i++) { |
| 4418 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4419 | } |
| 4420 | } |
| 4421 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4422 | private static String[] includeInStringArray(String[] array, String str) { |
| 4423 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4424 | return array; |
| 4425 | } |
| 4426 | String[] newArray = new String[array.length+1]; |
| 4427 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4428 | newArray[array.length] = str; |
| 4429 | return newArray; |
| 4430 | } |
| 4431 | |
| 4432 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4433 | int index = ArrayUtils.indexOf(array, str); |
| 4434 | if (index >= 0) { |
| 4435 | String[] newArray = new String[array.length-1]; |
| 4436 | if (index > 0) { |
| 4437 | System.arraycopy(array, 0, newArray, 0, index); |
| 4438 | } |
| 4439 | if (index < array.length-1) { |
| 4440 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4441 | } |
| 4442 | return newArray; |
| 4443 | } |
| 4444 | return array; |
| 4445 | } |
| 4446 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4447 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4448 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4449 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4450 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4451 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4452 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4453 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4454 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4455 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4456 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4457 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4458 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4459 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4460 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4461 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | public void noteNetworkStatsEnabledLocked() { |
| 4466 | // During device boot, qtaguid isn't enabled until after the inital |
| 4467 | // loading of battery stats. Now that they're enabled, take our initial |
| 4468 | // snapshot for future delta calculation. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4469 | updateMobileRadioStateLocked(mClocks.elapsedRealtime(), null); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4470 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4473 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4474 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4476 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4477 | @Override public int getScreenOnCount(int which) { |
| 4478 | return mScreenOnTimer.getCountLocked(which); |
| 4479 | } |
| 4480 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4481 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4482 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4483 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4484 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4485 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4486 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4487 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4488 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4489 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4490 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4491 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4492 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4495 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4496 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4497 | } |
| 4498 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4499 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 4500 | int which) { |
| 4501 | switch (mode) { |
| 4502 | case DEVICE_IDLE_MODE_LIGHT: |
| 4503 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4504 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4505 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4506 | } |
| 4507 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4508 | } |
| 4509 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4510 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 4511 | switch (mode) { |
| 4512 | case DEVICE_IDLE_MODE_LIGHT: |
| 4513 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4514 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4515 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 4516 | } |
| 4517 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4518 | } |
| 4519 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4520 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 4521 | switch (mode) { |
| 4522 | case DEVICE_IDLE_MODE_LIGHT: |
| 4523 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4524 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4525 | return mLongestFullIdleTime; |
| 4526 | } |
| 4527 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4530 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 4531 | switch (mode) { |
| 4532 | case DEVICE_IDLE_MODE_LIGHT: |
| 4533 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4534 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4535 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4536 | } |
| 4537 | return 0; |
| 4538 | } |
| 4539 | |
| 4540 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 4541 | switch (mode) { |
| 4542 | case DEVICE_IDLE_MODE_LIGHT: |
| 4543 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4544 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4545 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4546 | } |
| 4547 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4550 | @Override public int getNumConnectivityChange(int which) { |
| 4551 | int val = mNumConnectivityChange; |
| 4552 | if (which == STATS_CURRENT) { |
| 4553 | val -= mLoadedNumConnectivityChange; |
| 4554 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4555 | val -= mUnpluggedNumConnectivityChange; |
| 4556 | } |
| 4557 | return val; |
| 4558 | } |
| 4559 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4560 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4561 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4563 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4564 | @Override public int getPhoneOnCount(int which) { |
| 4565 | return mPhoneOnTimer.getCountLocked(which); |
| 4566 | } |
| 4567 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4568 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4569 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4570 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4571 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4572 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4573 | |
| 4574 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4575 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4576 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4577 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4580 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4581 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4582 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4583 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4584 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4585 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4586 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4587 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4588 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4589 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4590 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4591 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4592 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4593 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4594 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4595 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4596 | } |
| 4597 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4598 | @Override public int getMobileRadioActiveCount(int which) { |
| 4599 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4600 | } |
| 4601 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4602 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4603 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4604 | } |
| 4605 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4606 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4607 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4608 | } |
| 4609 | |
| 4610 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4611 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4612 | } |
| 4613 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4614 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4615 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4616 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4617 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4618 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4619 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4620 | } |
| 4621 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4622 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4623 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4624 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4625 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4629 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4630 | } |
| 4631 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4632 | @Override public long getWifiSupplStateTime(int state, |
| 4633 | long elapsedRealtimeUs, int which) { |
| 4634 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4635 | elapsedRealtimeUs, which); |
| 4636 | } |
| 4637 | |
| 4638 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4639 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4640 | } |
| 4641 | |
| 4642 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4643 | long elapsedRealtimeUs, int which) { |
| 4644 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4645 | elapsedRealtimeUs, which); |
| 4646 | } |
| 4647 | |
| 4648 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4649 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4650 | } |
| 4651 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4652 | @Override |
| 4653 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 4654 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4657 | @Override |
| 4658 | public ControllerActivityCounter getWifiControllerActivity() { |
| 4659 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4660 | } |
| 4661 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4662 | @Override |
| 4663 | public ControllerActivityCounter getModemControllerActivity() { |
| 4664 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4665 | } |
| 4666 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4667 | @Override |
| 4668 | public boolean hasBluetoothActivityReporting() { |
| 4669 | return mHasBluetoothReporting; |
| 4670 | } |
| 4671 | |
| 4672 | @Override |
| 4673 | public boolean hasWifiActivityReporting() { |
| 4674 | return mHasWifiReporting; |
| 4675 | } |
| 4676 | |
| 4677 | @Override |
| 4678 | public boolean hasModemActivityReporting() { |
| 4679 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4682 | @Override |
| 4683 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4684 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4685 | } |
| 4686 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4687 | @Override |
| 4688 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4689 | return mFlashlightOnTimer.getCountLocked(which); |
| 4690 | } |
| 4691 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4692 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4693 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4694 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4695 | } |
| 4696 | |
| 4697 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4698 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 4699 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4700 | } |
| 4701 | |
| 4702 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4703 | public long getNetworkActivityBytes(int type, int which) { |
| 4704 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4705 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4706 | } else { |
| 4707 | return 0; |
| 4708 | } |
| 4709 | } |
| 4710 | |
| 4711 | @Override |
| 4712 | public long getNetworkActivityPackets(int type, int which) { |
| 4713 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4714 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4715 | } else { |
| 4716 | return 0; |
| 4717 | } |
| 4718 | } |
| 4719 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4720 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4721 | final long currentTime = System.currentTimeMillis(); |
| 4722 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4723 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 4724 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4725 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4726 | return mStartClockTime; |
| 4727 | } |
| 4728 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4729 | @Override public String getStartPlatformVersion() { |
| 4730 | return mStartPlatformVersion; |
| 4731 | } |
| 4732 | |
| 4733 | @Override public String getEndPlatformVersion() { |
| 4734 | return mEndPlatformVersion; |
| 4735 | } |
| 4736 | |
| 4737 | @Override public int getParcelVersion() { |
| 4738 | return VERSION; |
| 4739 | } |
| 4740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4741 | @Override public boolean getIsOnBattery() { |
| 4742 | return mOnBattery; |
| 4743 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4746 | return mUidStats; |
| 4747 | } |
| 4748 | |
| 4749 | /** |
| 4750 | * The statistics associated with a particular uid. |
| 4751 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4752 | public static class Uid extends BatteryStats.Uid { |
| 4753 | /** |
| 4754 | * BatteryStatsImpl that we are associated with. |
| 4755 | */ |
| 4756 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4758 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4759 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4760 | boolean mWifiRunning; |
| 4761 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4762 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4763 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4764 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4765 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4766 | boolean mWifiScanStarted; |
| 4767 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4768 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4769 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4770 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4771 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4772 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4773 | boolean mWifiMulticastEnabled; |
| 4774 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4775 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4776 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4777 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4778 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 4779 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4780 | StopwatchTimer mForegroundActivityTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4781 | StopwatchTimer mBluetoothScanTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4782 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4783 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4784 | StopwatchTimer[] mProcessStateTimer; |
| 4785 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4786 | BatchTimer mVibratorOnTimer; |
| 4787 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4788 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4789 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4790 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4791 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4792 | LongSamplingCounter mMobileRadioActiveTime; |
| 4793 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4796 | * 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] | 4797 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4798 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4799 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4800 | |
| 4801 | /** |
| 4802 | * 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] | 4803 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4804 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4805 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 4806 | |
| 4807 | /** |
| 4808 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 4809 | * Can be null if the UID has had no such activity. |
| 4810 | */ |
| 4811 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4812 | |
| 4813 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4814 | * The CPU times we had at the last history details update. |
| 4815 | */ |
| 4816 | long mLastStepUserTime; |
| 4817 | long mLastStepSystemTime; |
| 4818 | long mCurStepUserTime; |
| 4819 | long mCurStepSystemTime; |
| 4820 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4821 | LongSamplingCounter mUserCpuTime; |
| 4822 | LongSamplingCounter mSystemCpuTime; |
| 4823 | LongSamplingCounter mCpuPower; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 4824 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4825 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4826 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4827 | * The statistics we have collected for this uid's wake locks. |
| 4828 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4829 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | |
| 4831 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4832 | * The statistics we have collected for this uid's syncs. |
| 4833 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4834 | final OverflowArrayMap<StopwatchTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4835 | |
| 4836 | /** |
| 4837 | * The statistics we have collected for this uid's jobs. |
| 4838 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4839 | final OverflowArrayMap<StopwatchTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4840 | |
| 4841 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | * The statistics we have collected for this uid's sensor activations. |
| 4843 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4844 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | |
| 4846 | /** |
| 4847 | * The statistics we have collected for this uid's processes. |
| 4848 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4849 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4850 | |
| 4851 | /** |
| 4852 | * The statistics we have collected for this uid's processes. |
| 4853 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4854 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4855 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4856 | /** |
| 4857 | * The transient wake stats we have collected for this uid's pids. |
| 4858 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4859 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4860 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4861 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 4862 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4863 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4864 | |
| 4865 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4866 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4867 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4868 | |
| 4869 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>() { |
| 4870 | @Override public Wakelock instantiateObject() { |
| 4871 | return new Wakelock(mBsi, Uid.this); |
| 4872 | } |
| 4873 | }; |
| 4874 | mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { |
| 4875 | @Override public StopwatchTimer instantiateObject() { |
| 4876 | return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 4877 | mBsi.mOnBatteryTimeBase); |
| 4878 | } |
| 4879 | }; |
| 4880 | mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { |
| 4881 | @Override public StopwatchTimer instantiateObject() { |
| 4882 | return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 4883 | mBsi.mOnBatteryTimeBase); |
| 4884 | } |
| 4885 | }; |
| 4886 | |
| 4887 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 4888 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 4889 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 4890 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
| 4891 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 4892 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4893 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4894 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 4895 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4896 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4900 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4901 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4905 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4906 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4910 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4911 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4915 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | return mSensorStats; |
| 4917 | } |
| 4918 | |
| 4919 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4920 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4921 | return mProcessStats; |
| 4922 | } |
| 4923 | |
| 4924 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4925 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | return mPackageStats; |
| 4927 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4928 | |
| 4929 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4930 | public int getUid() { |
| 4931 | return mUid; |
| 4932 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4933 | |
| 4934 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4935 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4936 | if (!mWifiRunning) { |
| 4937 | mWifiRunning = true; |
| 4938 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4939 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 4940 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4941 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4942 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4943 | } |
| 4944 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4945 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4946 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4947 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4948 | if (mWifiRunning) { |
| 4949 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4950 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4951 | } |
| 4952 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4953 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4954 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4955 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4956 | if (!mFullWifiLockOut) { |
| 4957 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4958 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4959 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 4960 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4961 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4962 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4963 | } |
| 4964 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4965 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4966 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4967 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4968 | if (mFullWifiLockOut) { |
| 4969 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4970 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4971 | } |
| 4972 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4973 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4974 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4975 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4976 | if (!mWifiScanStarted) { |
| 4977 | mWifiScanStarted = true; |
| 4978 | if (mWifiScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4979 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 4980 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4981 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4982 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4983 | } |
| 4984 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4985 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4986 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4987 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4988 | if (mWifiScanStarted) { |
| 4989 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4990 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4991 | } |
| 4992 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4993 | |
| 4994 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4995 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4996 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 4997 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4998 | csph = csph >> 3; |
| 4999 | bin++; |
| 5000 | } |
| 5001 | |
| 5002 | if (mWifiBatchedScanBinStarted == bin) return; |
| 5003 | |
| 5004 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5005 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5006 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5007 | } |
| 5008 | mWifiBatchedScanBinStarted = bin; |
| 5009 | if (mWifiBatchedScanTimer[bin] == null) { |
| 5010 | makeWifiBatchedScanBin(bin, null); |
| 5011 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5012 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5016 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5017 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5018 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5019 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5020 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5025 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5026 | if (!mWifiMulticastEnabled) { |
| 5027 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5028 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5029 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5030 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5031 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5032 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5033 | } |
| 5034 | } |
| 5035 | |
| 5036 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5037 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5038 | if (mWifiMulticastEnabled) { |
| 5039 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5040 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5041 | } |
| 5042 | } |
| 5043 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5044 | @Override |
| 5045 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5046 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5049 | @Override |
| 5050 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5051 | return mBluetoothControllerActivity; |
| 5052 | } |
| 5053 | |
| 5054 | @Override |
| 5055 | public ControllerActivityCounter getModemControllerActivity() { |
| 5056 | return mModemControllerActivity; |
| 5057 | } |
| 5058 | |
| 5059 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5060 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5061 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5062 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5063 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5064 | return mWifiControllerActivity; |
| 5065 | } |
| 5066 | |
| 5067 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5068 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5069 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5070 | NUM_BT_TX_LEVELS); |
| 5071 | } |
| 5072 | return mBluetoothControllerActivity; |
| 5073 | } |
| 5074 | |
| 5075 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5076 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5077 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5078 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5079 | } |
| 5080 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5081 | } |
| 5082 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5083 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5084 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5085 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5086 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5087 | } |
| 5088 | return mAudioTurnedOnTimer; |
| 5089 | } |
| 5090 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5091 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5092 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5093 | } |
| 5094 | |
| 5095 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5096 | if (mAudioTurnedOnTimer != null) { |
| 5097 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5098 | } |
| 5099 | } |
| 5100 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5101 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5102 | if (mAudioTurnedOnTimer != null) { |
| 5103 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5104 | } |
| 5105 | } |
| 5106 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5107 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 5108 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5109 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 5110 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5111 | } |
| 5112 | return mVideoTurnedOnTimer; |
| 5113 | } |
| 5114 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5115 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5116 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5117 | } |
| 5118 | |
| 5119 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 5120 | if (mVideoTurnedOnTimer != null) { |
| 5121 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5122 | } |
| 5123 | } |
| 5124 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5125 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 5126 | if (mVideoTurnedOnTimer != null) { |
| 5127 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5128 | } |
| 5129 | } |
| 5130 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5131 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 5132 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5133 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5134 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5135 | } |
| 5136 | return mFlashlightTurnedOnTimer; |
| 5137 | } |
| 5138 | |
| 5139 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 5140 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5141 | } |
| 5142 | |
| 5143 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 5144 | if (mFlashlightTurnedOnTimer != null) { |
| 5145 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 5150 | if (mFlashlightTurnedOnTimer != null) { |
| 5151 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 5156 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5157 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 5158 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5159 | } |
| 5160 | return mCameraTurnedOnTimer; |
| 5161 | } |
| 5162 | |
| 5163 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 5164 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5165 | } |
| 5166 | |
| 5167 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 5168 | if (mCameraTurnedOnTimer != null) { |
| 5169 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 5174 | if (mCameraTurnedOnTimer != null) { |
| 5175 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5176 | } |
| 5177 | } |
| 5178 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5179 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 5180 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5181 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5182 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5183 | } |
| 5184 | return mForegroundActivityTimer; |
| 5185 | } |
| 5186 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5187 | public StopwatchTimer createBluetoothScanTimerLocked() { |
| 5188 | if (mBluetoothScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5189 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 5190 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5191 | } |
| 5192 | return mBluetoothScanTimer; |
| 5193 | } |
| 5194 | |
| 5195 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) { |
| 5196 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5197 | } |
| 5198 | |
| 5199 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) { |
| 5200 | if (mBluetoothScanTimer != null) { |
| 5201 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 5206 | if (mBluetoothScanTimer != null) { |
| 5207 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5208 | } |
| 5209 | } |
| 5210 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5211 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5212 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5213 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5214 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5218 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5219 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5220 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5224 | public BatchTimer createVibratorOnTimerLocked() { |
| 5225 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5226 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 5227 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5228 | } |
| 5229 | return mVibratorOnTimer; |
| 5230 | } |
| 5231 | |
| 5232 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5233 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | public void noteVibratorOffLocked() { |
| 5237 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5238 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5239 | } |
| 5240 | } |
| 5241 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5242 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5243 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5244 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5245 | return 0; |
| 5246 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5247 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5248 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5249 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5250 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5251 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5252 | if (mFullWifiLockTimer == null) { |
| 5253 | return 0; |
| 5254 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5255 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5256 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5257 | |
| 5258 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5259 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5260 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5261 | return 0; |
| 5262 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5263 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5264 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5265 | |
| 5266 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5267 | public int getWifiScanCount(int which) { |
| 5268 | if (mWifiScanTimer == null) { |
| 5269 | return 0; |
| 5270 | } |
| 5271 | return mWifiScanTimer.getCountLocked(which); |
| 5272 | } |
| 5273 | |
| 5274 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5275 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5276 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5277 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5278 | return 0; |
| 5279 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5280 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5284 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 5285 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5286 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5287 | return 0; |
| 5288 | } |
| 5289 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 5290 | } |
| 5291 | |
| 5292 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5293 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5294 | if (mWifiMulticastTimer == null) { |
| 5295 | return 0; |
| 5296 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5297 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5300 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5301 | public Timer getAudioTurnedOnTimer() { |
| 5302 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5303 | } |
| 5304 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5305 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5306 | public Timer getVideoTurnedOnTimer() { |
| 5307 | return mVideoTurnedOnTimer; |
| 5308 | } |
| 5309 | |
| 5310 | @Override |
| 5311 | public Timer getFlashlightTurnedOnTimer() { |
| 5312 | return mFlashlightTurnedOnTimer; |
| 5313 | } |
| 5314 | |
| 5315 | @Override |
| 5316 | public Timer getCameraTurnedOnTimer() { |
| 5317 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5318 | } |
| 5319 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5320 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5321 | public Timer getForegroundActivityTimer() { |
| 5322 | return mForegroundActivityTimer; |
| 5323 | } |
| 5324 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5325 | @Override |
| 5326 | public Timer getBluetoothScanTimer() { |
| 5327 | return mBluetoothScanTimer; |
| 5328 | } |
| 5329 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5330 | void makeProcessState(int i, Parcel in) { |
| 5331 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 5332 | |
| 5333 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5334 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5335 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5336 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5337 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5338 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | @Override |
| 5343 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 5344 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 5345 | if (mProcessStateTimer[state] == null) { |
| 5346 | return 0; |
| 5347 | } |
| 5348 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5349 | } |
| 5350 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5351 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 5352 | public Timer getProcessStateTimer(int state) { |
| 5353 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 5354 | return mProcessStateTimer[state]; |
| 5355 | } |
| 5356 | |
| 5357 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5358 | public Timer getVibratorOnTimer() { |
| 5359 | return mVibratorOnTimer; |
| 5360 | } |
| 5361 | |
| 5362 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5363 | public void noteUserActivityLocked(int type) { |
| 5364 | if (mUserActivityCounters == null) { |
| 5365 | initUserActivityLocked(); |
| 5366 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 5367 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 5368 | mUserActivityCounters[type].stepAtomic(); |
| 5369 | } else { |
| 5370 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 5371 | new Throwable()); |
| 5372 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5373 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5374 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5375 | @Override |
| 5376 | public boolean hasUserActivity() { |
| 5377 | return mUserActivityCounters != null; |
| 5378 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5379 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5380 | @Override |
| 5381 | public int getUserActivityCount(int type, int which) { |
| 5382 | if (mUserActivityCounters == null) { |
| 5383 | return 0; |
| 5384 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5385 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5386 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5387 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5388 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 5389 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 5390 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5391 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5392 | if (collected == null) { |
| 5393 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5394 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5395 | } |
| 5396 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5397 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5398 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5399 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5400 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5401 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5406 | void initUserActivityLocked() { |
| 5407 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5408 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5409 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5410 | } |
| 5411 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5412 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5413 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5414 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5415 | initNetworkActivityLocked(); |
| 5416 | } |
| 5417 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5418 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5419 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5420 | } else { |
| 5421 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5422 | new Throwable()); |
| 5423 | } |
| 5424 | } |
| 5425 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5426 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5427 | if (mNetworkByteActivityCounters == null) { |
| 5428 | initNetworkActivityLocked(); |
| 5429 | } |
| 5430 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5431 | mMobileRadioActiveCount.addCountLocked(1); |
| 5432 | } |
| 5433 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5434 | @Override |
| 5435 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5436 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5440 | public long getNetworkActivityBytes(int type, int which) { |
| 5441 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5442 | && type < mNetworkByteActivityCounters.length) { |
| 5443 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5444 | } else { |
| 5445 | return 0; |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | @Override |
| 5450 | public long getNetworkActivityPackets(int type, int which) { |
| 5451 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5452 | && type < mNetworkPacketActivityCounters.length) { |
| 5453 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5454 | } else { |
| 5455 | return 0; |
| 5456 | } |
| 5457 | } |
| 5458 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5459 | @Override |
| 5460 | public long getMobileRadioActiveTime(int which) { |
| 5461 | return mMobileRadioActiveTime != null |
| 5462 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5463 | } |
| 5464 | |
| 5465 | @Override |
| 5466 | public int getMobileRadioActiveCount(int which) { |
| 5467 | return mMobileRadioActiveCount != null |
| 5468 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5469 | } |
| 5470 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5471 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5472 | public long getUserCpuTimeUs(int which) { |
| 5473 | return mUserCpuTime.getCountLocked(which); |
| 5474 | } |
| 5475 | |
| 5476 | @Override |
| 5477 | public long getSystemCpuTimeUs(int which) { |
| 5478 | return mSystemCpuTime.getCountLocked(which); |
| 5479 | } |
| 5480 | |
| 5481 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5482 | public long getCpuPowerMaUs(int which) { |
| 5483 | return mCpuPower.getCountLocked(which); |
| 5484 | } |
| 5485 | |
| 5486 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5487 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 5488 | if (mCpuClusterSpeed != null) { |
| 5489 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 5490 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 5491 | if (cpuSpeeds != null) { |
| 5492 | if (step >= 0 && step < cpuSpeeds.length) { |
| 5493 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 5494 | if (c != null) { |
| 5495 | return c.getCountLocked(which); |
| 5496 | } |
| 5497 | } |
| 5498 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5499 | } |
| 5500 | } |
| 5501 | return 0; |
| 5502 | } |
| 5503 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5504 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5505 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5506 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5507 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5508 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5509 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5510 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5511 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5512 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5514 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5515 | /** |
| 5516 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5517 | * inactive so can be dropped. |
| 5518 | */ |
| 5519 | boolean reset() { |
| 5520 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5521 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5522 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5523 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5524 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5525 | } |
| 5526 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5527 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5528 | active |= mFullWifiLockOut; |
| 5529 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5530 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5531 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5532 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5533 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5534 | if (mWifiBatchedScanTimer != null) { |
| 5535 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5536 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5537 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5538 | } |
| 5539 | } |
| 5540 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5541 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5542 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5543 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5544 | active |= mWifiMulticastEnabled; |
| 5545 | } |
| 5546 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5547 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5548 | } |
| 5549 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5550 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5551 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5552 | if (mFlashlightTurnedOnTimer != null) { |
| 5553 | active |= !mFlashlightTurnedOnTimer.reset(false); |
| 5554 | } |
| 5555 | if (mCameraTurnedOnTimer != null) { |
| 5556 | active |= !mCameraTurnedOnTimer.reset(false); |
| 5557 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5558 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5559 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5560 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5561 | if (mBluetoothScanTimer != null) { |
| 5562 | active |= !mBluetoothScanTimer.reset(false); |
| 5563 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5564 | if (mProcessStateTimer != null) { |
| 5565 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5566 | if (mProcessStateTimer[i] != null) { |
| 5567 | active |= !mProcessStateTimer[i].reset(false); |
| 5568 | } |
| 5569 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5570 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5571 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5572 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5573 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5574 | mVibratorOnTimer.detach(); |
| 5575 | mVibratorOnTimer = null; |
| 5576 | } else { |
| 5577 | active = true; |
| 5578 | } |
| 5579 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5580 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5581 | if (mUserActivityCounters != null) { |
| 5582 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5583 | mUserActivityCounters[i].reset(false); |
| 5584 | } |
| 5585 | } |
| 5586 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5587 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5588 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5589 | mNetworkByteActivityCounters[i].reset(false); |
| 5590 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5591 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5592 | mMobileRadioActiveTime.reset(false); |
| 5593 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5594 | } |
| 5595 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5596 | if (mWifiControllerActivity != null) { |
| 5597 | mWifiControllerActivity.reset(false); |
| 5598 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5599 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5600 | if (mBsi.mBluetoothActivity != null) { |
| 5601 | mBsi.mBluetoothActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5602 | } |
| 5603 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5604 | if (mBsi.mModemActivity != null) { |
| 5605 | mBsi.mModemActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5608 | mUserCpuTime.reset(false); |
| 5609 | mSystemCpuTime.reset(false); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5610 | mCpuPower.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5611 | |
| 5612 | if (mCpuClusterSpeed != null) { |
| 5613 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 5614 | if (speeds != null) { |
| 5615 | for (LongSamplingCounter speed : speeds) { |
| 5616 | if (speed != null) { |
| 5617 | speed.reset(false); |
| 5618 | } |
| 5619 | } |
| 5620 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5621 | } |
| 5622 | } |
| 5623 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5624 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5625 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5626 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5627 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5628 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5629 | } else { |
| 5630 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5631 | } |
| 5632 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5633 | mWakelockStats.cleanup(); |
| 5634 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5635 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5636 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5637 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5638 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5639 | timer.detach(); |
| 5640 | } else { |
| 5641 | active = true; |
| 5642 | } |
| 5643 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5644 | mSyncStats.cleanup(); |
| 5645 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5646 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5647 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5648 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5649 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5650 | timer.detach(); |
| 5651 | } else { |
| 5652 | active = true; |
| 5653 | } |
| 5654 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5655 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5656 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5657 | Sensor s = mSensorStats.valueAt(ise); |
| 5658 | if (s.reset()) { |
| 5659 | mSensorStats.removeAt(ise); |
| 5660 | } else { |
| 5661 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5662 | } |
| 5663 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5664 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5665 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5666 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5667 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5668 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5669 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5670 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5671 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5672 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5673 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5674 | } else { |
| 5675 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5679 | if (mPackageStats.size() > 0) { |
| 5680 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5681 | while (it.hasNext()) { |
| 5682 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5683 | Pkg p = pkgEntry.getValue(); |
| 5684 | p.detach(); |
| 5685 | if (p.mServiceStats.size() > 0) { |
| 5686 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5687 | = p.mServiceStats.entrySet().iterator(); |
| 5688 | while (it2.hasNext()) { |
| 5689 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5690 | servEntry.getValue().detach(); |
| 5691 | } |
| 5692 | } |
| 5693 | } |
| 5694 | mPackageStats.clear(); |
| 5695 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5696 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5697 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5698 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5699 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5700 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5701 | if (mWifiRunningTimer != null) { |
| 5702 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5703 | } |
| 5704 | if (mFullWifiLockTimer != null) { |
| 5705 | mFullWifiLockTimer.detach(); |
| 5706 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5707 | if (mWifiScanTimer != null) { |
| 5708 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5709 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5710 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5711 | if (mWifiBatchedScanTimer[i] != null) { |
| 5712 | mWifiBatchedScanTimer[i].detach(); |
| 5713 | } |
| 5714 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5715 | if (mWifiMulticastTimer != null) { |
| 5716 | mWifiMulticastTimer.detach(); |
| 5717 | } |
| 5718 | if (mAudioTurnedOnTimer != null) { |
| 5719 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5720 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5721 | } |
| 5722 | if (mVideoTurnedOnTimer != null) { |
| 5723 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5724 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5725 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5726 | if (mFlashlightTurnedOnTimer != null) { |
| 5727 | mFlashlightTurnedOnTimer.detach(); |
| 5728 | mFlashlightTurnedOnTimer = null; |
| 5729 | } |
| 5730 | if (mCameraTurnedOnTimer != null) { |
| 5731 | mCameraTurnedOnTimer.detach(); |
| 5732 | mCameraTurnedOnTimer = null; |
| 5733 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5734 | if (mForegroundActivityTimer != null) { |
| 5735 | mForegroundActivityTimer.detach(); |
| 5736 | mForegroundActivityTimer = null; |
| 5737 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5738 | if (mBluetoothScanTimer != null) { |
| 5739 | mBluetoothScanTimer.detach(); |
| 5740 | mBluetoothScanTimer = null; |
| 5741 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5742 | if (mUserActivityCounters != null) { |
| 5743 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5744 | mUserActivityCounters[i].detach(); |
| 5745 | } |
| 5746 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5747 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5748 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5749 | mNetworkByteActivityCounters[i].detach(); |
| 5750 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5751 | } |
| 5752 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5753 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5754 | if (mWifiControllerActivity != null) { |
| 5755 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5756 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5757 | |
| 5758 | if (mBluetoothControllerActivity != null) { |
| 5759 | mBluetoothControllerActivity.detach(); |
| 5760 | } |
| 5761 | |
| 5762 | if (mModemControllerActivity != null) { |
| 5763 | mModemControllerActivity.detach(); |
| 5764 | } |
| 5765 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5766 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5767 | |
| 5768 | mUserCpuTime.detach(); |
| 5769 | mSystemCpuTime.detach(); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5770 | mCpuPower.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5771 | |
| 5772 | if (mCpuClusterSpeed != null) { |
| 5773 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5774 | if (cpuSpeeds != null) { |
| 5775 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5776 | if (c != null) { |
| 5777 | c.detach(); |
| 5778 | } |
| 5779 | } |
| 5780 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5781 | } |
| 5782 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5783 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5784 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5785 | return !active; |
| 5786 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5787 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5788 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5789 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5790 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5791 | out.writeInt(NW); |
| 5792 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5793 | out.writeString(wakeStats.keyAt(iw)); |
| 5794 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5795 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5796 | } |
| 5797 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5798 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5799 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5800 | out.writeInt(NS); |
| 5801 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5802 | out.writeString(syncStats.keyAt(is)); |
| 5803 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5804 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5805 | } |
| 5806 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5807 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5808 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5809 | out.writeInt(NJ); |
| 5810 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5811 | out.writeString(jobStats.keyAt(ij)); |
| 5812 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5813 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5814 | } |
| 5815 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5816 | int NSE = mSensorStats.size(); |
| 5817 | out.writeInt(NSE); |
| 5818 | for (int ise=0; ise<NSE; ise++) { |
| 5819 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5820 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5821 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | } |
| 5823 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5824 | int NP = mProcessStats.size(); |
| 5825 | out.writeInt(NP); |
| 5826 | for (int ip=0; ip<NP; ip++) { |
| 5827 | out.writeString(mProcessStats.keyAt(ip)); |
| 5828 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5829 | proc.writeToParcelLocked(out); |
| 5830 | } |
| 5831 | |
| 5832 | out.writeInt(mPackageStats.size()); |
| 5833 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5834 | out.writeString(pkgEntry.getKey()); |
| 5835 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5836 | pkg.writeToParcelLocked(out); |
| 5837 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5838 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5839 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5840 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5841 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5842 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5843 | out.writeInt(0); |
| 5844 | } |
| 5845 | if (mFullWifiLockTimer != null) { |
| 5846 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5847 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5848 | } else { |
| 5849 | out.writeInt(0); |
| 5850 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5851 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5852 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5853 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5854 | } else { |
| 5855 | out.writeInt(0); |
| 5856 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5857 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5858 | if (mWifiBatchedScanTimer[i] != null) { |
| 5859 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5860 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5861 | } else { |
| 5862 | out.writeInt(0); |
| 5863 | } |
| 5864 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5865 | if (mWifiMulticastTimer != null) { |
| 5866 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5867 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5868 | } else { |
| 5869 | out.writeInt(0); |
| 5870 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5871 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5872 | if (mAudioTurnedOnTimer != null) { |
| 5873 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5874 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5875 | } else { |
| 5876 | out.writeInt(0); |
| 5877 | } |
| 5878 | if (mVideoTurnedOnTimer != null) { |
| 5879 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5880 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5881 | } else { |
| 5882 | out.writeInt(0); |
| 5883 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5884 | if (mFlashlightTurnedOnTimer != null) { |
| 5885 | out.writeInt(1); |
| 5886 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5887 | } else { |
| 5888 | out.writeInt(0); |
| 5889 | } |
| 5890 | if (mCameraTurnedOnTimer != null) { |
| 5891 | out.writeInt(1); |
| 5892 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5893 | } else { |
| 5894 | out.writeInt(0); |
| 5895 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5896 | if (mForegroundActivityTimer != null) { |
| 5897 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5898 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5899 | } else { |
| 5900 | out.writeInt(0); |
| 5901 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5902 | if (mBluetoothScanTimer != null) { |
| 5903 | out.writeInt(1); |
| 5904 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5905 | } else { |
| 5906 | out.writeInt(0); |
| 5907 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5908 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5909 | if (mProcessStateTimer[i] != null) { |
| 5910 | out.writeInt(1); |
| 5911 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 5912 | } else { |
| 5913 | out.writeInt(0); |
| 5914 | } |
| 5915 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5916 | if (mVibratorOnTimer != null) { |
| 5917 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5918 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5919 | } else { |
| 5920 | out.writeInt(0); |
| 5921 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5922 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5923 | out.writeInt(1); |
| 5924 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5925 | mUserActivityCounters[i].writeToParcel(out); |
| 5926 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5927 | } else { |
| 5928 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5929 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5930 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5931 | out.writeInt(1); |
| 5932 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5933 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 5934 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5935 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5936 | mMobileRadioActiveTime.writeToParcel(out); |
| 5937 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5938 | } else { |
| 5939 | out.writeInt(0); |
| 5940 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5941 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5942 | if (mWifiControllerActivity != null) { |
| 5943 | out.writeInt(1); |
| 5944 | mWifiControllerActivity.writeToParcel(out, 0); |
| 5945 | } else { |
| 5946 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5949 | if (mBluetoothControllerActivity != null) { |
| 5950 | out.writeInt(1); |
| 5951 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 5952 | } else { |
| 5953 | out.writeInt(0); |
| 5954 | } |
| 5955 | |
| 5956 | if (mModemControllerActivity != null) { |
| 5957 | out.writeInt(1); |
| 5958 | mModemControllerActivity.writeToParcel(out, 0); |
| 5959 | } else { |
| 5960 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5961 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5962 | |
| 5963 | mUserCpuTime.writeToParcel(out); |
| 5964 | mSystemCpuTime.writeToParcel(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5965 | mCpuPower.writeToParcel(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5966 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5967 | if (mCpuClusterSpeed != null) { |
| 5968 | out.writeInt(1); |
| 5969 | out.writeInt(mCpuClusterSpeed.length); |
| 5970 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5971 | if (cpuSpeeds != null) { |
| 5972 | out.writeInt(1); |
| 5973 | out.writeInt(cpuSpeeds.length); |
| 5974 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5975 | if (c != null) { |
| 5976 | out.writeInt(1); |
| 5977 | c.writeToParcel(out); |
| 5978 | } else { |
| 5979 | out.writeInt(0); |
| 5980 | } |
| 5981 | } |
| 5982 | } else { |
| 5983 | out.writeInt(0); |
| 5984 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5985 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5986 | } else { |
| 5987 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5988 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5989 | } |
| 5990 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5991 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | int numWakelocks = in.readInt(); |
| 5993 | mWakelockStats.clear(); |
| 5994 | for (int j = 0; j < numWakelocks; j++) { |
| 5995 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5996 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5997 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5998 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5999 | } |
| 6000 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6001 | int numSyncs = in.readInt(); |
| 6002 | mSyncStats.clear(); |
| 6003 | for (int j = 0; j < numSyncs; j++) { |
| 6004 | String syncName = in.readString(); |
| 6005 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6006 | mSyncStats.add(syncName, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6007 | new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6008 | } |
| 6009 | } |
| 6010 | |
| 6011 | int numJobs = in.readInt(); |
| 6012 | mJobStats.clear(); |
| 6013 | for (int j = 0; j < numJobs; j++) { |
| 6014 | String jobName = in.readString(); |
| 6015 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6016 | mJobStats.add(jobName, new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6017 | timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6018 | } |
| 6019 | } |
| 6020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6021 | int numSensors = in.readInt(); |
| 6022 | mSensorStats.clear(); |
| 6023 | for (int k = 0; k < numSensors; k++) { |
| 6024 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6025 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
| 6026 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6027 | mSensorStats.put(sensorNumber, sensor); |
| 6028 | } |
| 6029 | |
| 6030 | int numProcs = in.readInt(); |
| 6031 | mProcessStats.clear(); |
| 6032 | for (int k = 0; k < numProcs; k++) { |
| 6033 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6034 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6035 | proc.readFromParcelLocked(in); |
| 6036 | mProcessStats.put(processName, proc); |
| 6037 | } |
| 6038 | |
| 6039 | int numPkgs = in.readInt(); |
| 6040 | mPackageStats.clear(); |
| 6041 | for (int l = 0; l < numPkgs; l++) { |
| 6042 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6043 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6044 | pkg.readFromParcelLocked(in); |
| 6045 | mPackageStats.put(packageName, pkg); |
| 6046 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6047 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6048 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6049 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6050 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6051 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6052 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6053 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6054 | } |
| 6055 | mFullWifiLockOut = false; |
| 6056 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6057 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6058 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6059 | } else { |
| 6060 | mFullWifiLockTimer = null; |
| 6061 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6062 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6063 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6064 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6065 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6066 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6067 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6068 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6069 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6070 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6071 | if (in.readInt() != 0) { |
| 6072 | makeWifiBatchedScanBin(i, in); |
| 6073 | } else { |
| 6074 | mWifiBatchedScanTimer[i] = null; |
| 6075 | } |
| 6076 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6077 | mWifiMulticastEnabled = false; |
| 6078 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6079 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 6080 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6081 | } else { |
| 6082 | mWifiMulticastTimer = null; |
| 6083 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6084 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6085 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6086 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6087 | } else { |
| 6088 | mAudioTurnedOnTimer = null; |
| 6089 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6090 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6091 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6092 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6093 | } else { |
| 6094 | mVideoTurnedOnTimer = null; |
| 6095 | } |
| 6096 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6097 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6098 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6099 | } else { |
| 6100 | mFlashlightTurnedOnTimer = null; |
| 6101 | } |
| 6102 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6103 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6104 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6105 | } else { |
| 6106 | mCameraTurnedOnTimer = null; |
| 6107 | } |
| 6108 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6109 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6110 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6111 | } else { |
| 6112 | mForegroundActivityTimer = null; |
| 6113 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6114 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6115 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6116 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6117 | } else { |
| 6118 | mBluetoothScanTimer = null; |
| 6119 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6120 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6121 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6122 | if (in.readInt() != 0) { |
| 6123 | makeProcessState(i, in); |
| 6124 | } else { |
| 6125 | mProcessStateTimer[i] = null; |
| 6126 | } |
| 6127 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6128 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6129 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6130 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6131 | } else { |
| 6132 | mVibratorOnTimer = null; |
| 6133 | } |
| 6134 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6135 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6136 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6137 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6138 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6139 | } else { |
| 6140 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6141 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6142 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6143 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6144 | mNetworkPacketActivityCounters |
| 6145 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6146 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6147 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6148 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6149 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6150 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6151 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6152 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6153 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6154 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6155 | mNetworkByteActivityCounters = null; |
| 6156 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6157 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6158 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6159 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6160 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6161 | NUM_WIFI_TX_LEVELS, in); |
| 6162 | } else { |
| 6163 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6164 | } |
| 6165 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6166 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6167 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6168 | NUM_BT_TX_LEVELS, in); |
| 6169 | } else { |
| 6170 | mBluetoothControllerActivity = null; |
| 6171 | } |
| 6172 | |
| 6173 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6174 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6175 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 6176 | } else { |
| 6177 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6178 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6179 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6180 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6181 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6182 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6183 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6184 | if (in.readInt() != 0) { |
| 6185 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6186 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6187 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6188 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6189 | |
| 6190 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 6191 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 6192 | if (in.readInt() != 0) { |
| 6193 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6194 | if (mBsi.mPowerProfile != null && |
| 6195 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6196 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 6197 | } |
| 6198 | |
| 6199 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 6200 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 6201 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 6202 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6203 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6204 | } |
| 6205 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 6206 | } else { |
| 6207 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6208 | } |
| 6209 | } |
| 6210 | } else { |
| 6211 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6212 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | /** |
| 6216 | * The statistics associated with a particular wake lock. |
| 6217 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6218 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 6219 | /** |
| 6220 | * BatteryStatsImpl that we are associated with. |
| 6221 | */ |
| 6222 | protected BatteryStatsImpl mBsi; |
| 6223 | |
| 6224 | /** |
| 6225 | * BatteryStatsImpl that we are associated with. |
| 6226 | */ |
| 6227 | protected Uid mUid; |
| 6228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | /** |
| 6230 | * How long (in ms) this uid has been keeping the device partially awake. |
| 6231 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6232 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6233 | |
| 6234 | /** |
| 6235 | * How long (in ms) this uid has been keeping the device fully awake. |
| 6236 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6237 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | |
| 6239 | /** |
| 6240 | * How long (in ms) this uid has had a window keeping the device awake. |
| 6241 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6242 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | |
| 6244 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6245 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6246 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6247 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6248 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6249 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 6250 | mBsi = bsi; |
| 6251 | mUid = uid; |
| 6252 | } |
| 6253 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6254 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6255 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 6256 | * proper timer pool from the given BatteryStatsImpl object. |
| 6257 | * |
| 6258 | * @param in the Parcel to be read from. |
| 6259 | * return a new Timer, or null. |
| 6260 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6261 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6262 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | if (in.readInt() == 0) { |
| 6264 | return null; |
| 6265 | } |
| 6266 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6267 | 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] | 6268 | } |
| 6269 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6270 | boolean reset() { |
| 6271 | boolean wlactive = false; |
| 6272 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6273 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6274 | } |
| 6275 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6276 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6277 | } |
| 6278 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6279 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6280 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6281 | if (mTimerDraw != null) { |
| 6282 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6283 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6284 | if (!wlactive) { |
| 6285 | if (mTimerFull != null) { |
| 6286 | mTimerFull.detach(); |
| 6287 | mTimerFull = null; |
| 6288 | } |
| 6289 | if (mTimerPartial != null) { |
| 6290 | mTimerPartial.detach(); |
| 6291 | mTimerPartial = null; |
| 6292 | } |
| 6293 | if (mTimerWindow != null) { |
| 6294 | mTimerWindow.detach(); |
| 6295 | mTimerWindow = null; |
| 6296 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6297 | if (mTimerDraw != null) { |
| 6298 | mTimerDraw.detach(); |
| 6299 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6300 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6301 | } |
| 6302 | return !wlactive; |
| 6303 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6304 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6305 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6306 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6307 | mBsi.mPartialTimers, screenOffTimeBase, in); |
| 6308 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, mBsi.mFullTimers, timeBase, in); |
| 6309 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, mBsi.mWindowTimers, timeBase, in); |
| 6310 | mTimerDraw = readTimerFromParcel(WAKE_TYPE_DRAW, mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | } |
| 6312 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6313 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6314 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 6315 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 6316 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6317 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | @Override |
| 6321 | public Timer getWakeTime(int type) { |
| 6322 | switch (type) { |
| 6323 | case WAKE_TYPE_FULL: return mTimerFull; |
| 6324 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 6325 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6326 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | default: throw new IllegalArgumentException("type = " + type); |
| 6328 | } |
| 6329 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6330 | |
| 6331 | public StopwatchTimer getStopwatchTimer(int type) { |
| 6332 | StopwatchTimer t; |
| 6333 | switch (type) { |
| 6334 | case WAKE_TYPE_PARTIAL: |
| 6335 | t = mTimerPartial; |
| 6336 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6337 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_PARTIAL, |
| 6338 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6339 | mTimerPartial = t; |
| 6340 | } |
| 6341 | return t; |
| 6342 | case WAKE_TYPE_FULL: |
| 6343 | t = mTimerFull; |
| 6344 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6345 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_FULL, |
| 6346 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6347 | mTimerFull = t; |
| 6348 | } |
| 6349 | return t; |
| 6350 | case WAKE_TYPE_WINDOW: |
| 6351 | t = mTimerWindow; |
| 6352 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6353 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_WINDOW, |
| 6354 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6355 | mTimerWindow = t; |
| 6356 | } |
| 6357 | return t; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6358 | case WAKE_TYPE_DRAW: |
| 6359 | t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6360 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6361 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_DRAW, |
| 6362 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6363 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6364 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6365 | return t; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6366 | default: |
| 6367 | throw new IllegalArgumentException("type=" + type); |
| 6368 | } |
| 6369 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6370 | } |
| 6371 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6372 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 6373 | /** |
| 6374 | * BatteryStatsImpl that we are associated with. |
| 6375 | */ |
| 6376 | protected BatteryStatsImpl mBsi; |
| 6377 | |
| 6378 | /** |
| 6379 | * BatteryStatsImpl that we are associated with. |
| 6380 | */ |
| 6381 | protected Uid mUid; |
| 6382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6383 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6384 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6385 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6386 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 6387 | mBsi = bsi; |
| 6388 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | mHandle = handle; |
| 6390 | } |
| 6391 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6392 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6393 | if (in.readInt() == 0) { |
| 6394 | return null; |
| 6395 | } |
| 6396 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6397 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6399 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6400 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6402 | 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] | 6403 | } |
| 6404 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6405 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6406 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6407 | mTimer = null; |
| 6408 | return true; |
| 6409 | } |
| 6410 | return false; |
| 6411 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6412 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6413 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 6414 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | } |
| 6416 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6417 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6418 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | @Override |
| 6422 | public Timer getSensorTime() { |
| 6423 | return mTimer; |
| 6424 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6425 | |
| 6426 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6427 | public int getHandle() { |
| 6428 | return mHandle; |
| 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | /** |
| 6433 | * The statistics associated with a particular process. |
| 6434 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6435 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 6436 | /** |
| 6437 | * BatteryStatsImpl that we are associated with. |
| 6438 | */ |
| 6439 | protected BatteryStatsImpl mBsi; |
| 6440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6441 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6442 | * The name of this process. |
| 6443 | */ |
| 6444 | final String mName; |
| 6445 | |
| 6446 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6447 | * Remains true until removed from the stats. |
| 6448 | */ |
| 6449 | boolean mActive = true; |
| 6450 | |
| 6451 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6452 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | */ |
| 6454 | long mUserTime; |
| 6455 | |
| 6456 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6457 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | */ |
| 6459 | long mSystemTime; |
| 6460 | |
| 6461 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6462 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6463 | */ |
| 6464 | long mForegroundTime; |
| 6465 | |
| 6466 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6467 | * Number of times the process has been started. |
| 6468 | */ |
| 6469 | int mStarts; |
| 6470 | |
| 6471 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6472 | * Number of times the process has crashed. |
| 6473 | */ |
| 6474 | int mNumCrashes; |
| 6475 | |
| 6476 | /** |
| 6477 | * Number of times the process has had an ANR. |
| 6478 | */ |
| 6479 | int mNumAnrs; |
| 6480 | |
| 6481 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | * The amount of user time loaded from a previous save. |
| 6483 | */ |
| 6484 | long mLoadedUserTime; |
| 6485 | |
| 6486 | /** |
| 6487 | * The amount of system time loaded from a previous save. |
| 6488 | */ |
| 6489 | long mLoadedSystemTime; |
| 6490 | |
| 6491 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6492 | * The amount of foreground time loaded from a previous save. |
| 6493 | */ |
| 6494 | long mLoadedForegroundTime; |
| 6495 | |
| 6496 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6497 | * The number of times the process has started from a previous save. |
| 6498 | */ |
| 6499 | int mLoadedStarts; |
| 6500 | |
| 6501 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6502 | * 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] | 6503 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6504 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | |
| 6506 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6507 | * 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] | 6508 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6509 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6510 | |
| 6511 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6512 | * The amount of user time when last unplugged. |
| 6513 | */ |
| 6514 | long mUnpluggedUserTime; |
| 6515 | |
| 6516 | /** |
| 6517 | * The amount of system time when last unplugged. |
| 6518 | */ |
| 6519 | long mUnpluggedSystemTime; |
| 6520 | |
| 6521 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6522 | * The amount of foreground time since unplugged. |
| 6523 | */ |
| 6524 | long mUnpluggedForegroundTime; |
| 6525 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6526 | /** |
| 6527 | * The number of times the process has started before unplugged. |
| 6528 | */ |
| 6529 | int mUnpluggedStarts; |
| 6530 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6531 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6532 | * Number of times the process has crashed before unplugged. |
| 6533 | */ |
| 6534 | int mUnpluggedNumCrashes; |
| 6535 | |
| 6536 | /** |
| 6537 | * Number of times the process has had an ANR before unplugged. |
| 6538 | */ |
| 6539 | int mUnpluggedNumAnrs; |
| 6540 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6541 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6542 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6543 | public Proc(BatteryStatsImpl bsi, String name) { |
| 6544 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6545 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6546 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6548 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6549 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | mUnpluggedUserTime = mUserTime; |
| 6551 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6552 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6553 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6554 | mUnpluggedNumCrashes = mNumCrashes; |
| 6555 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6556 | } |
| 6557 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6558 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6560 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6561 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6562 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6563 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6564 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6565 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6566 | public int countExcessivePowers() { |
| 6567 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6570 | public ExcessivePower getExcessivePower(int i) { |
| 6571 | if (mExcessivePower != null) { |
| 6572 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6573 | } |
| 6574 | return null; |
| 6575 | } |
| 6576 | |
| 6577 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6578 | if (mExcessivePower == null) { |
| 6579 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6580 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6581 | ExcessivePower ew = new ExcessivePower(); |
| 6582 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6583 | ew.overTime = overTime; |
| 6584 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6585 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6586 | } |
| 6587 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6588 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 6589 | if (mExcessivePower == null) { |
| 6590 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 6591 | } |
| 6592 | ExcessivePower ew = new ExcessivePower(); |
| 6593 | ew.type = ExcessivePower.TYPE_CPU; |
| 6594 | ew.overTime = overTime; |
| 6595 | ew.usedTime = usedTime; |
| 6596 | mExcessivePower.add(ew); |
| 6597 | } |
| 6598 | |
| 6599 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 6600 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6601 | out.writeInt(0); |
| 6602 | return; |
| 6603 | } |
| 6604 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6605 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6606 | out.writeInt(N); |
| 6607 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6608 | ExcessivePower ew = mExcessivePower.get(i); |
| 6609 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6610 | out.writeLong(ew.overTime); |
| 6611 | out.writeLong(ew.usedTime); |
| 6612 | } |
| 6613 | } |
| 6614 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6615 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6616 | final int N = in.readInt(); |
| 6617 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6618 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6619 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6620 | } |
| 6621 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6622 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6623 | throw new ParcelFormatException( |
| 6624 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6625 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6626 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6627 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6628 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6629 | ExcessivePower ew = new ExcessivePower(); |
| 6630 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6631 | ew.overTime = in.readLong(); |
| 6632 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6633 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6634 | } |
| 6635 | } |
| 6636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6637 | void writeToParcelLocked(Parcel out) { |
| 6638 | out.writeLong(mUserTime); |
| 6639 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6640 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6641 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6642 | out.writeInt(mNumCrashes); |
| 6643 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | out.writeLong(mLoadedUserTime); |
| 6645 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6646 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6648 | out.writeInt(mLoadedNumCrashes); |
| 6649 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | out.writeLong(mUnpluggedUserTime); |
| 6651 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6652 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6653 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6654 | out.writeInt(mUnpluggedNumCrashes); |
| 6655 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6656 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | void readFromParcelLocked(Parcel in) { |
| 6660 | mUserTime = in.readLong(); |
| 6661 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6662 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6663 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6664 | mNumCrashes = in.readInt(); |
| 6665 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6666 | mLoadedUserTime = in.readLong(); |
| 6667 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6668 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6669 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6670 | mLoadedNumCrashes = in.readInt(); |
| 6671 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | mUnpluggedUserTime = in.readLong(); |
| 6673 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6674 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6675 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6676 | mUnpluggedNumCrashes = in.readInt(); |
| 6677 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6678 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | } |
| 6680 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6681 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6682 | mUserTime += utime; |
| 6683 | mSystemTime += stime; |
| 6684 | } |
| 6685 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6686 | public void addForegroundTimeLocked(long ttime) { |
| 6687 | mForegroundTime += ttime; |
| 6688 | } |
| 6689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6690 | public void incStartsLocked() { |
| 6691 | mStarts++; |
| 6692 | } |
| 6693 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6694 | public void incNumCrashesLocked() { |
| 6695 | mNumCrashes++; |
| 6696 | } |
| 6697 | |
| 6698 | public void incNumAnrsLocked() { |
| 6699 | mNumAnrs++; |
| 6700 | } |
| 6701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6703 | public boolean isActive() { |
| 6704 | return mActive; |
| 6705 | } |
| 6706 | |
| 6707 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6709 | long val = mUserTime; |
| 6710 | if (which == STATS_CURRENT) { |
| 6711 | val -= mLoadedUserTime; |
| 6712 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6713 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6714 | } |
| 6715 | return val; |
| 6716 | } |
| 6717 | |
| 6718 | @Override |
| 6719 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6720 | long val = mSystemTime; |
| 6721 | if (which == STATS_CURRENT) { |
| 6722 | val -= mLoadedSystemTime; |
| 6723 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6724 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | } |
| 6726 | return val; |
| 6727 | } |
| 6728 | |
| 6729 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6730 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6731 | long val = mForegroundTime; |
| 6732 | if (which == STATS_CURRENT) { |
| 6733 | val -= mLoadedForegroundTime; |
| 6734 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6735 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6736 | } |
| 6737 | return val; |
| 6738 | } |
| 6739 | |
| 6740 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6742 | int val = mStarts; |
| 6743 | if (which == STATS_CURRENT) { |
| 6744 | val -= mLoadedStarts; |
| 6745 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6746 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | } |
| 6748 | return val; |
| 6749 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6750 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6751 | @Override |
| 6752 | public int getNumCrashes(int which) { |
| 6753 | int val = mNumCrashes; |
| 6754 | if (which == STATS_CURRENT) { |
| 6755 | val -= mLoadedNumCrashes; |
| 6756 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6757 | val -= mUnpluggedNumCrashes; |
| 6758 | } |
| 6759 | return val; |
| 6760 | } |
| 6761 | |
| 6762 | @Override |
| 6763 | public int getNumAnrs(int which) { |
| 6764 | int val = mNumAnrs; |
| 6765 | if (which == STATS_CURRENT) { |
| 6766 | val -= mLoadedNumAnrs; |
| 6767 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6768 | val -= mUnpluggedNumAnrs; |
| 6769 | } |
| 6770 | return val; |
| 6771 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | /** |
| 6775 | * The statistics associated with a particular package. |
| 6776 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6777 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 6778 | /** |
| 6779 | * BatteryStatsImpl that we are associated with. |
| 6780 | */ |
| 6781 | protected BatteryStatsImpl mBsi; |
| 6782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6783 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6784 | * 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] | 6785 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6786 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6787 | |
| 6788 | /** |
| 6789 | * The statics we have collected for this package's services. |
| 6790 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6791 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6792 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6793 | public Pkg(BatteryStatsImpl bsi) { |
| 6794 | mBsi = bsi; |
| 6795 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6797 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6798 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | } |
| 6800 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6801 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6803 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6804 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6805 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6806 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6808 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6809 | int numWA = in.readInt(); |
| 6810 | mWakeupAlarms.clear(); |
| 6811 | for (int i=0; i<numWA; i++) { |
| 6812 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6813 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6814 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | |
| 6816 | int numServs = in.readInt(); |
| 6817 | mServiceStats.clear(); |
| 6818 | for (int m = 0; m < numServs; m++) { |
| 6819 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6820 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6821 | mServiceStats.put(serviceName, serv); |
| 6822 | |
| 6823 | serv.readFromParcelLocked(in); |
| 6824 | } |
| 6825 | } |
| 6826 | |
| 6827 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6828 | int numWA = mWakeupAlarms.size(); |
| 6829 | out.writeInt(numWA); |
| 6830 | for (int i=0; i<numWA; i++) { |
| 6831 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6832 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6833 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6834 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6835 | final int NS = mServiceStats.size(); |
| 6836 | out.writeInt(NS); |
| 6837 | for (int i=0; i<NS; i++) { |
| 6838 | out.writeString(mServiceStats.keyAt(i)); |
| 6839 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | serv.writeToParcelLocked(out); |
| 6841 | } |
| 6842 | } |
| 6843 | |
| 6844 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6845 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6846 | return mWakeupAlarms; |
| 6847 | } |
| 6848 | |
| 6849 | public void noteWakeupAlarmLocked(String tag) { |
| 6850 | Counter c = mWakeupAlarms.get(tag); |
| 6851 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6852 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6853 | mWakeupAlarms.put(tag, c); |
| 6854 | } |
| 6855 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6859 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6860 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6861 | } |
| 6862 | |
| 6863 | /** |
| 6864 | * The statistics associated with a particular service. |
| 6865 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6866 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 6867 | /** |
| 6868 | * BatteryStatsImpl that we are associated with. |
| 6869 | */ |
| 6870 | protected BatteryStatsImpl mBsi; |
| 6871 | |
| 6872 | /** |
| 6873 | * The android package in which this service resides. |
| 6874 | */ |
| 6875 | protected Pkg mPkg; |
| 6876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | /** |
| 6878 | * Total time (ms in battery uptime) the service has been left started. |
| 6879 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6880 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6881 | |
| 6882 | /** |
| 6883 | * If service has been started and not yet stopped, this is |
| 6884 | * when it was started. |
| 6885 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6886 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6887 | |
| 6888 | /** |
| 6889 | * True if we are currently running. |
| 6890 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6891 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | |
| 6893 | /** |
| 6894 | * Total number of times startService() has been called. |
| 6895 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6896 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | |
| 6898 | /** |
| 6899 | * Total time (ms in battery uptime) the service has been left launched. |
| 6900 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6901 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | |
| 6903 | /** |
| 6904 | * If service has been launched and not yet exited, this is |
| 6905 | * when it was launched (ms in battery uptime). |
| 6906 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6907 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | |
| 6909 | /** |
| 6910 | * True if we are currently launched. |
| 6911 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6912 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6913 | |
| 6914 | /** |
| 6915 | * Total number times the service has been launched. |
| 6916 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6917 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | |
| 6919 | /** |
| 6920 | * The amount of time spent started loaded from a previous save |
| 6921 | * (ms in battery uptime). |
| 6922 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6923 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6924 | |
| 6925 | /** |
| 6926 | * The number of starts loaded from a previous save. |
| 6927 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6928 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6929 | |
| 6930 | /** |
| 6931 | * The number of launches loaded from a previous save. |
| 6932 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6933 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6934 | |
| 6935 | /** |
| 6936 | * The amount of time spent started as of the last run (ms |
| 6937 | * in battery uptime). |
| 6938 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6939 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | |
| 6941 | /** |
| 6942 | * The number of starts as of the last run. |
| 6943 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6944 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | |
| 6946 | /** |
| 6947 | * The number of launches as of the last run. |
| 6948 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6949 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | |
| 6951 | /** |
| 6952 | * The amount of time spent started when last unplugged (ms |
| 6953 | * in battery uptime). |
| 6954 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6955 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | |
| 6957 | /** |
| 6958 | * The number of starts when last unplugged. |
| 6959 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6960 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6961 | |
| 6962 | /** |
| 6963 | * The number of launches when last unplugged. |
| 6964 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6965 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6966 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6967 | /** |
| 6968 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 6969 | */ |
| 6970 | public Serv(BatteryStatsImpl bsi) { |
| 6971 | mBsi = bsi; |
| 6972 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6974 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6975 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 6976 | long baseRealtime) { |
| 6977 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | mUnpluggedStarts = mStarts; |
| 6979 | mUnpluggedLaunches = mLaunches; |
| 6980 | } |
| 6981 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6982 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 6983 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6984 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6985 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6986 | /** |
| 6987 | * Remove this Serv as a listener from the time base. |
| 6988 | */ |
| 6989 | public void detach() { |
| 6990 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6991 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6992 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6993 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6994 | mStartTime = in.readLong(); |
| 6995 | mRunningSince = in.readLong(); |
| 6996 | mRunning = in.readInt() != 0; |
| 6997 | mStarts = in.readInt(); |
| 6998 | mLaunchedTime = in.readLong(); |
| 6999 | mLaunchedSince = in.readLong(); |
| 7000 | mLaunched = in.readInt() != 0; |
| 7001 | mLaunches = in.readInt(); |
| 7002 | mLoadedStartTime = in.readLong(); |
| 7003 | mLoadedStarts = in.readInt(); |
| 7004 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7005 | mLastStartTime = 0; |
| 7006 | mLastStarts = 0; |
| 7007 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7008 | mUnpluggedStartTime = in.readLong(); |
| 7009 | mUnpluggedStarts = in.readInt(); |
| 7010 | mUnpluggedLaunches = in.readInt(); |
| 7011 | } |
| 7012 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7013 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | out.writeLong(mStartTime); |
| 7015 | out.writeLong(mRunningSince); |
| 7016 | out.writeInt(mRunning ? 1 : 0); |
| 7017 | out.writeInt(mStarts); |
| 7018 | out.writeLong(mLaunchedTime); |
| 7019 | out.writeLong(mLaunchedSince); |
| 7020 | out.writeInt(mLaunched ? 1 : 0); |
| 7021 | out.writeInt(mLaunches); |
| 7022 | out.writeLong(mLoadedStartTime); |
| 7023 | out.writeInt(mLoadedStarts); |
| 7024 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | out.writeLong(mUnpluggedStartTime); |
| 7026 | out.writeInt(mUnpluggedStarts); |
| 7027 | out.writeInt(mUnpluggedLaunches); |
| 7028 | } |
| 7029 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7030 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | if (!mLaunched) return mLaunchedTime; |
| 7032 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 7033 | } |
| 7034 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7035 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | if (!mRunning) return mStartTime; |
| 7037 | return mStartTime + batteryUptime - mRunningSince; |
| 7038 | } |
| 7039 | |
| 7040 | public void startLaunchedLocked() { |
| 7041 | if (!mLaunched) { |
| 7042 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7043 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | mLaunched = true; |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | public void stopLaunchedLocked() { |
| 7049 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7050 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7051 | if (time > 0) { |
| 7052 | mLaunchedTime += time; |
| 7053 | } else { |
| 7054 | mLaunches--; |
| 7055 | } |
| 7056 | mLaunched = false; |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | public void startRunningLocked() { |
| 7061 | if (!mRunning) { |
| 7062 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7063 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7064 | mRunning = true; |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | public void stopRunningLocked() { |
| 7069 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7070 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | if (time > 0) { |
| 7072 | mStartTime += time; |
| 7073 | } else { |
| 7074 | mStarts--; |
| 7075 | } |
| 7076 | mRunning = false; |
| 7077 | } |
| 7078 | } |
| 7079 | |
| 7080 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7081 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | } |
| 7083 | |
| 7084 | @Override |
| 7085 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7086 | int val = mLaunches; |
| 7087 | if (which == STATS_CURRENT) { |
| 7088 | val -= mLoadedLaunches; |
| 7089 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7090 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7092 | return val; |
| 7093 | } |
| 7094 | |
| 7095 | @Override |
| 7096 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7097 | long val = getStartTimeToNowLocked(now); |
| 7098 | if (which == STATS_CURRENT) { |
| 7099 | val -= mLoadedStartTime; |
| 7100 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7101 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | return val; |
| 7104 | } |
| 7105 | |
| 7106 | @Override |
| 7107 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7108 | int val = mStarts; |
| 7109 | if (which == STATS_CURRENT) { |
| 7110 | val -= mLoadedStarts; |
| 7111 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7112 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7113 | } |
| 7114 | |
| 7115 | return val; |
| 7116 | } |
| 7117 | } |
| 7118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7119 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7120 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7121 | } |
| 7122 | } |
| 7123 | |
| 7124 | /** |
| 7125 | * Retrieve the statistics object for a particular process, creating |
| 7126 | * if needed. |
| 7127 | */ |
| 7128 | public Proc getProcessStatsLocked(String name) { |
| 7129 | Proc ps = mProcessStats.get(name); |
| 7130 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7131 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7132 | mProcessStats.put(name, ps); |
| 7133 | } |
| 7134 | |
| 7135 | return ps; |
| 7136 | } |
| 7137 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7138 | public void updateUidProcessStateLocked(int procState) { |
| 7139 | int uidRunningState; |
| 7140 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7141 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 7142 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 7143 | uidRunningState = PROCESS_STATE_TOP; |
| 7144 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 7145 | // Persistent and other foreground states go here. |
| 7146 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 7147 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 7148 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 7149 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7150 | // Persistent and other foreground states go here. |
| 7151 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 7152 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 7153 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7154 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7155 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7156 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7157 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7158 | if (mProcessState == uidRunningState) return; |
| 7159 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7160 | final long elapsedRealtime = mBsi.mClocks.elapsedRealtime(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7161 | |
| 7162 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7163 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtime); |
| 7164 | } |
| 7165 | mProcessState = uidRunningState; |
| 7166 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7167 | if (mProcessStateTimer[uidRunningState] == null) { |
| 7168 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7169 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7170 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7171 | } |
| 7172 | } |
| 7173 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7174 | public SparseArray<? extends Pid> getPidStats() { |
| 7175 | return mPids; |
| 7176 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7177 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7178 | public Pid getPidStatsLocked(int pid) { |
| 7179 | Pid p = mPids.get(pid); |
| 7180 | if (p == null) { |
| 7181 | p = new Pid(); |
| 7182 | mPids.put(pid, p); |
| 7183 | } |
| 7184 | return p; |
| 7185 | } |
| 7186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7187 | /** |
| 7188 | * Retrieve the statistics object for a particular service, creating |
| 7189 | * if needed. |
| 7190 | */ |
| 7191 | public Pkg getPackageStatsLocked(String name) { |
| 7192 | Pkg ps = mPackageStats.get(name); |
| 7193 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7194 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | mPackageStats.put(name, ps); |
| 7196 | } |
| 7197 | |
| 7198 | return ps; |
| 7199 | } |
| 7200 | |
| 7201 | /** |
| 7202 | * Retrieve the statistics object for a particular service, creating |
| 7203 | * if needed. |
| 7204 | */ |
| 7205 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 7206 | Pkg ps = getPackageStatsLocked(pkg); |
| 7207 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 7208 | if (ss == null) { |
| 7209 | ss = ps.newServiceStatsLocked(); |
| 7210 | ps.mServiceStats.put(serv, ss); |
| 7211 | } |
| 7212 | |
| 7213 | return ss; |
| 7214 | } |
| 7215 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7216 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 7217 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 7218 | timer.readSummaryFromParcelLocked(in); |
| 7219 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7220 | } |
| 7221 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7222 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 7223 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 7224 | timer.readSummaryFromParcelLocked(in); |
| 7225 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7226 | } |
| 7227 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7228 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7229 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7230 | mWakelockStats.add(wlName, wl); |
| 7231 | if (in.readInt() != 0) { |
| 7232 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7233 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7234 | if (in.readInt() != 0) { |
| 7235 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7236 | } |
| 7237 | if (in.readInt() != 0) { |
| 7238 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7240 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7241 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | } |
| 7244 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7245 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7246 | Sensor se = mSensorStats.get(sensor); |
| 7247 | if (se == null) { |
| 7248 | if (!create) { |
| 7249 | return null; |
| 7250 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7251 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | mSensorStats.put(sensor, se); |
| 7253 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7254 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7255 | if (t != null) { |
| 7256 | return t; |
| 7257 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7258 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7259 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7260 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7261 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7263 | t = new StopwatchTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 7264 | mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7265 | se.mTimer = t; |
| 7266 | return t; |
| 7267 | } |
| 7268 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7269 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7270 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7271 | if (t != null) { |
| 7272 | t.startRunningLocked(elapsedRealtimeMs); |
| 7273 | } |
| 7274 | } |
| 7275 | |
| 7276 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7277 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7278 | if (t != null) { |
| 7279 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7280 | } |
| 7281 | } |
| 7282 | |
| 7283 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7284 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7285 | if (t != null) { |
| 7286 | t.startRunningLocked(elapsedRealtimeMs); |
| 7287 | } |
| 7288 | } |
| 7289 | |
| 7290 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7291 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7292 | if (t != null) { |
| 7293 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7294 | } |
| 7295 | } |
| 7296 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7297 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7298 | Wakelock wl = mWakelockStats.startObject(name); |
| 7299 | if (wl != null) { |
| 7300 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7302 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7303 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7304 | if (p.mWakeNesting++ == 0) { |
| 7305 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 7306 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7307 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | } |
| 7309 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7310 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7311 | Wakelock wl = mWakelockStats.stopObject(name); |
| 7312 | if (wl != null) { |
| 7313 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7314 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7315 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7316 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7317 | if (p != null && p.mWakeNesting > 0) { |
| 7318 | if (p.mWakeNesting-- == 1) { |
| 7319 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 7320 | p.mWakeStartMs = 0; |
| 7321 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7322 | } |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 7327 | Proc p = getProcessStatsLocked(proc); |
| 7328 | if (p != null) { |
| 7329 | p.addExcessiveWake(overTime, usedTime); |
| 7330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7332 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7333 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 7334 | Proc p = getProcessStatsLocked(proc); |
| 7335 | if (p != null) { |
| 7336 | p.addExcessiveCpu(overTime, usedTime); |
| 7337 | } |
| 7338 | } |
| 7339 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7340 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7341 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7343 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7344 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7345 | } |
| 7346 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7347 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7348 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7349 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7351 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7353 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7354 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7355 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7356 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7357 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7358 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7359 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7360 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7361 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7362 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7363 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7364 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7365 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | } |
| 7368 | |
| 7369 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7370 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | } |
| 7372 | } |
| 7373 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7374 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7375 | this(new SystemClocks(), systemDir, handler, externalSync); |
| 7376 | } |
| 7377 | |
| 7378 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 7379 | ExternalStatsSync externalSync) { |
| 7380 | init(clocks); |
| 7381 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7382 | if (systemDir != null) { |
| 7383 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 7384 | new File(systemDir, "batterystats.bin.tmp")); |
| 7385 | } else { |
| 7386 | mFile = null; |
| 7387 | } |
| 7388 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7389 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7390 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 7391 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7393 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7394 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7395 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7396 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7397 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7398 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 7399 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 7400 | mOnBatteryTimeBase); |
| 7401 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 7402 | mOnBatteryTimeBase); |
| 7403 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 7404 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 7405 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 7406 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 7407 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 7408 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 7409 | mOnBatteryTimeBase); |
| 7410 | } |
| 7411 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 7412 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7413 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7414 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7415 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7416 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7417 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7418 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7419 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7420 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7421 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 7422 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7423 | NUM_BT_TX_LEVELS); |
| 7424 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7425 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7426 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7427 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 7428 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 7429 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7430 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7431 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7432 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7433 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 7434 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7435 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7436 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7437 | mOnBatteryTimeBase); |
| 7438 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7439 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7440 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 7441 | mOnBatteryTimeBase); |
| 7442 | } |
| 7443 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7444 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 7445 | mOnBatteryTimeBase); |
| 7446 | } |
| 7447 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 7448 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 7449 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 7450 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 7451 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7453 | long uptime = mClocks.uptimeMillis() * 1000; |
| 7454 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7455 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7456 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7457 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7458 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7459 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7460 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7461 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7462 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7463 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7464 | updateDailyDeadlineLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7468 | this(new SystemClocks(), p); |
| 7469 | } |
| 7470 | |
| 7471 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 7472 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7473 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7474 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7475 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7476 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7477 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7478 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7479 | readFromParcel(p); |
| 7480 | } |
| 7481 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7482 | public void setPowerProfile(PowerProfile profile) { |
| 7483 | synchronized (this) { |
| 7484 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7485 | |
| 7486 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 7487 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 7488 | // information. |
| 7489 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 7490 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 7491 | int firstCpuOfCluster = 0; |
| 7492 | for (int i = 0; i < numClusters; i++) { |
| 7493 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 7494 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 7495 | numSpeedSteps); |
| 7496 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 7497 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7498 | } |
| 7499 | } |
| 7500 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7501 | public void setCallback(BatteryCallback cb) { |
| 7502 | mCallback = cb; |
| 7503 | } |
| 7504 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7505 | public void setRadioScanningTimeout(long timeout) { |
| 7506 | if (mPhoneSignalScanningTimer != null) { |
| 7507 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 7508 | } |
| 7509 | } |
| 7510 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7511 | public void updateDailyDeadlineLocked() { |
| 7512 | // Get the current time. |
| 7513 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 7514 | Calendar calDeadline = Calendar.getInstance(); |
| 7515 | calDeadline.setTimeInMillis(currentTime); |
| 7516 | |
| 7517 | // Move time up to the next day, ranging from 1am to 3pm. |
| 7518 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 7519 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 7520 | calDeadline.set(Calendar.SECOND, 0); |
| 7521 | calDeadline.set(Calendar.MINUTE, 0); |
| 7522 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 7523 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 7524 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 7525 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 7526 | } |
| 7527 | |
| 7528 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 7529 | long currentTime = System.currentTimeMillis(); |
| 7530 | if (currentTime >= mNextMaxDailyDeadline) { |
| 7531 | recordDailyStatsLocked(); |
| 7532 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 7533 | recordDailyStatsLocked(); |
| 7534 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 7535 | recordDailyStatsLocked(); |
| 7536 | } |
| 7537 | } |
| 7538 | |
| 7539 | public void recordDailyStatsLocked() { |
| 7540 | DailyItem item = new DailyItem(); |
| 7541 | item.mStartTime = mDailyStartTime; |
| 7542 | item.mEndTime = System.currentTimeMillis(); |
| 7543 | boolean hasData = false; |
| 7544 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 7545 | hasData = true; |
| 7546 | item.mDischargeSteps = new LevelStepTracker( |
| 7547 | mDailyDischargeStepTracker.mNumStepDurations, |
| 7548 | mDailyDischargeStepTracker.mStepDurations); |
| 7549 | } |
| 7550 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 7551 | hasData = true; |
| 7552 | item.mChargeSteps = new LevelStepTracker( |
| 7553 | mDailyChargeStepTracker.mNumStepDurations, |
| 7554 | mDailyChargeStepTracker.mStepDurations); |
| 7555 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7556 | if (mDailyPackageChanges != null) { |
| 7557 | hasData = true; |
| 7558 | item.mPackageChanges = mDailyPackageChanges; |
| 7559 | mDailyPackageChanges = null; |
| 7560 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7561 | mDailyDischargeStepTracker.init(); |
| 7562 | mDailyChargeStepTracker.init(); |
| 7563 | updateDailyDeadlineLocked(); |
| 7564 | |
| 7565 | if (hasData) { |
| 7566 | mDailyItems.add(item); |
| 7567 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 7568 | mDailyItems.remove(0); |
| 7569 | } |
| 7570 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 7571 | try { |
| 7572 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7573 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7574 | writeDailyItemsLocked(out); |
| 7575 | BackgroundThread.getHandler().post(new Runnable() { |
| 7576 | @Override |
| 7577 | public void run() { |
| 7578 | synchronized (mCheckinFile) { |
| 7579 | FileOutputStream stream = null; |
| 7580 | try { |
| 7581 | stream = mDailyFile.startWrite(); |
| 7582 | memStream.writeTo(stream); |
| 7583 | stream.flush(); |
| 7584 | FileUtils.sync(stream); |
| 7585 | stream.close(); |
| 7586 | mDailyFile.finishWrite(stream); |
| 7587 | } catch (IOException e) { |
| 7588 | Slog.w("BatteryStats", |
| 7589 | "Error writing battery daily items", e); |
| 7590 | mDailyFile.failWrite(stream); |
| 7591 | } |
| 7592 | } |
| 7593 | } |
| 7594 | }); |
| 7595 | } catch (IOException e) { |
| 7596 | } |
| 7597 | } |
| 7598 | } |
| 7599 | |
| 7600 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 7601 | StringBuilder sb = new StringBuilder(64); |
| 7602 | out.startDocument(null, true); |
| 7603 | out.startTag(null, "daily-items"); |
| 7604 | for (int i=0; i<mDailyItems.size(); i++) { |
| 7605 | final DailyItem dit = mDailyItems.get(i); |
| 7606 | out.startTag(null, "item"); |
| 7607 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 7608 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 7609 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 7610 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7611 | if (dit.mPackageChanges != null) { |
| 7612 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 7613 | PackageChange pc = dit.mPackageChanges.get(j); |
| 7614 | if (pc.mUpdate) { |
| 7615 | out.startTag(null, "upd"); |
| 7616 | out.attribute(null, "pkg", pc.mPackageName); |
| 7617 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 7618 | out.endTag(null, "upd"); |
| 7619 | } else { |
| 7620 | out.startTag(null, "rem"); |
| 7621 | out.attribute(null, "pkg", pc.mPackageName); |
| 7622 | out.endTag(null, "rem"); |
| 7623 | } |
| 7624 | } |
| 7625 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7626 | out.endTag(null, "item"); |
| 7627 | } |
| 7628 | out.endTag(null, "daily-items"); |
| 7629 | out.endDocument(); |
| 7630 | } |
| 7631 | |
| 7632 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 7633 | StringBuilder tmpBuilder) throws IOException { |
| 7634 | if (steps != null) { |
| 7635 | out.startTag(null, tag); |
| 7636 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 7637 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 7638 | out.startTag(null, "s"); |
| 7639 | tmpBuilder.setLength(0); |
| 7640 | steps.encodeEntryAt(i, tmpBuilder); |
| 7641 | out.attribute(null, "v", tmpBuilder.toString()); |
| 7642 | out.endTag(null, "s"); |
| 7643 | } |
| 7644 | out.endTag(null, tag); |
| 7645 | } |
| 7646 | } |
| 7647 | |
| 7648 | public void readDailyStatsLocked() { |
| 7649 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 7650 | mDailyItems.clear(); |
| 7651 | FileInputStream stream; |
| 7652 | try { |
| 7653 | stream = mDailyFile.openRead(); |
| 7654 | } catch (FileNotFoundException e) { |
| 7655 | return; |
| 7656 | } |
| 7657 | try { |
| 7658 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7659 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7660 | readDailyItemsLocked(parser); |
| 7661 | } catch (XmlPullParserException e) { |
| 7662 | } finally { |
| 7663 | try { |
| 7664 | stream.close(); |
| 7665 | } catch (IOException e) { |
| 7666 | } |
| 7667 | } |
| 7668 | } |
| 7669 | |
| 7670 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7671 | try { |
| 7672 | int type; |
| 7673 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7674 | && type != XmlPullParser.END_DOCUMENT) { |
| 7675 | ; |
| 7676 | } |
| 7677 | |
| 7678 | if (type != XmlPullParser.START_TAG) { |
| 7679 | throw new IllegalStateException("no start tag found"); |
| 7680 | } |
| 7681 | |
| 7682 | int outerDepth = parser.getDepth(); |
| 7683 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7684 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7685 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7686 | continue; |
| 7687 | } |
| 7688 | |
| 7689 | String tagName = parser.getName(); |
| 7690 | if (tagName.equals("item")) { |
| 7691 | readDailyItemTagLocked(parser); |
| 7692 | } else { |
| 7693 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7694 | + parser.getName()); |
| 7695 | XmlUtils.skipCurrentTag(parser); |
| 7696 | } |
| 7697 | } |
| 7698 | |
| 7699 | } catch (IllegalStateException e) { |
| 7700 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7701 | } catch (NullPointerException e) { |
| 7702 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7703 | } catch (NumberFormatException e) { |
| 7704 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7705 | } catch (XmlPullParserException e) { |
| 7706 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7707 | } catch (IOException e) { |
| 7708 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7709 | } catch (IndexOutOfBoundsException e) { |
| 7710 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7711 | } |
| 7712 | } |
| 7713 | |
| 7714 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7715 | XmlPullParserException, IOException { |
| 7716 | DailyItem dit = new DailyItem(); |
| 7717 | String attr = parser.getAttributeValue(null, "start"); |
| 7718 | if (attr != null) { |
| 7719 | dit.mStartTime = Long.parseLong(attr); |
| 7720 | } |
| 7721 | attr = parser.getAttributeValue(null, "end"); |
| 7722 | if (attr != null) { |
| 7723 | dit.mEndTime = Long.parseLong(attr); |
| 7724 | } |
| 7725 | int outerDepth = parser.getDepth(); |
| 7726 | int type; |
| 7727 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7728 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7729 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7730 | continue; |
| 7731 | } |
| 7732 | |
| 7733 | String tagName = parser.getName(); |
| 7734 | if (tagName.equals("dis")) { |
| 7735 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7736 | } else if (tagName.equals("chg")) { |
| 7737 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7738 | } else if (tagName.equals("upd")) { |
| 7739 | if (dit.mPackageChanges == null) { |
| 7740 | dit.mPackageChanges = new ArrayList<>(); |
| 7741 | } |
| 7742 | PackageChange pc = new PackageChange(); |
| 7743 | pc.mUpdate = true; |
| 7744 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7745 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7746 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7747 | dit.mPackageChanges.add(pc); |
| 7748 | XmlUtils.skipCurrentTag(parser); |
| 7749 | } else if (tagName.equals("rem")) { |
| 7750 | if (dit.mPackageChanges == null) { |
| 7751 | dit.mPackageChanges = new ArrayList<>(); |
| 7752 | } |
| 7753 | PackageChange pc = new PackageChange(); |
| 7754 | pc.mUpdate = false; |
| 7755 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7756 | dit.mPackageChanges.add(pc); |
| 7757 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7758 | } else { |
| 7759 | Slog.w(TAG, "Unknown element under <item>: " |
| 7760 | + parser.getName()); |
| 7761 | XmlUtils.skipCurrentTag(parser); |
| 7762 | } |
| 7763 | } |
| 7764 | mDailyItems.add(dit); |
| 7765 | } |
| 7766 | |
| 7767 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7768 | String tag) |
| 7769 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7770 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7771 | if (numAttr == null) { |
| 7772 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7773 | XmlUtils.skipCurrentTag(parser); |
| 7774 | return; |
| 7775 | } |
| 7776 | final int num = Integer.parseInt(numAttr); |
| 7777 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7778 | if (isCharge) { |
| 7779 | dit.mChargeSteps = steps; |
| 7780 | } else { |
| 7781 | dit.mDischargeSteps = steps; |
| 7782 | } |
| 7783 | int i = 0; |
| 7784 | int outerDepth = parser.getDepth(); |
| 7785 | int type; |
| 7786 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7787 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7788 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7789 | continue; |
| 7790 | } |
| 7791 | |
| 7792 | String tagName = parser.getName(); |
| 7793 | if ("s".equals(tagName)) { |
| 7794 | if (i < num) { |
| 7795 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7796 | if (valueAttr != null) { |
| 7797 | steps.decodeEntryAt(i, valueAttr); |
| 7798 | i++; |
| 7799 | } |
| 7800 | } |
| 7801 | } else { |
| 7802 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7803 | + parser.getName()); |
| 7804 | XmlUtils.skipCurrentTag(parser); |
| 7805 | } |
| 7806 | } |
| 7807 | steps.mNumStepDurations = i; |
| 7808 | } |
| 7809 | |
| 7810 | @Override |
| 7811 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7812 | int index = mDailyItems.size()-1-daysAgo; |
| 7813 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7814 | } |
| 7815 | |
| 7816 | @Override |
| 7817 | public long getCurrentDailyStartTime() { |
| 7818 | return mDailyStartTime; |
| 7819 | } |
| 7820 | |
| 7821 | @Override |
| 7822 | public long getNextMinDailyDeadline() { |
| 7823 | return mNextMinDailyDeadline; |
| 7824 | } |
| 7825 | |
| 7826 | @Override |
| 7827 | public long getNextMaxDailyDeadline() { |
| 7828 | return mNextMaxDailyDeadline; |
| 7829 | } |
| 7830 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7831 | @Override |
| 7832 | public boolean startIteratingOldHistoryLocked() { |
| 7833 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7834 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7835 | if ((mHistoryIterator = mHistory) == null) { |
| 7836 | return false; |
| 7837 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7838 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7839 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7840 | mReadOverflow = false; |
| 7841 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7842 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7843 | } |
| 7844 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7845 | @Override |
| 7846 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7847 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7848 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7849 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7850 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7851 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7852 | HistoryItem cur = mHistoryIterator; |
| 7853 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7854 | if (!mReadOverflow && !end) { |
| 7855 | Slog.w(TAG, "Old history ends before new history!"); |
| 7856 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7857 | return false; |
| 7858 | } |
| 7859 | out.setTo(cur); |
| 7860 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7861 | if (!mReadOverflow) { |
| 7862 | if (end) { |
| 7863 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7864 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7865 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7866 | pw.println("Histories differ!"); |
| 7867 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7868 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7869 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7870 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7871 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7872 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7873 | } |
| 7874 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7875 | return true; |
| 7876 | } |
| 7877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7878 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7879 | public void finishIteratingOldHistoryLocked() { |
| 7880 | mIteratingHistory = false; |
| 7881 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7882 | mHistoryIterator = null; |
| 7883 | } |
| 7884 | |
| 7885 | public int getHistoryTotalSize() { |
| 7886 | return MAX_HISTORY_BUFFER; |
| 7887 | } |
| 7888 | |
| 7889 | public int getHistoryUsedSize() { |
| 7890 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7891 | } |
| 7892 | |
| 7893 | @Override |
| 7894 | public boolean startIteratingHistoryLocked() { |
| 7895 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7896 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7897 | if (mHistoryBuffer.dataSize() <= 0) { |
| 7898 | return false; |
| 7899 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7900 | mHistoryBuffer.setDataPosition(0); |
| 7901 | mReadOverflow = false; |
| 7902 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7903 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 7904 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 7905 | mReadHistoryChars = 0; |
| 7906 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7907 | final HistoryTag tag = ent.getKey(); |
| 7908 | final int idx = ent.getValue(); |
| 7909 | mReadHistoryStrings[idx] = tag.string; |
| 7910 | mReadHistoryUids[idx] = tag.uid; |
| 7911 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7912 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7913 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7914 | } |
| 7915 | |
| 7916 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7917 | public int getHistoryStringPoolSize() { |
| 7918 | return mReadHistoryStrings.length; |
| 7919 | } |
| 7920 | |
| 7921 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7922 | public int getHistoryStringPoolBytes() { |
| 7923 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 7924 | // Each string character is 2 bytes. |
| 7925 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 7926 | } |
| 7927 | |
| 7928 | @Override |
| 7929 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7930 | return mReadHistoryStrings[index]; |
| 7931 | } |
| 7932 | |
| 7933 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7934 | public int getHistoryTagPoolUid(int index) { |
| 7935 | return mReadHistoryUids[index]; |
| 7936 | } |
| 7937 | |
| 7938 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7939 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7940 | final int pos = mHistoryBuffer.dataPosition(); |
| 7941 | if (pos == 0) { |
| 7942 | out.clear(); |
| 7943 | } |
| 7944 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7945 | if (end) { |
| 7946 | return false; |
| 7947 | } |
| 7948 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7949 | final long lastRealtime = out.time; |
| 7950 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7951 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7952 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 7953 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7954 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 7955 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7956 | return true; |
| 7957 | } |
| 7958 | |
| 7959 | @Override |
| 7960 | public void finishIteratingHistoryLocked() { |
| 7961 | mIteratingHistory = false; |
| 7962 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7963 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7964 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7965 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7966 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7967 | public long getHistoryBaseTime() { |
| 7968 | return mHistoryBaseTime; |
| 7969 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7970 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7971 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7972 | public int getStartCount() { |
| 7973 | return mStartCount; |
| 7974 | } |
| 7975 | |
| 7976 | public boolean isOnBattery() { |
| 7977 | return mOnBattery; |
| 7978 | } |
| 7979 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7980 | public boolean isCharging() { |
| 7981 | return mCharging; |
| 7982 | } |
| 7983 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7984 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7985 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7986 | } |
| 7987 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7988 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7989 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7990 | mOnBatteryTimeBase.init(uptime, realtime); |
| 7991 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7992 | mRealtime = 0; |
| 7993 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7994 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7995 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7996 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7997 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7998 | void initDischarge() { |
| 7999 | mLowDischargeAmountSinceCharge = 0; |
| 8000 | mHighDischargeAmountSinceCharge = 0; |
| 8001 | mDischargeAmountScreenOn = 0; |
| 8002 | mDischargeAmountScreenOnSinceCharge = 0; |
| 8003 | mDischargeAmountScreenOff = 0; |
| 8004 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8005 | mDischargeStepTracker.init(); |
| 8006 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8007 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8008 | |
| 8009 | public void resetAllStatsCmdLocked() { |
| 8010 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8011 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8012 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8013 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8014 | long realtime = mSecRealtime * 1000; |
| 8015 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 8016 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8017 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8018 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 8019 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8020 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 8021 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 8022 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8023 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8024 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 8025 | mDischargeScreenOffUnplugLevel = 0; |
| 8026 | } else { |
| 8027 | mDischargeScreenOnUnplugLevel = 0; |
| 8028 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 8029 | } |
| 8030 | mDischargeAmountScreenOn = 0; |
| 8031 | mDischargeAmountScreenOff = 0; |
| 8032 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8033 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8037 | mStartCount = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8038 | initTimes(mClocks.uptimeMillis() * 1000, mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8039 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8040 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8041 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8042 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8043 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8044 | mPowerSaveModeEnabledTimer.reset(false); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 8045 | mLongestLightIdleTime = 0; |
| 8046 | mLongestFullIdleTime = 0; |
| 8047 | mDeviceIdleModeLightTimer.reset(false); |
| 8048 | mDeviceIdleModeFullTimer.reset(false); |
| 8049 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8050 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8051 | mPhoneOnTimer.reset(false); |
| 8052 | mAudioOnTimer.reset(false); |
| 8053 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8054 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8055 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8056 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8057 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8058 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8059 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8060 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8061 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8062 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8063 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8064 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8065 | mNetworkByteActivityCounters[i].reset(false); |
| 8066 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8067 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8068 | mMobileRadioActiveTimer.reset(false); |
| 8069 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8070 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8071 | mMobileRadioActiveUnknownTime.reset(false); |
| 8072 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8073 | mWifiOnTimer.reset(false); |
| 8074 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8075 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8076 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8077 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8078 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8079 | mWifiSupplStateTimer[i].reset(false); |
| 8080 | } |
| 8081 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8082 | mWifiSignalStrengthsTimer[i].reset(false); |
| 8083 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8084 | mWifiActivity.reset(false); |
| 8085 | mBluetoothActivity.reset(false); |
| 8086 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8087 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8088 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8089 | for (int i=0; i<mUidStats.size(); i++) { |
| 8090 | if (mUidStats.valueAt(i).reset()) { |
| 8091 | mUidStats.remove(mUidStats.keyAt(i)); |
| 8092 | i--; |
| 8093 | } |
| 8094 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8095 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8096 | if (mKernelWakelockStats.size() > 0) { |
| 8097 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8098 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8099 | } |
| 8100 | mKernelWakelockStats.clear(); |
| 8101 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8102 | |
| 8103 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8104 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 8105 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8106 | } |
| 8107 | mWakeupReasonStats.clear(); |
| 8108 | } |
| 8109 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8110 | mLastHistoryStepDetails = null; |
| 8111 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 8112 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 8113 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 8114 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 8115 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 8116 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 8117 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 8118 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 8119 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 8120 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 8121 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8122 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8123 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8124 | clearHistoryLocked(); |
| 8125 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8126 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8127 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8128 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8129 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 8130 | // Not recording process starts/stops. |
| 8131 | continue; |
| 8132 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8133 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8134 | if (active == null) { |
| 8135 | continue; |
| 8136 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8137 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 8138 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8139 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8140 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 8141 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8142 | } |
| 8143 | } |
| 8144 | } |
| 8145 | } |
| 8146 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8147 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8148 | if (oldScreenOn) { |
| 8149 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 8150 | if (diff > 0) { |
| 8151 | mDischargeAmountScreenOn += diff; |
| 8152 | mDischargeAmountScreenOnSinceCharge += diff; |
| 8153 | } |
| 8154 | } else { |
| 8155 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 8156 | if (diff > 0) { |
| 8157 | mDischargeAmountScreenOff += diff; |
| 8158 | mDischargeAmountScreenOffSinceCharge += diff; |
| 8159 | } |
| 8160 | } |
| 8161 | if (newScreenOn) { |
| 8162 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 8163 | mDischargeScreenOffUnplugLevel = 0; |
| 8164 | } else { |
| 8165 | mDischargeScreenOnUnplugLevel = 0; |
| 8166 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 8167 | } |
| 8168 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8169 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8170 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8171 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8172 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 8173 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8174 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8175 | } |
| 8176 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8177 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 8178 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 8179 | |
| 8180 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 8181 | |
| 8182 | private static final int NETWORK_STATS_LAST = 0; |
| 8183 | private static final int NETWORK_STATS_NEXT = 1; |
| 8184 | private static final int NETWORK_STATS_DELTA = 2; |
| 8185 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8186 | private NetworkStats[] mMobileNetworkStats; |
| 8187 | private NetworkStats[] mWifiNetworkStats; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8188 | |
| 8189 | /** |
| 8190 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 8191 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 8192 | */ |
| 8193 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 8194 | NetworkStats[] networkStatsBuffer) |
| 8195 | throws IOException { |
| 8196 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 8197 | false)) { |
| 8198 | return null; |
| 8199 | } |
| 8200 | |
| 8201 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 8202 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 8203 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 8204 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 8205 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 8206 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 8207 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 8208 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 8209 | } |
| 8210 | |
| 8211 | /** |
| 8212 | * Distribute WiFi energy info and network traffic to apps. |
| 8213 | * @param info The energy information from the WiFi controller. |
| 8214 | */ |
| 8215 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8216 | if (DEBUG_ENERGY) { |
| 8217 | Slog.d(TAG, "Updating wifi stats"); |
| 8218 | } |
| 8219 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8220 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8221 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8222 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8223 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 8224 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 8225 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8226 | } catch (IOException e) { |
| 8227 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 8228 | return; |
| 8229 | } |
| 8230 | |
| 8231 | if (!mOnBatteryInternal) { |
| 8232 | return; |
| 8233 | } |
| 8234 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8235 | SparseLongArray rxPackets = new SparseLongArray(); |
| 8236 | SparseLongArray txPackets = new SparseLongArray(); |
| 8237 | long totalTxPackets = 0; |
| 8238 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8239 | if (delta != null) { |
| 8240 | final int size = delta.size(); |
| 8241 | for (int i = 0; i < size; i++) { |
| 8242 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8243 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8244 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8245 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8246 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8247 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8248 | } |
| 8249 | |
Adam Lesinski | 6cca414 | 2016-02-25 18:23:02 -0800 | [diff] [blame] | 8250 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 8251 | // Skip the lookup below since there is no work to do. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8252 | continue; |
| 8253 | } |
| 8254 | |
| 8255 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8256 | if (entry.rxBytes != 0) { |
| 8257 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 8258 | entry.rxPackets); |
| 8259 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8260 | entry.rxBytes); |
| 8261 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8262 | entry.rxPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8263 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8264 | rxPackets.put(u.getUid(), entry.rxPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8265 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8266 | // Sum the total number of packets so that the Rx Power can |
| 8267 | // be evenly distributed amongst the apps. |
| 8268 | totalRxPackets += entry.rxPackets; |
| 8269 | } |
| 8270 | |
| 8271 | if (entry.txBytes != 0) { |
| 8272 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 8273 | entry.txPackets); |
| 8274 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8275 | entry.txBytes); |
| 8276 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8277 | entry.txPackets); |
| 8278 | |
| 8279 | txPackets.put(u.getUid(), entry.txPackets); |
| 8280 | |
| 8281 | // Sum the total number of packets so that the Tx Power can |
| 8282 | // be evenly distributed amongst the apps. |
| 8283 | totalTxPackets += entry.txPackets; |
| 8284 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8285 | } |
| 8286 | } |
| 8287 | |
| 8288 | if (info != null) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8289 | mHasWifiReporting = true; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 8290 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8291 | // Measured in mAms |
| 8292 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8293 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8294 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 8295 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 8296 | |
| 8297 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8298 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8299 | |
| 8300 | if (DEBUG_ENERGY) { |
| 8301 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 8302 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8303 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8304 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 8305 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 8306 | } |
| 8307 | |
| 8308 | long totalWifiLockTimeMs = 0; |
| 8309 | long totalScanTimeMs = 0; |
| 8310 | |
| 8311 | // On the first pass, collect some totals so that we can normalize power |
| 8312 | // calculations if we need to. |
| 8313 | final int uidStatsSize = mUidStats.size(); |
| 8314 | for (int i = 0; i < uidStatsSize; i++) { |
| 8315 | final Uid uid = mUidStats.valueAt(i); |
| 8316 | |
| 8317 | // Sum the total scan power for all apps. |
| 8318 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8319 | elapsedRealtimeMs * 1000) / 1000; |
| 8320 | |
| 8321 | // Sum the total time holding wifi lock for all apps. |
| 8322 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8323 | elapsedRealtimeMs * 1000) / 1000; |
| 8324 | } |
| 8325 | |
| 8326 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 8327 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 8328 | + rxTimeMs + " ms). Normalizing scan time."); |
| 8329 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8330 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 8331 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 8332 | + txTimeMs + " ms). Normalizing scan time."); |
| 8333 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8334 | |
| 8335 | // Actually assign and distribute power usage to apps. |
| 8336 | for (int i = 0; i < uidStatsSize; i++) { |
| 8337 | final Uid uid = mUidStats.valueAt(i); |
| 8338 | |
| 8339 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8340 | elapsedRealtimeMs * 1000) / 1000; |
| 8341 | if (scanTimeSinceMarkMs > 0) { |
| 8342 | // Set the new mark so that next time we get new data since this point. |
| 8343 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 8344 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8345 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8346 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8347 | |
| 8348 | // Our total scan time is more than the reported Tx/Rx time. |
| 8349 | // This is possible because the cost of a scan is approximate. |
| 8350 | // Let's normalize the result so that we evenly blame each app |
| 8351 | // scanning. |
| 8352 | // |
| 8353 | // This means that we may have apps that transmitted/received packets not be |
| 8354 | // 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] | 8355 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8356 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 8357 | totalScanTimeMs; |
| 8358 | } |
| 8359 | if (totalScanTimeMs > txTimeMs) { |
| 8360 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 8361 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8365 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 8366 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 8367 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8368 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8369 | |
| 8370 | ControllerActivityCounterImpl activityCounter = |
| 8371 | uid.getOrCreateWifiControllerActivityLocked(); |
| 8372 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 8373 | activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8374 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 8375 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8376 | } |
| 8377 | |
| 8378 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 8379 | // lock. |
| 8380 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8381 | elapsedRealtimeMs * 1000) / 1000; |
| 8382 | if (wifiLockTimeSinceMarkMs > 0) { |
| 8383 | // Set the new mark so that next time we get new data since this point. |
| 8384 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 8385 | |
| 8386 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 8387 | / totalWifiLockTimeMs; |
| 8388 | if (DEBUG_ENERGY) { |
| 8389 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 8390 | + myIdleTimeMs + " ms"); |
| 8391 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8392 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 8393 | .addCountLocked(myIdleTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8394 | } |
| 8395 | } |
| 8396 | |
| 8397 | if (DEBUG_ENERGY) { |
| 8398 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8399 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8400 | } |
| 8401 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8402 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 8403 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8404 | for (int i = 0; i < txPackets.size(); i++) { |
| 8405 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8406 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8407 | if (DEBUG_ENERGY) { |
| 8408 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 8409 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8410 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 8411 | .addCountLocked(myTxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8412 | } |
| 8413 | |
| 8414 | // Distribute the remaining Rx power appropriately between all apps that received |
| 8415 | // packets. |
| 8416 | for (int i = 0; i < rxPackets.size(); i++) { |
| 8417 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 8418 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 8419 | if (DEBUG_ENERGY) { |
| 8420 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 8421 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8422 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 8423 | .addCountLocked(myRxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8424 | } |
| 8425 | |
| 8426 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 8427 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8428 | // Update WiFi controller stats. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8429 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 8430 | mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis()); |
| 8431 | mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8432 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8433 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8434 | final double opVolt = mPowerProfile.getAveragePower( |
| 8435 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8436 | if (opVolt != 0) { |
| 8437 | // We store the power drain as mAms. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8438 | mWifiActivity.getPowerCounter().addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8439 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8440 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | /** |
| 8445 | * Distribute Cell radio energy info and network traffic to apps. |
| 8446 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8447 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs, |
| 8448 | final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8449 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8450 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8451 | } |
| 8452 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8453 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8454 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8455 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 8456 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 8457 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8458 | } catch (IOException e) { |
| 8459 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 8460 | return; |
| 8461 | } |
| 8462 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8463 | if (!mOnBatteryInternal) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8464 | return; |
| 8465 | } |
| 8466 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8467 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 8468 | elapsedRealtimeMs * 1000); |
| 8469 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8470 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8471 | long totalRxPackets = 0; |
| 8472 | long totalTxPackets = 0; |
| 8473 | if (delta != null) { |
| 8474 | final int size = delta.size(); |
| 8475 | for (int i = 0; i < size; i++) { |
| 8476 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8477 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8478 | continue; |
| 8479 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8480 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8481 | if (DEBUG_ENERGY) { |
| 8482 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 8483 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8484 | + " txPackets=" + entry.txPackets); |
| 8485 | } |
| 8486 | |
| 8487 | totalRxPackets += entry.rxPackets; |
| 8488 | totalTxPackets += entry.txPackets; |
| 8489 | |
| 8490 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8491 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, entry.rxPackets); |
| 8492 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, entry.txPackets); |
| 8493 | |
| 8494 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8495 | entry.rxBytes); |
| 8496 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8497 | entry.txBytes); |
| 8498 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8499 | entry.rxPackets); |
| 8500 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8501 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8502 | } |
| 8503 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8504 | // Now distribute proportional blame to the apps that did networking. |
| 8505 | long totalPackets = totalRxPackets + totalTxPackets; |
| 8506 | if (totalPackets > 0) { |
| 8507 | for (int i = 0; i < size; i++) { |
| 8508 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8509 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 8510 | continue; |
| 8511 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8512 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8513 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8514 | |
| 8515 | // Distribute total radio active time in to this app. |
| 8516 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 8517 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 8518 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 8519 | |
| 8520 | // Remove this app from the totals, so that we don't lose any time |
| 8521 | // due to rounding. |
| 8522 | radioTime -= appRadioTime; |
| 8523 | totalPackets -= appPackets; |
| 8524 | |
| 8525 | if (activityInfo != null) { |
| 8526 | ControllerActivityCounterImpl activityCounter = |
| 8527 | u.getOrCreateModemControllerActivityLocked(); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8528 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8529 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 8530 | / totalRxPackets; |
| 8531 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 8532 | } |
| 8533 | |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8534 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8535 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8536 | long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 8537 | txMs /= totalTxPackets; |
| 8538 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 8539 | } |
| 8540 | } |
| 8541 | } |
| 8542 | } |
| 8543 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8544 | |
| 8545 | if (radioTime > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8546 | // Whoops, there is some radio time we can't blame on an app! |
| 8547 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 8548 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8549 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8550 | } |
| 8551 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8552 | if (activityInfo != null) { |
| 8553 | mHasModemReporting = true; |
| 8554 | mModemActivity.getIdleTimeCounter().addCountLocked(activityInfo.getIdleTimeMillis()); |
| 8555 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 8556 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8557 | mModemActivity.getTxTimeCounters()[lvl] |
| 8558 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 8559 | } |
| 8560 | |
| 8561 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8562 | final double opVolt = mPowerProfile.getAveragePower( |
| 8563 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8564 | if (opVolt != 0) { |
| 8565 | // We store the power drain as mAms. |
| 8566 | mModemActivity.getPowerCounter().addCountLocked( |
| 8567 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 8568 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8569 | } |
| 8570 | } |
| 8571 | |
| 8572 | /** |
| 8573 | * Distribute Bluetooth energy info and network traffic to apps. |
| 8574 | * @param info The energy information from the bluetooth controller. |
| 8575 | */ |
| 8576 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8577 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8578 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8579 | } |
| 8580 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8581 | if (info == null || !mOnBatteryInternal) { |
| 8582 | return; |
| 8583 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8584 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8585 | mHasBluetoothReporting = true; |
| 8586 | |
| 8587 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 8588 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8589 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8590 | |
| 8591 | if (DEBUG_ENERGY) { |
| 8592 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 8593 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8594 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8595 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 8596 | } |
| 8597 | |
| 8598 | long totalScanTimeMs = 0; |
| 8599 | |
| 8600 | final int uidCount = mUidStats.size(); |
| 8601 | for (int i = 0; i < uidCount; i++) { |
| 8602 | final Uid u = mUidStats.valueAt(i); |
| 8603 | if (u.mBluetoothScanTimer == null) { |
| 8604 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8605 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8606 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8607 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8608 | elapsedRealtimeMs * 1000) / 1000; |
| 8609 | } |
| 8610 | |
| 8611 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 8612 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 8613 | |
| 8614 | if (DEBUG_ENERGY) { |
| 8615 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 8616 | + " TX=" + normalizeScanTxTime); |
| 8617 | } |
| 8618 | |
| 8619 | long leftOverRxTimeMs = rxTimeMs; |
| 8620 | long leftOverTxTimeMs = txTimeMs; |
| 8621 | |
| 8622 | for (int i = 0; i < uidCount; i++) { |
| 8623 | final Uid u = mUidStats.valueAt(i); |
| 8624 | if (u.mBluetoothScanTimer == null) { |
| 8625 | continue; |
| 8626 | } |
| 8627 | |
| 8628 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8629 | elapsedRealtimeMs * 1000) / 1000; |
| 8630 | if (scanTimeSinceMarkMs > 0) { |
| 8631 | // Set the new mark so that next time we get new data since this point. |
| 8632 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 8633 | |
| 8634 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 8635 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 8636 | |
| 8637 | if (normalizeScanRxTime) { |
| 8638 | // Scan time is longer than the total rx time in the controller, |
| 8639 | // so distribute the scan time proportionately. This means regular traffic |
| 8640 | // will not blamed, but scans are more expensive anyways. |
| 8641 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 8642 | } |
| 8643 | |
| 8644 | if (normalizeScanTxTime) { |
| 8645 | // Scan time is longer than the total tx time in the controller, |
| 8646 | // so distribute the scan time proportionately. This means regular traffic |
| 8647 | // will not blamed, but scans are more expensive anyways. |
| 8648 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 8649 | } |
| 8650 | |
| 8651 | final ControllerActivityCounterImpl counter = |
| 8652 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8653 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 8654 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 8655 | |
| 8656 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 8657 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 8658 | } |
| 8659 | } |
| 8660 | |
| 8661 | if (DEBUG_ENERGY) { |
| 8662 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 8663 | + " TX=" + leftOverTxTimeMs); |
| 8664 | } |
| 8665 | |
| 8666 | // |
| 8667 | // Now distribute blame to apps that did bluetooth traffic. |
| 8668 | // |
| 8669 | |
| 8670 | long totalTxBytes = 0; |
| 8671 | long totalRxBytes = 0; |
| 8672 | |
| 8673 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 8674 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 8675 | for (int i = 0; i < numUids; i++) { |
| 8676 | final UidTraffic traffic = uidTraffic[i]; |
| 8677 | |
| 8678 | // Add to the global counters. |
| 8679 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 8680 | traffic.getRxBytes()); |
| 8681 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 8682 | traffic.getTxBytes()); |
| 8683 | |
| 8684 | // Add to the UID counters. |
| 8685 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 8686 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 8687 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 8688 | |
| 8689 | // Calculate the total traffic. |
| 8690 | totalTxBytes += traffic.getTxBytes(); |
| 8691 | totalRxBytes += traffic.getRxBytes(); |
| 8692 | } |
| 8693 | |
| 8694 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 8695 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8696 | for (int i = 0; i < numUids; i++) { |
| 8697 | final UidTraffic traffic = uidTraffic[i]; |
| 8698 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8699 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8700 | final ControllerActivityCounterImpl counter = |
| 8701 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8702 | |
| 8703 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 8704 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 8705 | |
| 8706 | if (DEBUG_ENERGY) { |
| 8707 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 8708 | + " rx_time=" + timeRxMs); |
| 8709 | } |
| 8710 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 8711 | leftOverRxTimeMs -= timeRxMs; |
| 8712 | } |
| 8713 | |
| 8714 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 8715 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 8716 | |
| 8717 | if (DEBUG_ENERGY) { |
| 8718 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 8719 | + " tx_time=" + timeTxMs); |
| 8720 | } |
| 8721 | |
| 8722 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 8723 | leftOverTxTimeMs -= timeTxMs; |
| 8724 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8725 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8726 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8727 | |
| 8728 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 8729 | info.getControllerRxTimeMillis()); |
| 8730 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 8731 | info.getControllerTxTimeMillis()); |
| 8732 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 8733 | info.getControllerIdleTimeMillis()); |
| 8734 | |
| 8735 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8736 | final double opVolt = mPowerProfile.getAveragePower( |
| 8737 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8738 | if (opVolt != 0) { |
| 8739 | // We store the power drain as mAms. |
| 8740 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 8741 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 8742 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8743 | } |
| 8744 | |
| 8745 | /** |
| 8746 | * Read and distribute kernel wake lock use across apps. |
| 8747 | */ |
| 8748 | public void updateKernelWakelocksLocked() { |
| 8749 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 8750 | mTmpWakelockStats); |
| 8751 | if (wakelockStats == null) { |
| 8752 | // Not crashing might make board bringup easier. |
| 8753 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 8754 | return; |
| 8755 | } |
| 8756 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8757 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 8758 | boolean seenNonZeroTime = false; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8759 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 8760 | String name = ent.getKey(); |
| 8761 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 8762 | |
| 8763 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 8764 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 8765 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8766 | mKernelWakelockStats.put(name, kwlt); |
| 8767 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 8768 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8769 | kwlt.setUpdateVersion(kws.mVersion); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8770 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 8771 | if (kws.mVersion != wakelockStats.kernelWakelockVersion) { |
| 8772 | seenNonZeroTime |= kws.mTotalTime > 0; |
| 8773 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8774 | } |
| 8775 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8776 | int numWakelocksSetStale = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8777 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 8778 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 8779 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 8780 | SamplingTimer st = ent.getValue(); |
| 8781 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame^] | 8782 | st.endSample(); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8783 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8784 | } |
| 8785 | } |
| 8786 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8787 | |
| 8788 | if (!seenNonZeroTime) { |
| 8789 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 8790 | } |
| 8791 | |
| 8792 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 8793 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 8794 | wakelockStats.kernelWakelockVersion); |
| 8795 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8796 | } |
| 8797 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8798 | // We use an anonymous class to access these variables, |
| 8799 | // so they can't live on the stack or they'd have to be |
| 8800 | // final MutableLong objects (more allocations). |
| 8801 | // Used in updateCpuTimeLocked(). |
| 8802 | long mTempTotalCpuUserTimeUs; |
| 8803 | long mTempTotalCpuSystemTimeUs; |
| 8804 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8805 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8806 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 8807 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 8808 | * 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] | 8809 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8810 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8811 | if (mPowerProfile == null) { |
| 8812 | return; |
| 8813 | } |
| 8814 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8815 | if (DEBUG_ENERGY_CPU) { |
| 8816 | Slog.d(TAG, "!Cpu updating!"); |
| 8817 | } |
| 8818 | |
| 8819 | // Holding a wakelock costs more than just using the cpu. |
| 8820 | // Currently, we assign only half the cpu time to an app that is running but |
| 8821 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 8822 | // If no app is holding a wakelock, then the distribution is normal. |
| 8823 | final int wakelockWeight = 50; |
| 8824 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8825 | // Read the time spent for each cluster at various cpu frequencies. |
| 8826 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 8827 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 8828 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 8829 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8830 | |
| 8831 | int numWakelocks = 0; |
| 8832 | |
| 8833 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 8834 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 8835 | final int numPartialTimers = mPartialTimers.size(); |
| 8836 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 8837 | for (int i = 0; i < numPartialTimers; i++) { |
| 8838 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8839 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8840 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 8841 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 8842 | // the newly added timer for past cpu time, so we only consider timers that |
| 8843 | // were present for one round of collection. Once a timer has gone through |
| 8844 | // a round of collection, its mInList field is set to true. |
| 8845 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8846 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8847 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8848 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8849 | |
| 8850 | final int numWakelocksF = numWakelocks; |
| 8851 | mTempTotalCpuUserTimeUs = 0; |
| 8852 | mTempTotalCpuSystemTimeUs = 0; |
| 8853 | |
| 8854 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 8855 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 8856 | // we just ignore the data. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8857 | final long startTimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8858 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 8859 | new KernelUidCpuTimeReader.Callback() { |
| 8860 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8861 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs, |
| 8862 | long powerMaUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8863 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 8864 | |
| 8865 | // Accumulate the total system and user time. |
| 8866 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 8867 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 8868 | |
| 8869 | StringBuilder sb = null; |
| 8870 | if (DEBUG_ENERGY_CPU) { |
| 8871 | sb = new StringBuilder(); |
| 8872 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 8873 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8874 | sb.append(" s="); |
| 8875 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8876 | sb.append(" p=").append(powerMaUs / 1000).append("mAms\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8877 | } |
| 8878 | |
| 8879 | if (numWakelocksF > 0) { |
| 8880 | // We have wakelocks being held, so only give a portion of the |
| 8881 | // time to the process. The rest will be distributed among wakelock |
| 8882 | // holders. |
| 8883 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 8884 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 8885 | } |
| 8886 | |
| 8887 | if (sb != null) { |
| 8888 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 8889 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8890 | sb.append(" s="); |
| 8891 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8892 | sb.append(" p=").append(powerMaUs / 1000).append("mAms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8893 | Slog.d(TAG, sb.toString()); |
| 8894 | } |
| 8895 | |
| 8896 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 8897 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8898 | u.mCpuPower.addCountLocked(powerMaUs); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8899 | |
| 8900 | // Add the cpu speeds to this UID. These are used as a ratio |
| 8901 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8902 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8903 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 8904 | numClusters) { |
| 8905 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8906 | } |
| 8907 | |
| 8908 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8909 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 8910 | cluster); |
| 8911 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 8912 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8913 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8914 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8915 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8916 | |
| 8917 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 8918 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 8919 | if (cpuSpeeds[speed] == null) { |
| 8920 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8921 | } |
| 8922 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 8923 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8924 | } |
| 8925 | } |
| 8926 | }); |
| 8927 | |
| 8928 | if (DEBUG_ENERGY_CPU) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8929 | Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) + |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8930 | " ms"); |
| 8931 | } |
| 8932 | |
| 8933 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 8934 | // Distribute a portion of the total cpu time to wakelock holders. |
| 8935 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 8936 | mTempTotalCpuSystemTimeUs = |
| 8937 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 8938 | |
| 8939 | for (int i = 0; i < numPartialTimers; i++) { |
| 8940 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8941 | |
| 8942 | // The system does not share any blame, as it is usually holding the wakelock |
| 8943 | // on behalf of an app. |
| 8944 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8945 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 8946 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 8947 | |
| 8948 | if (DEBUG_ENERGY_CPU) { |
| 8949 | StringBuilder sb = new StringBuilder(); |
| 8950 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 8951 | .append(": u="); |
| 8952 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8953 | sb.append(" s="); |
| 8954 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 8955 | Slog.d(TAG, sb.toString()); |
| 8956 | } |
| 8957 | |
| 8958 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 8959 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 8960 | |
| 8961 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 8962 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8963 | |
| 8964 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 8965 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 8966 | numWakelocks--; |
| 8967 | } |
| 8968 | } |
| 8969 | |
| 8970 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 8971 | // Anything left over is given to the system. |
| 8972 | if (DEBUG_ENERGY_CPU) { |
| 8973 | StringBuilder sb = new StringBuilder(); |
| 8974 | sb.append(" Distributing lost time to system: u="); |
| 8975 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 8976 | sb.append(" s="); |
| 8977 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 8978 | Slog.d(TAG, sb.toString()); |
| 8979 | } |
| 8980 | |
| 8981 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 8982 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 8983 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 8984 | |
| 8985 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 8986 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 8987 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8988 | } |
| 8989 | } |
| 8990 | |
| 8991 | // See if there is a difference in wakelocks between this collection and the last |
| 8992 | // collection. |
| 8993 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 8994 | // No difference, so each timer is now considered for the next collection. |
| 8995 | for (int i = 0; i < numPartialTimers; i++) { |
| 8996 | mPartialTimers.get(i).mInList = true; |
| 8997 | } |
| 8998 | } else { |
| 8999 | // The lists are different, meaning we added (or removed a timer) since the last |
| 9000 | // collection. |
| 9001 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 9002 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 9003 | mLastPartialTimers.get(i).mInList = false; |
| 9004 | } |
| 9005 | mLastPartialTimers.clear(); |
| 9006 | |
| 9007 | // Mark the current timers as gone through a collection. |
| 9008 | for (int i = 0; i < numPartialTimers; i++) { |
| 9009 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9010 | timer.mInList = true; |
| 9011 | mLastPartialTimers.add(timer); |
| 9012 | } |
| 9013 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9014 | } |
| 9015 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9016 | boolean setChargingLocked(boolean charging) { |
| 9017 | if (mCharging != charging) { |
| 9018 | mCharging = charging; |
| 9019 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9020 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9021 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9022 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9023 | } |
| 9024 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 9025 | return true; |
| 9026 | } |
| 9027 | return false; |
| 9028 | } |
| 9029 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9030 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 9031 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9032 | boolean doWrite = false; |
| 9033 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 9034 | m.arg1 = onBattery ? 1 : 0; |
| 9035 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9036 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9037 | final long uptime = mSecUptime * 1000; |
| 9038 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9039 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9040 | if (onBattery) { |
| 9041 | // We will reset our status if we are unplugging after the |
| 9042 | // battery was last full, or the level is at 100, or |
| 9043 | // we have gone through a significant charge (from a very low |
| 9044 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9045 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 9046 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9047 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9048 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 9049 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 9050 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9051 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9052 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9053 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 9054 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9055 | // Before we write, collect a snapshot of the final aggregated |
| 9056 | // stats to be reported in the next checkin. Only do this if we have |
| 9057 | // a sufficient amount of data to make it interesting. |
| 9058 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 9059 | final Parcel parcel = Parcel.obtain(); |
| 9060 | writeSummaryToParcel(parcel, true); |
| 9061 | BackgroundThread.getHandler().post(new Runnable() { |
| 9062 | @Override public void run() { |
| 9063 | synchronized (mCheckinFile) { |
| 9064 | FileOutputStream stream = null; |
| 9065 | try { |
| 9066 | stream = mCheckinFile.startWrite(); |
| 9067 | stream.write(parcel.marshall()); |
| 9068 | stream.flush(); |
| 9069 | FileUtils.sync(stream); |
| 9070 | stream.close(); |
| 9071 | mCheckinFile.finishWrite(stream); |
| 9072 | } catch (IOException e) { |
| 9073 | Slog.w("BatteryStats", |
| 9074 | "Error writing checkin battery statistics", e); |
| 9075 | mCheckinFile.failWrite(stream); |
| 9076 | } finally { |
| 9077 | parcel.recycle(); |
| 9078 | } |
| 9079 | } |
| 9080 | } |
| 9081 | }); |
| 9082 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9083 | doWrite = true; |
| 9084 | resetAllStatsLocked(); |
| 9085 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9086 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9087 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9088 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9089 | if (mCharging) { |
| 9090 | setChargingLocked(false); |
| 9091 | } |
| 9092 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9093 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9094 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9095 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9096 | mDischargeStepTracker.clearTime(); |
| 9097 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9098 | mInitStepMode = mCurStepMode; |
| 9099 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9100 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9101 | mHistoryCur.batteryLevel = (byte)level; |
| 9102 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9103 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 9104 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9105 | if (reset) { |
| 9106 | mRecordingHistory = true; |
| 9107 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 9108 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9109 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9110 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9111 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9112 | mDischargeScreenOnUnplugLevel = level; |
| 9113 | mDischargeScreenOffUnplugLevel = 0; |
| 9114 | } else { |
| 9115 | mDischargeScreenOnUnplugLevel = 0; |
| 9116 | mDischargeScreenOffUnplugLevel = level; |
| 9117 | } |
| 9118 | mDischargeAmountScreenOn = 0; |
| 9119 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9120 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9121 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9122 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9123 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9124 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9125 | mHistoryCur.batteryLevel = (byte)level; |
| 9126 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9127 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 9128 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9129 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9130 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9131 | if (level < mDischargeUnplugLevel) { |
| 9132 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 9133 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 9134 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9135 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 9136 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9137 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9138 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9139 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9140 | mInitStepMode = mCurStepMode; |
| 9141 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9142 | } |
| 9143 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 9144 | if (mFile != null) { |
| 9145 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9146 | } |
| 9147 | } |
| 9148 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9149 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9150 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 9151 | boolean reset) { |
| 9152 | mRecordingHistory = true; |
| 9153 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9154 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 9155 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9156 | mHistoryCur); |
| 9157 | mHistoryCur.currentTime = 0; |
| 9158 | if (reset) { |
| 9159 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 9160 | } |
| 9161 | } |
| 9162 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9163 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 9164 | final long uptimeMs) { |
| 9165 | if (mRecordingHistory) { |
| 9166 | mHistoryCur.currentTime = currentTime; |
| 9167 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 9168 | mHistoryCur); |
| 9169 | mHistoryCur.currentTime = 0; |
| 9170 | } |
| 9171 | } |
| 9172 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9173 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 9174 | if (mRecordingHistory) { |
| 9175 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9176 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 9177 | mHistoryCur); |
| 9178 | mHistoryCur.currentTime = 0; |
| 9179 | } |
| 9180 | } |
| 9181 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9182 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9183 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9184 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9185 | } |
| 9186 | } |
| 9187 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9188 | // 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] | 9189 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9190 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9191 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9192 | int temp, int volt) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9193 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9194 | final long uptime = mClocks.uptimeMillis(); |
| 9195 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9196 | if (!mHaveBatteryLevel) { |
| 9197 | mHaveBatteryLevel = true; |
| 9198 | // We start out assuming that the device is plugged in (not |
| 9199 | // on battery). If our first report is now that we are indeed |
| 9200 | // plugged in, then twiddle our state to correctly reflect that |
| 9201 | // since we won't be going through the full setOnBattery(). |
| 9202 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9203 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9204 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9205 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9206 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9207 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9208 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9209 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9210 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9211 | mHistoryCur.batteryStatus = (byte)status; |
| 9212 | mHistoryCur.batteryLevel = (byte)level; |
| 9213 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 9214 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9215 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9216 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 9217 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 9218 | } |
| 9219 | int oldStatus = mHistoryCur.batteryStatus; |
| 9220 | if (onBattery) { |
| 9221 | mDischargeCurrentLevel = level; |
| 9222 | if (!mRecordingHistory) { |
| 9223 | mRecordingHistory = true; |
| 9224 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 9225 | } |
| 9226 | } else if (level < 96) { |
| 9227 | if (!mRecordingHistory) { |
| 9228 | mRecordingHistory = true; |
| 9229 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9230 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9231 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9232 | mCurrentBatteryLevel = level; |
| 9233 | if (mDischargePlugLevel < 0) { |
| 9234 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9235 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9236 | if (onBattery != mOnBattery) { |
| 9237 | mHistoryCur.batteryLevel = (byte)level; |
| 9238 | mHistoryCur.batteryStatus = (byte)status; |
| 9239 | mHistoryCur.batteryHealth = (byte)health; |
| 9240 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9241 | mHistoryCur.batteryTemperature = (short)temp; |
| 9242 | mHistoryCur.batteryVoltage = (char)volt; |
| 9243 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 9244 | } else { |
| 9245 | boolean changed = false; |
| 9246 | if (mHistoryCur.batteryLevel != level) { |
| 9247 | mHistoryCur.batteryLevel = (byte)level; |
| 9248 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9249 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9250 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 9251 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9252 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9253 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9254 | if (mHistoryCur.batteryStatus != status) { |
| 9255 | mHistoryCur.batteryStatus = (byte)status; |
| 9256 | changed = true; |
| 9257 | } |
| 9258 | if (mHistoryCur.batteryHealth != health) { |
| 9259 | mHistoryCur.batteryHealth = (byte)health; |
| 9260 | changed = true; |
| 9261 | } |
| 9262 | if (mHistoryCur.batteryPlugType != plugType) { |
| 9263 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9264 | changed = true; |
| 9265 | } |
| 9266 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 9267 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 9268 | mHistoryCur.batteryTemperature = (short)temp; |
| 9269 | changed = true; |
| 9270 | } |
| 9271 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 9272 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 9273 | mHistoryCur.batteryVoltage = (char)volt; |
| 9274 | changed = true; |
| 9275 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9276 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 9277 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 9278 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 9279 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9280 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9281 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 9282 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9283 | modeBits, elapsedRealtime); |
| 9284 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9285 | modeBits, elapsedRealtime); |
| 9286 | mLastDischargeStepLevel = level; |
| 9287 | mMinDischargeStepLevel = level; |
| 9288 | mInitStepMode = mCurStepMode; |
| 9289 | mModStepMode = 0; |
| 9290 | } |
| 9291 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9292 | if (level >= 90) { |
| 9293 | // If the battery level is at least 90%, always consider the device to be |
| 9294 | // charging even if it happens to go down a level. |
| 9295 | changed |= setChargingLocked(true); |
| 9296 | mLastChargeStepLevel = level; |
| 9297 | } if (!mCharging) { |
| 9298 | if (mLastChargeStepLevel < level) { |
| 9299 | // We have not reporting that we are charging, but the level has now |
| 9300 | // gone up, so consider the state to be charging. |
| 9301 | changed |= setChargingLocked(true); |
| 9302 | mLastChargeStepLevel = level; |
| 9303 | } |
| 9304 | } else { |
| 9305 | if (mLastChargeStepLevel > level) { |
| 9306 | // We had reported that the device was charging, but here we are with |
| 9307 | // power connected and the level going down. Looks like the current |
| 9308 | // power supplied isn't enough, so consider the device to now be |
| 9309 | // discharging. |
| 9310 | changed |= setChargingLocked(false); |
| 9311 | mLastChargeStepLevel = level; |
| 9312 | } |
| 9313 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9314 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 9315 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9316 | modeBits, elapsedRealtime); |
| 9317 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9318 | modeBits, elapsedRealtime); |
| 9319 | mLastChargeStepLevel = level; |
| 9320 | mMaxChargeStepLevel = level; |
| 9321 | mInitStepMode = mCurStepMode; |
| 9322 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9323 | } |
| 9324 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9325 | if (changed) { |
| 9326 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 9327 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9328 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9329 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 9330 | // We don't record history while we are plugged in and fully charged. |
| 9331 | // The next time we are unplugged, history will be cleared. |
| 9332 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 9333 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9334 | } |
| 9335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9336 | public long getAwakeTimeBattery() { |
| 9337 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 9338 | } |
| 9339 | |
| 9340 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9341 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9342 | } |
| 9343 | |
| 9344 | @Override |
| 9345 | public long computeUptime(long curTime, int which) { |
| 9346 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9347 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9348 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9349 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9350 | } |
| 9351 | return 0; |
| 9352 | } |
| 9353 | |
| 9354 | @Override |
| 9355 | public long computeRealtime(long curTime, int which) { |
| 9356 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9357 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9358 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9359 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9360 | } |
| 9361 | return 0; |
| 9362 | } |
| 9363 | |
| 9364 | @Override |
| 9365 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9366 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9367 | } |
| 9368 | |
| 9369 | @Override |
| 9370 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9371 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9372 | } |
| 9373 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9374 | @Override |
| 9375 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 9376 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 9377 | } |
| 9378 | |
| 9379 | @Override |
| 9380 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 9381 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9382 | } |
| 9383 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9384 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 9385 | // For now we'll do a simple average across all steps. |
| 9386 | if (numSteps <= 0) { |
| 9387 | return -1; |
| 9388 | } |
| 9389 | long total = 0; |
| 9390 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9391 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9392 | } |
| 9393 | return total / numSteps; |
| 9394 | /* |
| 9395 | long[] buckets = new long[numSteps]; |
| 9396 | int numBuckets = 0; |
| 9397 | int numToAverage = 4; |
| 9398 | int i = 0; |
| 9399 | while (i < numSteps) { |
| 9400 | long totalTime = 0; |
| 9401 | int num = 0; |
| 9402 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9403 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9404 | num++; |
| 9405 | } |
| 9406 | buckets[numBuckets] = totalTime / num; |
| 9407 | numBuckets++; |
| 9408 | numToAverage *= 2; |
| 9409 | i += num; |
| 9410 | } |
| 9411 | if (numBuckets < 1) { |
| 9412 | return -1; |
| 9413 | } |
| 9414 | long averageTime = buckets[numBuckets-1]; |
| 9415 | for (i=numBuckets-2; i>=0; i--) { |
| 9416 | averageTime = (averageTime + buckets[i]) / 2; |
| 9417 | } |
| 9418 | return averageTime; |
| 9419 | */ |
| 9420 | } |
| 9421 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9422 | @Override |
| 9423 | public long computeBatteryTimeRemaining(long curTime) { |
| 9424 | if (!mOnBattery) { |
| 9425 | return -1; |
| 9426 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9427 | /* Simple implementation just looks at the average discharge per level across the |
| 9428 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9429 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 9430 | if (discharge < 2) { |
| 9431 | return -1; |
| 9432 | } |
| 9433 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 9434 | if (duration < 1000*1000) { |
| 9435 | return -1; |
| 9436 | } |
| 9437 | long usPerLevel = duration/discharge; |
| 9438 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9439 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9440 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9441 | return -1; |
| 9442 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9443 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9444 | if (msPerLevel <= 0) { |
| 9445 | return -1; |
| 9446 | } |
| 9447 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9448 | } |
| 9449 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9450 | @Override |
| 9451 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 9452 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9453 | } |
| 9454 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9455 | @Override |
| 9456 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 9457 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9458 | } |
| 9459 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9460 | @Override |
| 9461 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9462 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9463 | // Not yet working. |
| 9464 | return -1; |
| 9465 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9466 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9467 | int curLevel = mCurrentBatteryLevel; |
| 9468 | int plugLevel = mDischargePlugLevel; |
| 9469 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 9470 | return -1; |
| 9471 | } |
| 9472 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 9473 | if (duration < 1000*1000) { |
| 9474 | return -1; |
| 9475 | } |
| 9476 | long usPerLevel = duration/(curLevel-plugLevel); |
| 9477 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9478 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9479 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9480 | return -1; |
| 9481 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9482 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9483 | if (msPerLevel <= 0) { |
| 9484 | return -1; |
| 9485 | } |
| 9486 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9487 | } |
| 9488 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9489 | @Override |
| 9490 | public LevelStepTracker getChargeLevelStepTracker() { |
| 9491 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9492 | } |
| 9493 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9494 | @Override |
| 9495 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 9496 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9497 | } |
| 9498 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9499 | @Override |
| 9500 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 9501 | return mDailyPackageChanges; |
| 9502 | } |
| 9503 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 9504 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9505 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9506 | } |
| 9507 | |
| 9508 | @Override |
| 9509 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9510 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9511 | } |
| 9512 | |
| 9513 | @Override |
| 9514 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9515 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9516 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 9517 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9518 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9519 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9520 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9521 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9522 | } |
| 9523 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9524 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9525 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9526 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9527 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9528 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9529 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9530 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9531 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9532 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9533 | } |
| 9534 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9535 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9536 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9537 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9539 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9540 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9541 | public int getLowDischargeAmountSinceCharge() { |
| 9542 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9543 | int val = mLowDischargeAmountSinceCharge; |
| 9544 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9545 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 9546 | } |
| 9547 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9548 | } |
| 9549 | } |
| 9550 | |
| 9551 | @Override |
| 9552 | public int getHighDischargeAmountSinceCharge() { |
| 9553 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9554 | int val = mHighDischargeAmountSinceCharge; |
| 9555 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9556 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 9557 | } |
| 9558 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9559 | } |
| 9560 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9561 | |
| 9562 | @Override |
| 9563 | public int getDischargeAmount(int which) { |
| 9564 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 9565 | ? getHighDischargeAmountSinceCharge() |
| 9566 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 9567 | if (dischargeAmount < 0) { |
| 9568 | dischargeAmount = 0; |
| 9569 | } |
| 9570 | return dischargeAmount; |
| 9571 | } |
| 9572 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9573 | public int getDischargeAmountScreenOn() { |
| 9574 | synchronized(this) { |
| 9575 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9576 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9577 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9578 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9579 | } |
| 9580 | return val; |
| 9581 | } |
| 9582 | } |
| 9583 | |
| 9584 | public int getDischargeAmountScreenOnSinceCharge() { |
| 9585 | synchronized(this) { |
| 9586 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9587 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9588 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9589 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9590 | } |
| 9591 | return val; |
| 9592 | } |
| 9593 | } |
| 9594 | |
| 9595 | public int getDischargeAmountScreenOff() { |
| 9596 | synchronized(this) { |
| 9597 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9598 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9599 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9600 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9601 | } |
| 9602 | return val; |
| 9603 | } |
| 9604 | } |
| 9605 | |
| 9606 | public int getDischargeAmountScreenOffSinceCharge() { |
| 9607 | synchronized(this) { |
| 9608 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9609 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9610 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9611 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9612 | } |
| 9613 | return val; |
| 9614 | } |
| 9615 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9617 | /** |
| 9618 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 9619 | */ |
| 9620 | public Uid getUidStatsLocked(int uid) { |
| 9621 | Uid u = mUidStats.get(uid); |
| 9622 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9623 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9624 | mUidStats.put(uid, u); |
| 9625 | } |
| 9626 | return u; |
| 9627 | } |
| 9628 | |
| 9629 | /** |
| 9630 | * Remove the statistics object for a particular uid. |
| 9631 | */ |
| 9632 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 9633 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | mUidStats.remove(uid); |
| 9635 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 9636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9637 | /** |
| 9638 | * Retrieve the statistics object for a particular process, creating |
| 9639 | * if needed. |
| 9640 | */ |
| 9641 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9642 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9643 | Uid u = getUidStatsLocked(uid); |
| 9644 | return u.getProcessStatsLocked(name); |
| 9645 | } |
| 9646 | |
| 9647 | /** |
| 9648 | * Retrieve the statistics object for a particular process, creating |
| 9649 | * if needed. |
| 9650 | */ |
| 9651 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9652 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9653 | Uid u = getUidStatsLocked(uid); |
| 9654 | return u.getPackageStatsLocked(pkg); |
| 9655 | } |
| 9656 | |
| 9657 | /** |
| 9658 | * Retrieve the statistics object for a particular service, creating |
| 9659 | * if needed. |
| 9660 | */ |
| 9661 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9662 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9663 | Uid u = getUidStatsLocked(uid); |
| 9664 | return u.getServiceStatsLocked(pkg, name); |
| 9665 | } |
| 9666 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9667 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9668 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9669 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9670 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9671 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9672 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9673 | Parcel mPendingWrite = null; |
| 9674 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 9675 | |
| 9676 | public void writeAsyncLocked() { |
| 9677 | writeLocked(false); |
| 9678 | } |
| 9679 | |
| 9680 | public void writeSyncLocked() { |
| 9681 | writeLocked(true); |
| 9682 | } |
| 9683 | |
| 9684 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9685 | if (mFile == null) { |
| 9686 | 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] | 9687 | return; |
| 9688 | } |
| 9689 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9690 | if (mShuttingDown) { |
| 9691 | return; |
| 9692 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9693 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9694 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9695 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9696 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9697 | |
| 9698 | if (mPendingWrite != null) { |
| 9699 | mPendingWrite.recycle(); |
| 9700 | } |
| 9701 | mPendingWrite = out; |
| 9702 | |
| 9703 | if (sync) { |
| 9704 | commitPendingDataToDisk(); |
| 9705 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9706 | BackgroundThread.getHandler().post(new Runnable() { |
| 9707 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9708 | commitPendingDataToDisk(); |
| 9709 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9710 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9711 | } |
| 9712 | } |
| 9713 | |
| 9714 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9715 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9716 | synchronized (this) { |
| 9717 | next = mPendingWrite; |
| 9718 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9719 | if (next == null) { |
| 9720 | return; |
| 9721 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9722 | |
| 9723 | mWriteLock.lock(); |
| 9724 | } |
| 9725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9727 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9728 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9729 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 9730 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9732 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9733 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9734 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9735 | mFile.rollback(); |
| 9736 | } finally { |
| 9737 | next.recycle(); |
| 9738 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 9739 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9740 | } |
| 9741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9742 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9743 | if (mDailyFile != null) { |
| 9744 | readDailyStatsLocked(); |
| 9745 | } |
| 9746 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9747 | if (mFile == null) { |
| 9748 | 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] | 9749 | return; |
| 9750 | } |
| 9751 | |
| 9752 | mUidStats.clear(); |
| 9753 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9754 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9755 | File file = mFile.chooseForRead(); |
| 9756 | if (!file.exists()) { |
| 9757 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9759 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9760 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9761 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9762 | Parcel in = Parcel.obtain(); |
| 9763 | in.unmarshall(raw, 0, raw.length); |
| 9764 | in.setDataPosition(0); |
| 9765 | stream.close(); |
| 9766 | |
| 9767 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 9768 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9769 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9770 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9772 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9773 | mEndPlatformVersion = Build.ID; |
| 9774 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9775 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9776 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9777 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 9778 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9779 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9780 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9781 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9782 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 9783 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9784 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9785 | |
| 9786 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | } |
| 9788 | |
| 9789 | public int describeContents() { |
| 9790 | return 0; |
| 9791 | } |
| 9792 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9793 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9794 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9795 | |
| 9796 | mHistoryBuffer.setDataSize(0); |
| 9797 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9798 | mHistoryTagPool.clear(); |
| 9799 | mNextHistoryTagIdx = 0; |
| 9800 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9801 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9802 | int numTags = in.readInt(); |
| 9803 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9804 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9805 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9806 | if (str == null) { |
| 9807 | throw new ParcelFormatException("null history tag string"); |
| 9808 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9809 | int uid = in.readInt(); |
| 9810 | HistoryTag tag = new HistoryTag(); |
| 9811 | tag.string = str; |
| 9812 | tag.uid = uid; |
| 9813 | tag.poolIdx = idx; |
| 9814 | mHistoryTagPool.put(tag, idx); |
| 9815 | if (idx >= mNextHistoryTagIdx) { |
| 9816 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9817 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9818 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9819 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9820 | |
| 9821 | int bufSize = in.readInt(); |
| 9822 | int curPos = in.dataPosition(); |
| 9823 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9824 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 9825 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9826 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9827 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 9828 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9829 | } else { |
| 9830 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 9831 | + " bytes at " + curPos); |
| 9832 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 9833 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9834 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9835 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9836 | if (andOldHistory) { |
| 9837 | readOldHistory(in); |
| 9838 | } |
| 9839 | |
| 9840 | if (DEBUG_HISTORY) { |
| 9841 | StringBuilder sb = new StringBuilder(128); |
| 9842 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 9843 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9844 | Slog.i(TAG, sb.toString()); |
| 9845 | } |
| 9846 | mHistoryBaseTime = historyBaseTime; |
| 9847 | if (DEBUG_HISTORY) { |
| 9848 | StringBuilder sb = new StringBuilder(128); |
| 9849 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 9850 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9851 | Slog.i(TAG, sb.toString()); |
| 9852 | } |
| 9853 | |
| 9854 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 9855 | // the last run until samples in this run. |
| 9856 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9857 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9858 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9859 | if (DEBUG_HISTORY) { |
| 9860 | StringBuilder sb = new StringBuilder(128); |
| 9861 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 9862 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9863 | Slog.i(TAG, sb.toString()); |
| 9864 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 9865 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9866 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9867 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9868 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9869 | if (!USE_OLD_HISTORY) { |
| 9870 | return; |
| 9871 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9872 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 9873 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 9874 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9875 | HistoryItem rec = new HistoryItem(time, in); |
| 9876 | addHistoryRecordLocked(rec); |
| 9877 | } |
| 9878 | } |
| 9879 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9880 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9881 | if (DEBUG_HISTORY) { |
| 9882 | StringBuilder sb = new StringBuilder(128); |
| 9883 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 9884 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9885 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 9886 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9887 | Slog.i(TAG, sb.toString()); |
| 9888 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9889 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9890 | if (!inclData) { |
| 9891 | out.writeInt(0); |
| 9892 | out.writeInt(0); |
| 9893 | return; |
| 9894 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9895 | out.writeInt(mHistoryTagPool.size()); |
| 9896 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 9897 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9898 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9899 | out.writeString(tag.string); |
| 9900 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9901 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9902 | out.writeInt(mHistoryBuffer.dataSize()); |
| 9903 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 9904 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 9905 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9906 | |
| 9907 | if (andOldHistory) { |
| 9908 | writeOldHistory(out); |
| 9909 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9910 | } |
| 9911 | |
| 9912 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9913 | if (!USE_OLD_HISTORY) { |
| 9914 | return; |
| 9915 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9916 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9917 | while (rec != null) { |
| 9918 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 9919 | rec = rec.next; |
| 9920 | } |
| 9921 | out.writeLong(-1); |
| 9922 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9923 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9924 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9925 | final int version = in.readInt(); |
| 9926 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9927 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9928 | + ", expected " + VERSION + "; erasing old stats"); |
| 9929 | return; |
| 9930 | } |
| 9931 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9932 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9934 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9935 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9937 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9938 | mStartPlatformVersion = in.readString(); |
| 9939 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9940 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 9941 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9942 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9943 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9944 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9945 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9946 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9947 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9948 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9949 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9950 | mDischargeStepTracker.readFromParcel(in); |
| 9951 | mChargeStepTracker.readFromParcel(in); |
| 9952 | mDailyDischargeStepTracker.readFromParcel(in); |
| 9953 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9954 | int NPKG = in.readInt(); |
| 9955 | if (NPKG > 0) { |
| 9956 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 9957 | while (NPKG > 0) { |
| 9958 | NPKG--; |
| 9959 | PackageChange pc = new PackageChange(); |
| 9960 | pc.mPackageName = in.readString(); |
| 9961 | pc.mUpdate = in.readInt() != 0; |
| 9962 | pc.mVersionCode = in.readInt(); |
| 9963 | mDailyPackageChanges.add(pc); |
| 9964 | } |
| 9965 | } else { |
| 9966 | mDailyPackageChanges = null; |
| 9967 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9968 | mDailyStartTime = in.readLong(); |
| 9969 | mNextMinDailyDeadline = in.readLong(); |
| 9970 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9972 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9973 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9974 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9976 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9977 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 9978 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9979 | mInteractive = false; |
| 9980 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9981 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9982 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 9983 | mLongestLightIdleTime = in.readLong(); |
| 9984 | mLongestFullIdleTime = in.readLong(); |
| 9985 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 9986 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 9987 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9988 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9989 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9990 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9991 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9992 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 9993 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9994 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9995 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 9996 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9997 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9998 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9999 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10000 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10001 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10002 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10003 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10004 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10005 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 10006 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10007 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10008 | mWifiOn = false; |
| 10009 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10010 | mGlobalWifiRunning = false; |
| 10011 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10012 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10013 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 10014 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10015 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10016 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 10017 | } |
| 10018 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10019 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10020 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10021 | mWifiActivity.readSummaryFromParcel(in); |
| 10022 | mBluetoothActivity.readSummaryFromParcel(in); |
| 10023 | mModemActivity.readSummaryFromParcel(in); |
| 10024 | mHasWifiReporting = in.readInt() != 0; |
| 10025 | mHasBluetoothReporting = in.readInt() != 0; |
| 10026 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10027 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10028 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10029 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10030 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10031 | mCameraOnNesting = 0; |
| 10032 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10033 | mBluetoothScanNesting = 0; |
| 10034 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10035 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10036 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10037 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10038 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10039 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10040 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10041 | if (in.readInt() != 0) { |
| 10042 | String kwltName = in.readString(); |
| 10043 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 10044 | } |
| 10045 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10046 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10047 | int NWR = in.readInt(); |
| 10048 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10049 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10050 | } |
| 10051 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10052 | if (in.readInt() != 0) { |
| 10053 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10054 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10055 | } |
| 10056 | } |
| 10057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10058 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10059 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10060 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10061 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10062 | for (int iu = 0; iu < NU; iu++) { |
| 10063 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10064 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10065 | mUidStats.put(uid, u); |
| 10066 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10067 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10068 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10069 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10070 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10071 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10072 | if (in.readInt() != 0) { |
| 10073 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 10074 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10075 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10076 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10077 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10078 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10079 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 10080 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10081 | if (in.readInt() != 0) { |
| 10082 | u.makeWifiBatchedScanBin(i, null); |
| 10083 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 10084 | } |
| 10085 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10086 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10087 | if (in.readInt() != 0) { |
| 10088 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 10089 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10090 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10091 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10092 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10093 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10094 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10095 | } |
| 10096 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10097 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10098 | } |
| 10099 | if (in.readInt() != 0) { |
| 10100 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10101 | } |
| 10102 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10103 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 10104 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10105 | if (in.readInt() != 0) { |
| 10106 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 10107 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 10108 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10109 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10110 | if (in.readInt() != 0) { |
| 10111 | u.makeProcessState(i, null); |
| 10112 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 10113 | } |
| 10114 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10115 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10116 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10117 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10118 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10119 | if (in.readInt() != 0) { |
| 10120 | if (u.mUserActivityCounters == null) { |
| 10121 | u.initUserActivityLocked(); |
| 10122 | } |
| 10123 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10124 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10125 | } |
| 10126 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10127 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10128 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10129 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10130 | u.initNetworkActivityLocked(); |
| 10131 | } |
| 10132 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10133 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10134 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10135 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10136 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 10137 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10138 | } |
| 10139 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10140 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 10141 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10142 | u.mCpuPower.readSummaryFromParcelLocked(in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10143 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10144 | if (in.readInt() != 0) { |
| 10145 | final int numClusters = in.readInt(); |
| 10146 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 10147 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10148 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10149 | |
| 10150 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 10151 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10152 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10153 | final int NSB = in.readInt(); |
| 10154 | if (mPowerProfile != null && |
| 10155 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 10156 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 10157 | NSB); |
| 10158 | } |
| 10159 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10160 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 10161 | for (int speed = 0; speed < NSB; speed++) { |
| 10162 | if (in.readInt() != 0) { |
| 10163 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 10164 | mOnBatteryTimeBase); |
| 10165 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 10166 | } |
| 10167 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10168 | } else { |
| 10169 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10170 | } |
| 10171 | } |
| 10172 | } else { |
| 10173 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10174 | } |
| 10175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10176 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10177 | if (NW > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10178 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10180 | for (int iw = 0; iw < NW; iw++) { |
| 10181 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10182 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10183 | } |
| 10184 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10185 | int NS = in.readInt(); |
| 10186 | if (NS > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10187 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10188 | } |
| 10189 | for (int is = 0; is < NS; is++) { |
| 10190 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10191 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10192 | } |
| 10193 | |
| 10194 | int NJ = in.readInt(); |
| 10195 | if (NJ > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10196 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10197 | } |
| 10198 | for (int ij = 0; ij < NJ; ij++) { |
| 10199 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10200 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10201 | } |
| 10202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10203 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10204 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10205 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10207 | for (int is = 0; is < NP; is++) { |
| 10208 | int seNumber = in.readInt(); |
| 10209 | if (in.readInt() != 0) { |
| 10210 | u.getSensorTimerLocked(seNumber, true) |
| 10211 | .readSummaryFromParcelLocked(in); |
| 10212 | } |
| 10213 | } |
| 10214 | |
| 10215 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10216 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10217 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10218 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10219 | for (int ip = 0; ip < NP; ip++) { |
| 10220 | String procName = in.readString(); |
| 10221 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 10222 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10223 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10224 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10225 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10226 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 10227 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10228 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10229 | } |
| 10230 | |
| 10231 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10232 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10233 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10235 | for (int ip = 0; ip < NP; ip++) { |
| 10236 | String pkgName = in.readString(); |
| 10237 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10238 | final int NWA = in.readInt(); |
| 10239 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10240 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10241 | } |
| 10242 | p.mWakeupAlarms.clear(); |
| 10243 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10244 | String tag = in.readString(); |
| 10245 | Counter c = new Counter(mOnBatteryTimeBase); |
| 10246 | c.readSummaryFromParcelLocked(in); |
| 10247 | p.mWakeupAlarms.put(tag, c); |
| 10248 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10249 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10250 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10251 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10252 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10253 | for (int is = 0; is < NS; is++) { |
| 10254 | String servName = in.readString(); |
| 10255 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 10256 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10257 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10258 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10259 | } |
| 10260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10261 | } |
| 10262 | } |
| 10263 | |
| 10264 | /** |
| 10265 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 10266 | * disk. This format does not allow a lossless round-trip. |
| 10267 | * |
| 10268 | * @param out the Parcel to be written to. |
| 10269 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10270 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10271 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10272 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10273 | // Pull the clock time. This may update the time and make a new history entry |
| 10274 | // if we had originally pulled a time before the RTC was set. |
| 10275 | long startClockTime = getStartClockTime(); |
| 10276 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10277 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 10278 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10279 | |
| 10280 | out.writeInt(VERSION); |
| 10281 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10282 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10284 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10285 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10286 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10287 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10288 | out.writeString(mStartPlatformVersion); |
| 10289 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10290 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 10291 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10292 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10293 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10294 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10295 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10296 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 10297 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10298 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 10299 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10300 | mDischargeStepTracker.writeToParcel(out); |
| 10301 | mChargeStepTracker.writeToParcel(out); |
| 10302 | mDailyDischargeStepTracker.writeToParcel(out); |
| 10303 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10304 | if (mDailyPackageChanges != null) { |
| 10305 | final int NPKG = mDailyPackageChanges.size(); |
| 10306 | out.writeInt(NPKG); |
| 10307 | for (int i=0; i<NPKG; i++) { |
| 10308 | PackageChange pc = mDailyPackageChanges.get(i); |
| 10309 | out.writeString(pc.mPackageName); |
| 10310 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 10311 | out.writeInt(pc.mVersionCode); |
| 10312 | } |
| 10313 | } else { |
| 10314 | out.writeInt(0); |
| 10315 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10316 | out.writeLong(mDailyStartTime); |
| 10317 | out.writeLong(mNextMinDailyDeadline); |
| 10318 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10319 | |
| 10320 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10321 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10322 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10323 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10324 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10325 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10326 | out.writeLong(mLongestLightIdleTime); |
| 10327 | out.writeLong(mLongestFullIdleTime); |
| 10328 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10329 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10330 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10331 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10332 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10333 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10334 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10335 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10336 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10337 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10338 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10339 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10340 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10341 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10342 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10343 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10344 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10345 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10346 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10347 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 10348 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10349 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10350 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10351 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10352 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10353 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10354 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10355 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10356 | } |
| 10357 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10358 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10359 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10360 | mWifiActivity.writeSummaryToParcel(out); |
| 10361 | mBluetoothActivity.writeSummaryToParcel(out); |
| 10362 | mModemActivity.writeSummaryToParcel(out); |
| 10363 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 10364 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 10365 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 10366 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10367 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10368 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10369 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10370 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10371 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10372 | out.writeInt(mKernelWakelockStats.size()); |
| 10373 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10374 | Timer kwlt = ent.getValue(); |
| 10375 | if (kwlt != null) { |
| 10376 | out.writeInt(1); |
| 10377 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10378 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10379 | } else { |
| 10380 | out.writeInt(0); |
| 10381 | } |
| 10382 | } |
| 10383 | |
| 10384 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10385 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10386 | SamplingTimer timer = ent.getValue(); |
| 10387 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10388 | out.writeInt(1); |
| 10389 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10390 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10391 | } else { |
| 10392 | out.writeInt(0); |
| 10393 | } |
| 10394 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10396 | final int NU = mUidStats.size(); |
| 10397 | out.writeInt(NU); |
| 10398 | for (int iu = 0; iu < NU; iu++) { |
| 10399 | out.writeInt(mUidStats.keyAt(iu)); |
| 10400 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10401 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10402 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10403 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10404 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10405 | } else { |
| 10406 | out.writeInt(0); |
| 10407 | } |
| 10408 | if (u.mFullWifiLockTimer != null) { |
| 10409 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10410 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10411 | } else { |
| 10412 | out.writeInt(0); |
| 10413 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10414 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10415 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10416 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10417 | } else { |
| 10418 | out.writeInt(0); |
| 10419 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10420 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10421 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 10422 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10423 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10424 | } else { |
| 10425 | out.writeInt(0); |
| 10426 | } |
| 10427 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10428 | if (u.mWifiMulticastTimer != null) { |
| 10429 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10430 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10431 | } else { |
| 10432 | out.writeInt(0); |
| 10433 | } |
| 10434 | if (u.mAudioTurnedOnTimer != null) { |
| 10435 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10436 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10437 | } else { |
| 10438 | out.writeInt(0); |
| 10439 | } |
| 10440 | if (u.mVideoTurnedOnTimer != null) { |
| 10441 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10442 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10443 | } else { |
| 10444 | out.writeInt(0); |
| 10445 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10446 | if (u.mFlashlightTurnedOnTimer != null) { |
| 10447 | out.writeInt(1); |
| 10448 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10449 | } else { |
| 10450 | out.writeInt(0); |
| 10451 | } |
| 10452 | if (u.mCameraTurnedOnTimer != null) { |
| 10453 | out.writeInt(1); |
| 10454 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10455 | } else { |
| 10456 | out.writeInt(0); |
| 10457 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10458 | if (u.mForegroundActivityTimer != null) { |
| 10459 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10460 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10461 | } else { |
| 10462 | out.writeInt(0); |
| 10463 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10464 | if (u.mBluetoothScanTimer != null) { |
| 10465 | out.writeInt(1); |
| 10466 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10467 | } else { |
| 10468 | out.writeInt(0); |
| 10469 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10470 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10471 | if (u.mProcessStateTimer[i] != null) { |
| 10472 | out.writeInt(1); |
| 10473 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10474 | } else { |
| 10475 | out.writeInt(0); |
| 10476 | } |
| 10477 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10478 | if (u.mVibratorOnTimer != null) { |
| 10479 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10480 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10481 | } else { |
| 10482 | out.writeInt(0); |
| 10483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10484 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10485 | if (u.mUserActivityCounters == null) { |
| 10486 | out.writeInt(0); |
| 10487 | } else { |
| 10488 | out.writeInt(1); |
| 10489 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10490 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10491 | } |
| 10492 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10493 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10494 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10495 | out.writeInt(0); |
| 10496 | } else { |
| 10497 | out.writeInt(1); |
| 10498 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10499 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10500 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10501 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10502 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 10503 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10504 | } |
| 10505 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10506 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 10507 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10508 | u.mCpuPower.writeSummaryFromParcelLocked(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10509 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10510 | if (u.mCpuClusterSpeed != null) { |
| 10511 | out.writeInt(1); |
| 10512 | out.writeInt(u.mCpuClusterSpeed.length); |
| 10513 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 10514 | if (cpuSpeeds != null) { |
| 10515 | out.writeInt(1); |
| 10516 | out.writeInt(cpuSpeeds.length); |
| 10517 | for (LongSamplingCounter c : cpuSpeeds) { |
| 10518 | if (c != null) { |
| 10519 | out.writeInt(1); |
| 10520 | c.writeSummaryFromParcelLocked(out); |
| 10521 | } else { |
| 10522 | out.writeInt(0); |
| 10523 | } |
| 10524 | } |
| 10525 | } else { |
| 10526 | out.writeInt(0); |
| 10527 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10528 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10529 | } else { |
| 10530 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10531 | } |
| 10532 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10533 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 10534 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10535 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10536 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10537 | out.writeString(wakeStats.keyAt(iw)); |
| 10538 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10539 | if (wl.mTimerFull != null) { |
| 10540 | out.writeInt(1); |
| 10541 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10542 | } else { |
| 10543 | out.writeInt(0); |
| 10544 | } |
| 10545 | if (wl.mTimerPartial != null) { |
| 10546 | out.writeInt(1); |
| 10547 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10548 | } else { |
| 10549 | out.writeInt(0); |
| 10550 | } |
| 10551 | if (wl.mTimerWindow != null) { |
| 10552 | out.writeInt(1); |
| 10553 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10554 | } else { |
| 10555 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10557 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10558 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10559 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10560 | } else { |
| 10561 | out.writeInt(0); |
| 10562 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10563 | } |
| 10564 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10565 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 10566 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10567 | out.writeInt(NS); |
| 10568 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10569 | out.writeString(syncStats.keyAt(is)); |
| 10570 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10571 | } |
| 10572 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10573 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 10574 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10575 | out.writeInt(NJ); |
| 10576 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10577 | out.writeString(jobStats.keyAt(ij)); |
| 10578 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10579 | } |
| 10580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10581 | int NSE = u.mSensorStats.size(); |
| 10582 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10583 | for (int ise=0; ise<NSE; ise++) { |
| 10584 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 10585 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 10586 | if (se.mTimer != null) { |
| 10587 | out.writeInt(1); |
| 10588 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10589 | } else { |
| 10590 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10591 | } |
| 10592 | } |
| 10593 | |
| 10594 | int NP = u.mProcessStats.size(); |
| 10595 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10596 | for (int ip=0; ip<NP; ip++) { |
| 10597 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 10598 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 10599 | out.writeLong(ps.mUserTime); |
| 10600 | out.writeLong(ps.mSystemTime); |
| 10601 | out.writeLong(ps.mForegroundTime); |
| 10602 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10603 | out.writeInt(ps.mNumCrashes); |
| 10604 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10605 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10606 | } |
| 10607 | |
| 10608 | NP = u.mPackageStats.size(); |
| 10609 | out.writeInt(NP); |
| 10610 | if (NP > 0) { |
| 10611 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 10612 | : u.mPackageStats.entrySet()) { |
| 10613 | out.writeString(ent.getKey()); |
| 10614 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10615 | final int NWA = ps.mWakeupAlarms.size(); |
| 10616 | out.writeInt(NWA); |
| 10617 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10618 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 10619 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 10620 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10621 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10622 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10623 | for (int is=0; is<NS; is++) { |
| 10624 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 10625 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 10626 | long time = ss.getStartTimeToNowLocked( |
| 10627 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 10628 | out.writeLong(time); |
| 10629 | out.writeInt(ss.mStarts); |
| 10630 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10631 | } |
| 10632 | } |
| 10633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | } |
| 10635 | } |
| 10636 | |
| 10637 | public void readFromParcel(Parcel in) { |
| 10638 | readFromParcelLocked(in); |
| 10639 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10641 | void readFromParcelLocked(Parcel in) { |
| 10642 | int magic = in.readInt(); |
| 10643 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10644 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10645 | } |
| 10646 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10647 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10649 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10650 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10651 | mStartPlatformVersion = in.readString(); |
| 10652 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10653 | mUptime = in.readLong(); |
| 10654 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | mRealtime = in.readLong(); |
| 10656 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10657 | mOnBattery = in.readInt() != 0; |
| 10658 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10659 | mOnBatteryTimeBase.readFromParcel(in); |
| 10660 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 10661 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10662 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10663 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10664 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10665 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 10666 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10667 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10668 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10669 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10670 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10671 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10672 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10673 | mLongestLightIdleTime = in.readLong(); |
| 10674 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10675 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 10676 | mOnBatteryTimeBase, in); |
| 10677 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10678 | mOnBatteryTimeBase, in); |
| 10679 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 10680 | mOnBatteryTimeBase, in); |
| 10681 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 10682 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10683 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10684 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10685 | null, mOnBatteryTimeBase, in); |
| 10686 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10687 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10688 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10689 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10690 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10691 | null, mOnBatteryTimeBase, in); |
| 10692 | } |
| 10693 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10694 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10695 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10696 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10697 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10698 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 10699 | mOnBatteryTimeBase, in); |
| 10700 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10701 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10702 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10703 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10704 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10705 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10706 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10707 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10708 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10709 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 10710 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10711 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10712 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10713 | null, mOnBatteryTimeBase, in); |
| 10714 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10715 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10716 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10717 | null, mOnBatteryTimeBase, in); |
| 10718 | } |
| 10719 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10720 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10721 | null, mOnBatteryTimeBase, in); |
| 10722 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10723 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10724 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10725 | NUM_WIFI_TX_LEVELS, in); |
| 10726 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10727 | NUM_BT_TX_LEVELS, in); |
| 10728 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10729 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 10730 | mHasWifiReporting = in.readInt() != 0; |
| 10731 | mHasBluetoothReporting = in.readInt() != 0; |
| 10732 | mHasModemReporting = in.readInt() != 0; |
| 10733 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10734 | mNumConnectivityChange = in.readInt(); |
| 10735 | mLoadedNumConnectivityChange = in.readInt(); |
| 10736 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10737 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10738 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10739 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10740 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10741 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10742 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10743 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10744 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10745 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10746 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10747 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10748 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10749 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10750 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10751 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10752 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10753 | mDischargeAmountScreenOn = in.readInt(); |
| 10754 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10755 | mDischargeAmountScreenOff = in.readInt(); |
| 10756 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10757 | mDischargeStepTracker.readFromParcel(in); |
| 10758 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10759 | mLastWriteTime = in.readLong(); |
| 10760 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10761 | mKernelWakelockStats.clear(); |
| 10762 | int NKW = in.readInt(); |
| 10763 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10764 | if (in.readInt() != 0) { |
| 10765 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10766 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10767 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 10768 | } |
| 10769 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10770 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10771 | mWakeupReasonStats.clear(); |
| 10772 | int NWR = in.readInt(); |
| 10773 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10774 | if (in.readInt() != 0) { |
| 10775 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10776 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10777 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10778 | } |
| 10779 | } |
| 10780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10781 | mPartialTimers.clear(); |
| 10782 | mFullTimers.clear(); |
| 10783 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10784 | mWifiRunningTimers.clear(); |
| 10785 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10786 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10787 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10788 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10789 | mAudioTurnedOnTimers.clear(); |
| 10790 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10791 | mFlashlightTurnedOnTimers.clear(); |
| 10792 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10793 | |
| 10794 | int numUids = in.readInt(); |
| 10795 | mUidStats.clear(); |
| 10796 | for (int i = 0; i < numUids; i++) { |
| 10797 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10798 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10799 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10800 | mUidStats.append(uid, u); |
| 10801 | } |
| 10802 | } |
| 10803 | |
| 10804 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10805 | writeToParcelLocked(out, true, flags); |
| 10806 | } |
| 10807 | |
| 10808 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 10809 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10810 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10811 | |
| 10812 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10813 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10814 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10815 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10816 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10817 | // Pull the clock time. This may update the time and make a new history entry |
| 10818 | // if we had originally pulled a time before the RTC was set. |
| 10819 | long startClockTime = getStartClockTime(); |
| 10820 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10821 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 10822 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10823 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 10824 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10826 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10827 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10828 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10830 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10831 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10832 | out.writeString(mStartPlatformVersion); |
| 10833 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10834 | out.writeLong(mUptime); |
| 10835 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10836 | out.writeLong(mRealtime); |
| 10837 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10838 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10839 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10840 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10841 | |
| 10842 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 10843 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10844 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 10845 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10846 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10847 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10848 | out.writeLong(mLongestLightIdleTime); |
| 10849 | out.writeLong(mLongestFullIdleTime); |
| 10850 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 10851 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 10852 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10853 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10854 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 10855 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10856 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10857 | } |
| 10858 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 10859 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10860 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 10861 | } |
| 10862 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10863 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 10864 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 10865 | } |
| 10866 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 10867 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10868 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10869 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 10870 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 10871 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 10872 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 10873 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10874 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 10875 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10876 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10877 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 10878 | } |
| 10879 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10880 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10881 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10882 | mWifiActivity.writeToParcel(out, 0); |
| 10883 | mBluetoothActivity.writeToParcel(out, 0); |
| 10884 | mModemActivity.writeToParcel(out, 0); |
| 10885 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 10886 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 10887 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 10888 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10889 | out.writeInt(mNumConnectivityChange); |
| 10890 | out.writeInt(mLoadedNumConnectivityChange); |
| 10891 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10892 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10893 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10894 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10895 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10896 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10897 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10898 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10899 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 10900 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10901 | out.writeInt(mDischargeAmountScreenOn); |
| 10902 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 10903 | out.writeInt(mDischargeAmountScreenOff); |
| 10904 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10905 | mDischargeStepTracker.writeToParcel(out); |
| 10906 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10907 | out.writeLong(mLastWriteTime); |
| 10908 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10909 | if (inclUids) { |
| 10910 | out.writeInt(mKernelWakelockStats.size()); |
| 10911 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10912 | SamplingTimer kwlt = ent.getValue(); |
| 10913 | if (kwlt != null) { |
| 10914 | out.writeInt(1); |
| 10915 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10916 | kwlt.writeToParcel(out, uSecRealtime); |
| 10917 | } else { |
| 10918 | out.writeInt(0); |
| 10919 | } |
| 10920 | } |
| 10921 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10922 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10923 | SamplingTimer timer = ent.getValue(); |
| 10924 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10925 | out.writeInt(1); |
| 10926 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10927 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10928 | } else { |
| 10929 | out.writeInt(0); |
| 10930 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10931 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10932 | } else { |
| 10933 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10934 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10935 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10936 | if (inclUids) { |
| 10937 | int size = mUidStats.size(); |
| 10938 | out.writeInt(size); |
| 10939 | for (int i = 0; i < size; i++) { |
| 10940 | out.writeInt(mUidStats.keyAt(i)); |
| 10941 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10943 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10944 | } |
| 10945 | } else { |
| 10946 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10947 | } |
| 10948 | } |
| 10949 | |
| 10950 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 10951 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 10952 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 10953 | return new BatteryStatsImpl(in); |
| 10954 | } |
| 10955 | |
| 10956 | public BatteryStatsImpl[] newArray(int size) { |
| 10957 | return new BatteryStatsImpl[size]; |
| 10958 | } |
| 10959 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10960 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10961 | public void prepareForDumpLocked() { |
| 10962 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10963 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10964 | |
| 10965 | // Pull the clock time. This may update the time and make a new history entry |
| 10966 | // if we had originally pulled a time before the RTC was set. |
| 10967 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10968 | } |
| 10969 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 10970 | 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] | 10971 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10972 | pw.println("mOnBatteryTimeBase:"); |
| 10973 | mOnBatteryTimeBase.dump(pw, " "); |
| 10974 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 10975 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10976 | Printer pr = new PrintWriterPrinter(pw); |
| 10977 | pr.println("*** Screen timer:"); |
| 10978 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10979 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10980 | pr.println("*** Screen brightness #" + i + ":"); |
| 10981 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10982 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10983 | pr.println("*** Interactive timer:"); |
| 10984 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10985 | pr.println("*** Power save mode timer:"); |
| 10986 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10987 | pr.println("*** Device idle mode light timer:"); |
| 10988 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 10989 | pr.println("*** Device idle mode full timer:"); |
| 10990 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 10991 | pr.println("*** Device light idling timer:"); |
| 10992 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10993 | pr.println("*** Device idling timer:"); |
| 10994 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10995 | pr.println("*** Phone timer:"); |
| 10996 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10997 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10998 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10999 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11000 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11001 | pr.println("*** Signal scanning :"); |
| 11002 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11003 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11004 | pr.println("*** Data connection type #" + i + ":"); |
| 11005 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11006 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11007 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11008 | pr.println("*** Mobile network active timer:"); |
| 11009 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11010 | pr.println("*** Mobile network active adjusted timer:"); |
| 11011 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11012 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11013 | pr.println("*** Wifi timer:"); |
| 11014 | mWifiOnTimer.logState(pr, " "); |
| 11015 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11016 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11017 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11018 | pr.println("*** Wifi state #" + i + ":"); |
| 11019 | mWifiStateTimer[i].logState(pr, " "); |
| 11020 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11021 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11022 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 11023 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 11024 | } |
| 11025 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11026 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 11027 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 11028 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11029 | pr.println("*** Flashlight timer:"); |
| 11030 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11031 | pr.println("*** Camera timer:"); |
| 11032 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11033 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11034 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11036 | } |