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; |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothDevice; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothHeadset; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 26 | import android.net.ConnectivityManager; |
| 27 | import android.net.NetworkStats; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 29 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 30 | import android.os.BadParcelableException; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 31 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 33 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 34 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 35 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 36 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 37 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.Parcel; |
| 39 | import android.os.ParcelFormatException; |
| 40 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 41 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 43 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 44 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 45 | import android.telephony.DataConnectionRealTimeInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 46 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 47 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 48 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 49 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 50 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 52 | import android.util.LogWriter; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 53 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 54 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 56 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 58 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 59 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 60 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 61 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 62 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 84 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 86 | import java.util.Iterator; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 87 | import java.util.List; |
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 | */ |
| 97 | public final class BatteryStatsImpl extends BatteryStats { |
| 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 | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 100 | private static final boolean DEBUG_ENERGY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 101 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 102 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 103 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 104 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | // 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] | 107 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
| 109 | // Current on-disk Parcel version |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 110 | private static final int VERSION = 123 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 111 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 112 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 113 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 114 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 115 | // No, really, THIS is the maximum number of items we will record in the history. |
| 116 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 117 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 118 | // The maximum number of names wakelocks we will keep track of |
| 119 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 120 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 121 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 122 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 123 | private static int sNumSpeedSteps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 125 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 126 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 127 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 129 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 130 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 131 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 132 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 133 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 134 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 135 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 136 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 137 | public interface BatteryCallback { |
| 138 | public void batteryNeedsCpuUpdate(); |
| 139 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 140 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 144 | public MyHandler(Looper looper) { |
| 145 | super(looper, null, true); |
| 146 | } |
| 147 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 148 | @Override |
| 149 | public void handleMessage(Message msg) { |
| 150 | BatteryCallback cb = mCallback; |
| 151 | switch (msg.what) { |
| 152 | case MSG_UPDATE_WAKELOCKS: |
| 153 | if (cb != null) { |
| 154 | cb.batteryNeedsCpuUpdate(); |
| 155 | } |
| 156 | break; |
| 157 | case MSG_REPORT_POWER_CHANGE: |
| 158 | if (cb != null) { |
| 159 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 160 | } |
| 161 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 162 | case MSG_REPORT_CHARGING: |
| 163 | if (cb != null) { |
| 164 | final String action; |
| 165 | synchronized (BatteryStatsImpl.this) { |
| 166 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 167 | : BatteryManager.ACTION_DISCHARGING; |
| 168 | } |
| 169 | Intent intent = new Intent(action); |
| 170 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 171 | cb.batterySendBroadcast(intent); |
| 172 | } |
| 173 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 178 | public interface ExternalStatsSync { |
| 179 | void scheduleSync(); |
| 180 | } |
| 181 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 182 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 183 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 184 | |
| 185 | private BatteryCallback mCallback; |
| 186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 188 | * Mapping isolated uids to the actual owning app uid. |
| 189 | */ |
| 190 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 191 | |
| 192 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | * The statistics we have collected organized by uids. |
| 194 | */ |
| 195 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 196 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 197 | |
| 198 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 199 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 200 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 201 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 202 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 203 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 204 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
| 205 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 206 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 207 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 208 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 209 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 210 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 211 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 212 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 214 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 215 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | // These are the objects that will want to do something when the device |
| 218 | // is unplugged from power. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 219 | final TimeBase mOnBatteryTimeBase = new TimeBase(); |
| 220 | |
| 221 | // These are the objects that will want to do something when the device |
| 222 | // is unplugged from power *and* the screen is off. |
| 223 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 224 | |
| 225 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 226 | // CPU update, even if we aren't currently running wake locks. |
| 227 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 228 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 229 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 230 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 231 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 232 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 233 | long mHistoryBaseTime; |
| 234 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 235 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 236 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 238 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 239 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 240 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 241 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 242 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 243 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 244 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 245 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 246 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 247 | int[] mReadHistoryUids; |
| 248 | int mReadHistoryChars; |
| 249 | int mNextHistoryTagIdx = 0; |
| 250 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 251 | int mHistoryBufferLastPos = -1; |
| 252 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 253 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 254 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 255 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 256 | |
| 257 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 258 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 259 | HistoryItem mHistory; |
| 260 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 261 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 262 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 263 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 264 | // Used by computeHistoryStepDetails |
| 265 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 266 | byte mLastHistoryStepLevel = 0; |
| 267 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 268 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 269 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
| 270 | /** |
| 271 | * Total time (in 1/100 sec) spent executing in user code. |
| 272 | */ |
| 273 | long mLastStepCpuUserTime; |
| 274 | long mCurStepCpuUserTime; |
| 275 | /** |
| 276 | * Total time (in 1/100 sec) spent executing in kernel code. |
| 277 | */ |
| 278 | long mLastStepCpuSystemTime; |
| 279 | long mCurStepCpuSystemTime; |
| 280 | /** |
| 281 | * Times from /proc/stat |
| 282 | */ |
| 283 | long mLastStepStatUserTime; |
| 284 | long mLastStepStatSystemTime; |
| 285 | long mLastStepStatIOWaitTime; |
| 286 | long mLastStepStatIrqTime; |
| 287 | long mLastStepStatSoftIrqTime; |
| 288 | long mLastStepStatIdleTime; |
| 289 | long mCurStepStatUserTime; |
| 290 | long mCurStepStatSystemTime; |
| 291 | long mCurStepStatIOWaitTime; |
| 292 | long mCurStepStatIrqTime; |
| 293 | long mCurStepStatSoftIrqTime; |
| 294 | long mCurStepStatIdleTime; |
| 295 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 296 | private HistoryItem mHistoryIterator; |
| 297 | private boolean mReadOverflow; |
| 298 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | int mStartCount; |
| 301 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 302 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 303 | String mStartPlatformVersion; |
| 304 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 305 | |
Dianne Hackborn | a7d0d55 | 2014-09-12 17:15:52 -0700 | [diff] [blame] | 306 | long mLastRecordedClockTime; |
| 307 | long mLastRecordedClockRealtime; |
| 308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | long mUptime; |
| 310 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | long mRealtime; |
| 312 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 313 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 314 | int mWakeLockNesting; |
| 315 | boolean mWakeLockImportant; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 316 | boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 317 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 318 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 319 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 320 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 321 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 322 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 323 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 324 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 325 | boolean mInteractive; |
| 326 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 327 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 328 | boolean mPowerSaveModeEnabled; |
| 329 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 330 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 331 | boolean mDeviceIdling; |
| 332 | StopwatchTimer mDeviceIdlingTimer; |
| 333 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 334 | boolean mDeviceIdleModeEnabled; |
| 335 | StopwatchTimer mDeviceIdleModeEnabledTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 338 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 339 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 340 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 341 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 343 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 344 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 345 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 346 | boolean mFlashlightOn; |
| 347 | StopwatchTimer mFlashlightOnTimer; |
| 348 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 349 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 350 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 351 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 352 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 353 | |
| 354 | StopwatchTimer mPhoneSignalScanningTimer; |
| 355 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 356 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 357 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 358 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 359 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 360 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 361 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 362 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 363 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 364 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 365 | final LongSamplingCounter[] mBluetoothActivityCounters = |
| 366 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 367 | |
| 368 | final LongSamplingCounter[] mWifiActivityCounters = |
| 369 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 370 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 371 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 372 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 373 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 374 | boolean mGlobalWifiRunning; |
| 375 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 376 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 377 | int mWifiState = -1; |
| 378 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 379 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 380 | int mWifiSupplState = -1; |
| 381 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 382 | |
| 383 | int mWifiSignalStrengthBin = -1; |
| 384 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 385 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 386 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 387 | boolean mBluetoothOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 388 | StopwatchTimer mBluetoothOnTimer; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 389 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 390 | int mBluetoothState = -1; |
| 391 | final StopwatchTimer[] mBluetoothStateTimer = new StopwatchTimer[NUM_BLUETOOTH_STATES]; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 392 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 393 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 394 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 395 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 396 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 397 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 398 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 399 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 400 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 401 | /** Bluetooth headset object */ |
| 402 | BluetoothHeadset mBtHeadset; |
| 403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | /** |
| 405 | * These provide time bases that discount the time the device is plugged |
| 406 | * in to power. |
| 407 | */ |
| 408 | boolean mOnBattery; |
| 409 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 410 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 411 | /** |
| 412 | * External reporting of whether the device is actually charging. |
| 413 | */ |
| 414 | boolean mCharging = true; |
| 415 | int mLastChargingStateLevel; |
| 416 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 417 | /* |
| 418 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 419 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 420 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 421 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 422 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 423 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 424 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 425 | int mLowDischargeAmountSinceCharge; |
| 426 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 427 | int mDischargeScreenOnUnplugLevel; |
| 428 | int mDischargeScreenOffUnplugLevel; |
| 429 | int mDischargeAmountScreenOn; |
| 430 | int mDischargeAmountScreenOnSinceCharge; |
| 431 | int mDischargeAmountScreenOff; |
| 432 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 433 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 434 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 435 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 436 | int mInitStepMode = 0; |
| 437 | int mCurStepMode = 0; |
| 438 | int mModStepMode = 0; |
| 439 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 440 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 441 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 442 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 443 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 444 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 445 | |
| 446 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 447 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 448 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 449 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 450 | |
| 451 | static final int MAX_DAILY_ITEMS = 10; |
| 452 | |
| 453 | long mDailyStartTime = 0; |
| 454 | long mNextMinDailyDeadline = 0; |
| 455 | long mNextMaxDailyDeadline = 0; |
| 456 | |
| 457 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 460 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 461 | private int mBluetoothPingCount; |
| 462 | private int mBluetoothPingStart = -1; |
| 463 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 464 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 465 | private int mPhoneServiceStateRaw = -1; |
| 466 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 467 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 468 | private int mNumConnectivityChange; |
| 469 | private int mLoadedNumConnectivityChange; |
| 470 | private int mUnpluggedNumConnectivityChange; |
| 471 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 472 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 473 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 474 | private PowerProfile mPowerProfile; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 475 | private boolean mHasWifiEnergyReporting = false; |
| 476 | private boolean mHasBluetoothEnergyReporting = false; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 477 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 478 | /* |
| 479 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 480 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 481 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 482 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 483 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 484 | return mKernelWakelockStats; |
| 485 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 486 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 487 | String mLastWakeupReason = null; |
| 488 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 489 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 490 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 491 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 492 | return mWakeupReasonStats; |
| 493 | } |
| 494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 496 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 497 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 498 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 499 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 500 | mExternalSync = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 501 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 504 | public static interface TimeBaseObs { |
| 505 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 506 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 507 | } |
| 508 | |
| 509 | static class TimeBase { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 510 | private final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 511 | |
| 512 | private long mUptime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 513 | private long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 514 | |
| 515 | private boolean mRunning; |
| 516 | |
| 517 | private long mPastUptime; |
| 518 | private long mUptimeStart; |
| 519 | private long mPastRealtime; |
| 520 | private long mRealtimeStart; |
| 521 | private long mUnpluggedUptime; |
| 522 | private long mUnpluggedRealtime; |
| 523 | |
| 524 | public void dump(PrintWriter pw, String prefix) { |
| 525 | StringBuilder sb = new StringBuilder(128); |
| 526 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 527 | sb.setLength(0); |
| 528 | sb.append(prefix); |
| 529 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 530 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 531 | pw.println(sb.toString()); |
| 532 | sb.setLength(0); |
| 533 | sb.append(prefix); |
| 534 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 535 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 536 | pw.println(sb.toString()); |
| 537 | sb.setLength(0); |
| 538 | sb.append(prefix); |
| 539 | sb.append("mPastUptime="); |
| 540 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 541 | formatTimeMs(sb, mUptimeStart / 1000); |
| 542 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 543 | pw.println(sb.toString()); |
| 544 | sb.setLength(0); |
| 545 | sb.append(prefix); |
| 546 | sb.append("mPastRealtime="); |
| 547 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 548 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 549 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 550 | pw.println(sb.toString()); |
| 551 | } |
| 552 | |
| 553 | public void add(TimeBaseObs observer) { |
| 554 | mObservers.add(observer); |
| 555 | } |
| 556 | |
| 557 | public void remove(TimeBaseObs observer) { |
| 558 | if (!mObservers.remove(observer)) { |
| 559 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | public void init(long uptime, long realtime) { |
| 564 | mRealtime = 0; |
| 565 | mUptime = 0; |
| 566 | mPastUptime = 0; |
| 567 | mPastRealtime = 0; |
| 568 | mUptimeStart = uptime; |
| 569 | mRealtimeStart = realtime; |
| 570 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 571 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 572 | } |
| 573 | |
| 574 | public void reset(long uptime, long realtime) { |
| 575 | if (!mRunning) { |
| 576 | mPastUptime = 0; |
| 577 | mPastRealtime = 0; |
| 578 | } else { |
| 579 | mUptimeStart = uptime; |
| 580 | mRealtimeStart = realtime; |
| 581 | mUnpluggedUptime = getUptime(uptime); |
| 582 | mUnpluggedRealtime = getRealtime(realtime); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | public long computeUptime(long curTime, int which) { |
| 587 | switch (which) { |
| 588 | case STATS_SINCE_CHARGED: |
| 589 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 590 | case STATS_CURRENT: |
| 591 | return getUptime(curTime); |
| 592 | case STATS_SINCE_UNPLUGGED: |
| 593 | return getUptime(curTime) - mUnpluggedUptime; |
| 594 | } |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | public long computeRealtime(long curTime, int which) { |
| 599 | switch (which) { |
| 600 | case STATS_SINCE_CHARGED: |
| 601 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 602 | case STATS_CURRENT: |
| 603 | return getRealtime(curTime); |
| 604 | case STATS_SINCE_UNPLUGGED: |
| 605 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 606 | } |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | public long getUptime(long curTime) { |
| 611 | long time = mPastUptime; |
| 612 | if (mRunning) { |
| 613 | time += curTime - mUptimeStart; |
| 614 | } |
| 615 | return time; |
| 616 | } |
| 617 | |
| 618 | public long getRealtime(long curTime) { |
| 619 | long time = mPastRealtime; |
| 620 | if (mRunning) { |
| 621 | time += curTime - mRealtimeStart; |
| 622 | } |
| 623 | return time; |
| 624 | } |
| 625 | |
| 626 | public long getUptimeStart() { |
| 627 | return mUptimeStart; |
| 628 | } |
| 629 | |
| 630 | public long getRealtimeStart() { |
| 631 | return mRealtimeStart; |
| 632 | } |
| 633 | |
| 634 | public boolean isRunning() { |
| 635 | return mRunning; |
| 636 | } |
| 637 | |
| 638 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 639 | if (mRunning != running) { |
| 640 | mRunning = running; |
| 641 | if (running) { |
| 642 | mUptimeStart = uptime; |
| 643 | mRealtimeStart = realtime; |
| 644 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 645 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 646 | |
| 647 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 648 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 649 | } |
| 650 | } else { |
| 651 | mPastUptime += uptime - mUptimeStart; |
| 652 | mPastRealtime += realtime - mRealtimeStart; |
| 653 | |
| 654 | long batteryUptime = getUptime(uptime); |
| 655 | long batteryRealtime = getRealtime(realtime); |
| 656 | |
| 657 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 658 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 659 | } |
| 660 | } |
| 661 | return true; |
| 662 | } |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | public void readSummaryFromParcel(Parcel in) { |
| 667 | mUptime = in.readLong(); |
| 668 | mRealtime = in.readLong(); |
| 669 | } |
| 670 | |
| 671 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 672 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 673 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 674 | } |
| 675 | |
| 676 | public void readFromParcel(Parcel in) { |
| 677 | mRunning = false; |
| 678 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 679 | mPastUptime = in.readLong(); |
| 680 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 681 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 682 | mPastRealtime = in.readLong(); |
| 683 | mRealtimeStart = in.readLong(); |
| 684 | mUnpluggedUptime = in.readLong(); |
| 685 | mUnpluggedRealtime = in.readLong(); |
| 686 | } |
| 687 | |
| 688 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 689 | final long runningUptime = getUptime(uptime); |
| 690 | final long runningRealtime = getRealtime(realtime); |
| 691 | out.writeLong(mUptime); |
| 692 | out.writeLong(runningUptime); |
| 693 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 694 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 695 | out.writeLong(runningRealtime); |
| 696 | out.writeLong(mRealtimeStart); |
| 697 | out.writeLong(mUnpluggedUptime); |
| 698 | out.writeLong(mUnpluggedRealtime); |
| 699 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 703 | * State for keeping track of counting information. |
| 704 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 705 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 706 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 707 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 708 | int mLoadedCount; |
| 709 | int mLastCount; |
| 710 | int mUnpluggedCount; |
| 711 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 712 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 713 | Counter(TimeBase timeBase, Parcel in) { |
| 714 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 715 | mPluggedCount = in.readInt(); |
| 716 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 717 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 718 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 719 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 720 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 723 | Counter(TimeBase timeBase) { |
| 724 | mTimeBase = timeBase; |
| 725 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 726 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 727 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 728 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 729 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 730 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 731 | out.writeInt(mUnpluggedCount); |
| 732 | } |
| 733 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 734 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 735 | mUnpluggedCount = mPluggedCount; |
| 736 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 739 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 740 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 741 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 742 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 743 | /** |
| 744 | * Writes a possibly null Counter to a Parcel. |
| 745 | * |
| 746 | * @param out the Parcel to be written to. |
| 747 | * @param counter a Counter, or null. |
| 748 | */ |
| 749 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 750 | if (counter == null) { |
| 751 | out.writeInt(0); // indicates null |
| 752 | return; |
| 753 | } |
| 754 | out.writeInt(1); // indicates non-null |
| 755 | |
| 756 | counter.writeToParcel(out); |
| 757 | } |
| 758 | |
| 759 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 760 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 761 | int val = mCount.get(); |
| 762 | if (which == STATS_SINCE_UNPLUGGED) { |
| 763 | val -= mUnpluggedCount; |
| 764 | } else if (which != STATS_SINCE_CHARGED) { |
| 765 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | return val; |
| 769 | } |
| 770 | |
| 771 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 772 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 773 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 774 | + " mUnpluggedCount=" + mUnpluggedCount |
| 775 | + " mPluggedCount=" + mPluggedCount); |
| 776 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 777 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 778 | void stepAtomic() { |
| 779 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 782 | /** |
| 783 | * Clear state of this counter. |
| 784 | */ |
| 785 | void reset(boolean detachIfReset) { |
| 786 | mCount.set(0); |
| 787 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 788 | if (detachIfReset) { |
| 789 | detach(); |
| 790 | } |
| 791 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 792 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 793 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 794 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 795 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 796 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 797 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 798 | int count = mCount.get(); |
| 799 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 803 | mLoadedCount = in.readInt(); |
| 804 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 805 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 806 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 809 | |
| 810 | public static class SamplingCounter extends Counter { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 811 | SamplingCounter(TimeBase timeBase, Parcel in) { |
| 812 | super(timeBase, in); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 815 | SamplingCounter(TimeBase timeBase) { |
| 816 | super(timeBase); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 819 | public void addCountAtomic(long count) { |
| 820 | mCount.addAndGet((int)count); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 824 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 825 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 826 | long mCount; |
| 827 | long mLoadedCount; |
| 828 | long mLastCount; |
| 829 | long mUnpluggedCount; |
| 830 | long mPluggedCount; |
| 831 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 832 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 833 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 834 | mPluggedCount = in.readLong(); |
| 835 | mCount = mPluggedCount; |
| 836 | mLoadedCount = in.readLong(); |
| 837 | mLastCount = 0; |
| 838 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 839 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 842 | LongSamplingCounter(TimeBase timeBase) { |
| 843 | mTimeBase = timeBase; |
| 844 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | public void writeToParcel(Parcel out) { |
| 848 | out.writeLong(mCount); |
| 849 | out.writeLong(mLoadedCount); |
| 850 | out.writeLong(mUnpluggedCount); |
| 851 | } |
| 852 | |
| 853 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 854 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 855 | mUnpluggedCount = mPluggedCount; |
| 856 | mCount = mPluggedCount; |
| 857 | } |
| 858 | |
| 859 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 860 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 861 | mPluggedCount = mCount; |
| 862 | } |
| 863 | |
| 864 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 865 | long val = mCount; |
| 866 | if (which == STATS_SINCE_UNPLUGGED) { |
| 867 | val -= mUnpluggedCount; |
| 868 | } else if (which != STATS_SINCE_CHARGED) { |
| 869 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | return val; |
| 873 | } |
| 874 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 875 | @Override |
| 876 | public void logState(Printer pw, String prefix) { |
| 877 | pw.println(prefix + "mCount=" + mCount |
| 878 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 879 | + " mUnpluggedCount=" + mUnpluggedCount |
| 880 | + " mPluggedCount=" + mPluggedCount); |
| 881 | } |
| 882 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 883 | void addCountLocked(long count) { |
| 884 | mCount += count; |
| 885 | } |
| 886 | |
| 887 | /** |
| 888 | * Clear state of this counter. |
| 889 | */ |
| 890 | void reset(boolean detachIfReset) { |
| 891 | mCount = 0; |
| 892 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 893 | if (detachIfReset) { |
| 894 | detach(); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 899 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void writeSummaryFromParcelLocked(Parcel out) { |
| 903 | out.writeLong(mCount); |
| 904 | } |
| 905 | |
| 906 | void readSummaryFromParcelLocked(Parcel in) { |
| 907 | mLoadedCount = in.readLong(); |
| 908 | mCount = mLoadedCount; |
| 909 | mLastCount = 0; |
| 910 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 911 | } |
| 912 | } |
| 913 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 914 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | * State for keeping track of timing information. |
| 916 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 917 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | final int mType; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 919 | final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | int mCount; |
| 922 | int mLoadedCount; |
| 923 | int mLastCount; |
| 924 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | // Times are in microseconds for better accuracy when dividing by the |
| 927 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | /** |
| 930 | * The total time we have accumulated since the start of the original |
| 931 | * boot, to the last time something interesting happened in the |
| 932 | * current run. |
| 933 | */ |
| 934 | long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | /** |
| 937 | * The total time we loaded for the previous runs. Subtract this from |
| 938 | * mTotalTime to find the time for the current run of the system. |
| 939 | */ |
| 940 | long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | /** |
| 943 | * The run time of the last run of the system, as loaded from the |
| 944 | * saved data. |
| 945 | */ |
| 946 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | /** |
| 949 | * The value of mTotalTime when unplug() was last called. Subtract |
| 950 | * this from mTotalTime to find the time since the last unplug from |
| 951 | * power. |
| 952 | */ |
| 953 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 954 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 955 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 956 | * The total time this timer has been running until the latest mark has been set. |
| 957 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 958 | */ |
| 959 | long mTimeBeforeMark; |
| 960 | |
| 961 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 962 | * Constructs from a parcel. |
| 963 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 964 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 965 | * @param in |
| 966 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 967 | Timer(int type, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 969 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | mCount = in.readInt(); |
| 972 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 973 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | mUnpluggedCount = in.readInt(); |
| 975 | mTotalTime = in.readLong(); |
| 976 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 977 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 979 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 980 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 981 | 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] | 982 | } |
| 983 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 984 | Timer(int type, TimeBase timeBase) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 986 | mTimeBase = timeBase; |
| 987 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 989 | |
| 990 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 991 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 992 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 993 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 994 | /** |
| 995 | * Clear state of this timer. Returns true if the timer is inactive |
| 996 | * so can be completely dropped. |
| 997 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 998 | boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 999 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1000 | mCount = mLoadedCount = mLastCount = 0; |
| 1001 | if (detachIfReset) { |
| 1002 | detach(); |
| 1003 | } |
| 1004 | return true; |
| 1005 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1006 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1007 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1008 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1009 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1010 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1011 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1012 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1013 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | out.writeInt(mCount); |
| 1015 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1017 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1020 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1023 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1024 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1026 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1028 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1029 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1030 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | mUnpluggedCount = mCount; |
| 1032 | if (DEBUG && mType < 0) { |
| 1033 | Log.v(TAG, "unplug #" + mType |
| 1034 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1035 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1036 | } |
| 1037 | } |
| 1038 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1039 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1040 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1041 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1042 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1043 | + " old mTotalTime=" + mTotalTime); |
| 1044 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1045 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1046 | mCount = computeCurrentCountLocked(); |
| 1047 | if (DEBUG && mType < 0) { |
| 1048 | Log.v(TAG, "plug #" + mType |
| 1049 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | } |
| 1051 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | /** |
| 1054 | * Writes a possibly null Timer to a Parcel. |
| 1055 | * |
| 1056 | * @param out the Parcel to be written to. |
| 1057 | * @param timer a Timer, or null. |
| 1058 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1059 | 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] | 1060 | if (timer == null) { |
| 1061 | out.writeInt(0); // indicates null |
| 1062 | return; |
| 1063 | } |
| 1064 | out.writeInt(1); // indicates non-null |
| 1065 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1066 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1070 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1071 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1072 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1073 | val -= mUnpluggedTime; |
| 1074 | } else if (which != STATS_SINCE_CHARGED) { |
| 1075 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | return val; |
| 1079 | } |
| 1080 | |
| 1081 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1082 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1083 | int val = computeCurrentCountLocked(); |
| 1084 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1085 | val -= mUnpluggedCount; |
| 1086 | } else if (which != STATS_SINCE_CHARGED) { |
| 1087 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | return val; |
| 1091 | } |
| 1092 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1093 | @Override |
| 1094 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1095 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1096 | return val - mTimeBeforeMark; |
| 1097 | } |
| 1098 | |
| 1099 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1100 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1101 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1103 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1104 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1106 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1108 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1109 | |
| 1110 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1111 | void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1112 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1113 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1114 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | void readSummaryFromParcelLocked(Parcel in) { |
| 1118 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1119 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1120 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1121 | mUnpluggedTime = mTotalTime; |
| 1122 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1123 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1124 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1125 | |
| 1126 | // When reading the summary, we set the mark to be the latest information. |
| 1127 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1130 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1131 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1132 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1133 | /** |
| 1134 | * The most recent reported count from /proc/wakelocks. |
| 1135 | */ |
| 1136 | int mCurrentReportedCount; |
| 1137 | |
| 1138 | /** |
| 1139 | * The reported count from /proc/wakelocks when unplug() was last |
| 1140 | * called. |
| 1141 | */ |
| 1142 | int mUnpluggedReportedCount; |
| 1143 | |
| 1144 | /** |
| 1145 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1146 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1147 | long mCurrentReportedTotalTime; |
| 1148 | |
| 1149 | |
| 1150 | /** |
| 1151 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1152 | * called. |
| 1153 | */ |
| 1154 | long mUnpluggedReportedTotalTime; |
| 1155 | |
| 1156 | /** |
| 1157 | * Whether we are currently in a discharge cycle. |
| 1158 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1159 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1160 | |
| 1161 | /** |
| 1162 | * Whether we are currently recording reported values. |
| 1163 | */ |
| 1164 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1165 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1166 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1167 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1168 | */ |
| 1169 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1170 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1171 | SamplingTimer(TimeBase timeBase, Parcel in) { |
| 1172 | super(0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1173 | mCurrentReportedCount = in.readInt(); |
| 1174 | mUnpluggedReportedCount = in.readInt(); |
| 1175 | mCurrentReportedTotalTime = in.readLong(); |
| 1176 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1177 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1178 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1179 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1180 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1181 | SamplingTimer(TimeBase timeBase, boolean trackReportedValues) { |
| 1182 | super(0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1183 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1184 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1185 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1186 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1187 | public void setStale() { |
| 1188 | mTrackingReportedValues = false; |
| 1189 | mUnpluggedReportedTotalTime = 0; |
| 1190 | mUnpluggedReportedCount = 0; |
| 1191 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1192 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1193 | public void setUpdateVersion(int version) { |
| 1194 | mUpdateVersion = version; |
| 1195 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1196 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1197 | public int getUpdateVersion() { |
| 1198 | return mUpdateVersion; |
| 1199 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1200 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1201 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1202 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1203 | // Updating the reported value for the first time. |
| 1204 | mUnpluggedReportedCount = count; |
| 1205 | // If we are receiving an update update mTrackingReportedValues; |
| 1206 | mTrackingReportedValues = true; |
| 1207 | } |
| 1208 | mCurrentReportedCount = count; |
| 1209 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1210 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1211 | public void addCurrentReportedCount(int delta) { |
| 1212 | updateCurrentReportedCount(mCurrentReportedCount + delta); |
| 1213 | } |
| 1214 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1215 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1216 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1217 | // Updating the reported value for the first time. |
| 1218 | mUnpluggedReportedTotalTime = totalTime; |
| 1219 | // If we are receiving an update update mTrackingReportedValues; |
| 1220 | mTrackingReportedValues = true; |
| 1221 | } |
| 1222 | mCurrentReportedTotalTime = totalTime; |
| 1223 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1224 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1225 | public void addCurrentReportedTotalTime(long delta) { |
| 1226 | updateCurrentReportedTotalTime(mCurrentReportedTotalTime + delta); |
| 1227 | } |
| 1228 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1229 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1230 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1231 | if (mTrackingReportedValues) { |
| 1232 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1233 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1234 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1235 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1238 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1239 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1240 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1241 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1242 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1243 | public void logState(Printer pw, String prefix) { |
| 1244 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1245 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1246 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1247 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1248 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1249 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1250 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1251 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1252 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1253 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1254 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1255 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1256 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1257 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1258 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1259 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1260 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1261 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1262 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1263 | out.writeInt(mCurrentReportedCount); |
| 1264 | out.writeInt(mUnpluggedReportedCount); |
| 1265 | out.writeLong(mCurrentReportedTotalTime); |
| 1266 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1267 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1268 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1269 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1270 | boolean reset(boolean detachIfReset) { |
| 1271 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1272 | setStale(); |
| 1273 | return true; |
| 1274 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1275 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1276 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 1277 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1278 | out.writeLong(mCurrentReportedTotalTime); |
| 1279 | out.writeInt(mCurrentReportedCount); |
| 1280 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1281 | } |
| 1282 | |
| 1283 | void readSummaryFromParcelLocked(Parcel in) { |
| 1284 | super.readSummaryFromParcelLocked(in); |
| 1285 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1286 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1287 | mTrackingReportedValues = in.readInt() == 1; |
| 1288 | } |
| 1289 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1290 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1291 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1292 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1293 | * for a pre-determined amount. |
| 1294 | */ |
| 1295 | public static final class BatchTimer extends Timer { |
| 1296 | final Uid mUid; |
| 1297 | |
| 1298 | /** |
| 1299 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1300 | */ |
| 1301 | long mLastAddedTime; |
| 1302 | |
| 1303 | /** |
| 1304 | * The last duration that we added to the timer. This is in microseconds. |
| 1305 | */ |
| 1306 | long mLastAddedDuration; |
| 1307 | |
| 1308 | /** |
| 1309 | * Whether we are currently in a discharge cycle. |
| 1310 | */ |
| 1311 | boolean mInDischarge; |
| 1312 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1313 | BatchTimer(Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1314 | super(type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1315 | mUid = uid; |
| 1316 | mLastAddedTime = in.readLong(); |
| 1317 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1318 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1321 | BatchTimer(Uid uid, int type, TimeBase timeBase) { |
| 1322 | super(type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1323 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1324 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1328 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1329 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1330 | out.writeLong(mLastAddedTime); |
| 1331 | out.writeLong(mLastAddedDuration); |
| 1332 | } |
| 1333 | |
| 1334 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1335 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1336 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 1337 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1338 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1342 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1343 | recomputeLastDuration(elapsedRealtime, false); |
| 1344 | mInDischarge = true; |
| 1345 | // If we are still within the last added duration, then re-added whatever remains. |
| 1346 | if (mLastAddedTime == elapsedRealtime) { |
| 1347 | mTotalTime += mLastAddedDuration; |
| 1348 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1349 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | @Override |
| 1353 | public void logState(Printer pw, String prefix) { |
| 1354 | super.logState(pw, prefix); |
| 1355 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1356 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1357 | } |
| 1358 | |
| 1359 | private long computeOverage(long curTime) { |
| 1360 | if (mLastAddedTime > 0) { |
| 1361 | return mLastTime + mLastAddedDuration - curTime; |
| 1362 | } |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1367 | final long overage = computeOverage(curTime); |
| 1368 | if (overage > 0) { |
| 1369 | // Aborting before the duration ran out -- roll back the remaining |
| 1370 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1371 | // actually add the time. |
| 1372 | if (mInDischarge) { |
| 1373 | mTotalTime -= overage; |
| 1374 | } |
| 1375 | if (abort) { |
| 1376 | mLastAddedTime = 0; |
| 1377 | } else { |
| 1378 | mLastAddedTime = curTime; |
| 1379 | mLastAddedDuration -= overage; |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1385 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1386 | recomputeLastDuration(now, true); |
| 1387 | mLastAddedTime = now; |
| 1388 | mLastAddedDuration = durationMillis * 1000; |
| 1389 | if (mInDischarge) { |
| 1390 | mTotalTime += mLastAddedDuration; |
| 1391 | mCount++; |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1396 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1397 | recomputeLastDuration(now, true); |
| 1398 | } |
| 1399 | |
| 1400 | @Override |
| 1401 | protected int computeCurrentCountLocked() { |
| 1402 | return mCount; |
| 1403 | } |
| 1404 | |
| 1405 | @Override |
| 1406 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1407 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1408 | if (overage > 0) { |
| 1409 | return mTotalTime = overage; |
| 1410 | } |
| 1411 | return mTotalTime; |
| 1412 | } |
| 1413 | |
| 1414 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1415 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1416 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1417 | recomputeLastDuration(now, true); |
| 1418 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1419 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1420 | return !stillActive; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1425 | * State for keeping track of timing information. |
| 1426 | */ |
| 1427 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1428 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1429 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1430 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1431 | int mNesting; |
| 1432 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1433 | /** |
| 1434 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1435 | * subtract this from the current battery time to find the amount of |
| 1436 | * time we have been running since we last computed an update. |
| 1437 | */ |
| 1438 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1439 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1440 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1441 | * 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] | 1442 | * was actually held for an interesting duration. |
| 1443 | */ |
| 1444 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1445 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1446 | long mTimeout; |
| 1447 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1448 | /** |
| 1449 | * For partial wake locks, keep track of whether we are in the list |
| 1450 | * to consume CPU cycles. |
| 1451 | */ |
| 1452 | boolean mInList; |
| 1453 | |
| 1454 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1455 | TimeBase timeBase, Parcel in) { |
| 1456 | super(type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1457 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1458 | mTimerPool = timerPool; |
| 1459 | mUpdateTime = in.readLong(); |
| 1460 | } |
| 1461 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1462 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1463 | TimeBase timeBase) { |
| 1464 | super(type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1465 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1466 | mTimerPool = timerPool; |
| 1467 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1468 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1469 | void setTimeout(long timeout) { |
| 1470 | mTimeout = timeout; |
| 1471 | } |
| 1472 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1473 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1474 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1475 | out.writeLong(mUpdateTime); |
| 1476 | } |
| 1477 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1478 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1479 | if (mNesting > 0) { |
| 1480 | if (DEBUG && mType < 0) { |
| 1481 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1482 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1483 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1484 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1485 | if (DEBUG && mType < 0) { |
| 1486 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | public void logState(Printer pw, String prefix) { |
| 1492 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1493 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | + " mAcquireTime=" + mAcquireTime); |
| 1495 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1496 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1497 | void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1499 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1500 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | if (mTimerPool != null) { |
| 1502 | // Accumulate time to all currently active timers before adding |
| 1503 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1504 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | // Add this timer to the active pool |
| 1506 | mTimerPool.add(this); |
| 1507 | } |
| 1508 | // Increment the count |
| 1509 | mCount++; |
| 1510 | mAcquireTime = mTotalTime; |
| 1511 | if (DEBUG && mType < 0) { |
| 1512 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1513 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1514 | + " mAcquireTime=" + mAcquireTime); |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1519 | boolean isRunningLocked() { |
| 1520 | return mNesting > 0; |
| 1521 | } |
| 1522 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1523 | void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | // Ignore attempt to stop a timer that isn't running |
| 1525 | if (mNesting == 0) { |
| 1526 | return; |
| 1527 | } |
| 1528 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1529 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | if (mTimerPool != null) { |
| 1531 | // Accumulate time to all active counters, scaled by the total |
| 1532 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1533 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | // Remove this timer from the active pool |
| 1535 | mTimerPool.remove(this); |
| 1536 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | mNesting = 1; |
| 1538 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1539 | mNesting = 0; |
| 1540 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | if (DEBUG && mType < 0) { |
| 1543 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1544 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1545 | + " mAcquireTime=" + mAcquireTime); |
| 1546 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | if (mTotalTime == mAcquireTime) { |
| 1549 | // If there was no change in the time, then discard this |
| 1550 | // count. A somewhat cheezy strategy, but hey. |
| 1551 | mCount--; |
| 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1556 | void stopAllRunningLocked(long elapsedRealtimeMs) { |
| 1557 | if (mNesting > 0) { |
| 1558 | mNesting = 1; |
| 1559 | stopRunningLocked(elapsedRealtimeMs); |
| 1560 | } |
| 1561 | } |
| 1562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | // Update the total time for all other running Timers with the same type as this Timer |
| 1564 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1565 | private static long refreshTimersLocked(long batteryRealtime, |
| 1566 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1567 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | final int N = pool.size(); |
| 1569 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1570 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1572 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1573 | final long myTime = heldTime / N; |
| 1574 | if (t == self) { |
| 1575 | selfTime = myTime; |
| 1576 | } |
| 1577 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | } |
| 1579 | t.mUpdateTime = batteryRealtime; |
| 1580 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1581 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1584 | @Override |
| 1585 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1586 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1587 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1588 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | return mTotalTime + (mNesting > 0 |
| 1590 | ? (curBatteryRealtime - mUpdateTime) |
| 1591 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1592 | : 0); |
| 1593 | } |
| 1594 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1595 | @Override |
| 1596 | protected int computeCurrentCountLocked() { |
| 1597 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | } |
| 1599 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1600 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1601 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1602 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1603 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1604 | if (mNesting > 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1605 | mUpdateTime = mTimeBase.getRealtime(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1606 | } |
| 1607 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1608 | return canDetach; |
| 1609 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1610 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1611 | @Override |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1612 | void detach() { |
| 1613 | super.detach(); |
| 1614 | if (mTimerPool != null) { |
| 1615 | mTimerPool.remove(this); |
| 1616 | } |
| 1617 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1618 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1619 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1621 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | mNesting = 0; |
| 1623 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1624 | |
| 1625 | /** |
| 1626 | * Set the mark so that we can query later for the total time the timer has |
| 1627 | * accumulated since this point. The timer can be running or not. |
| 1628 | * |
| 1629 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1630 | */ |
| 1631 | public void setMark(long elapsedRealtimeMs) { |
| 1632 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1633 | if (mNesting > 0) { |
| 1634 | // We are running. |
| 1635 | if (mTimerPool != null) { |
| 1636 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1637 | } else { |
| 1638 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1639 | mUpdateTime = batteryRealtime; |
| 1640 | } |
| 1641 | } |
| 1642 | mTimeBeforeMark = mTotalTime; |
| 1643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1645 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1646 | public abstract class OverflowArrayMap<T> { |
| 1647 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1648 | |
| 1649 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1650 | T mCurOverflow; |
| 1651 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1652 | |
| 1653 | public OverflowArrayMap() { |
| 1654 | } |
| 1655 | |
| 1656 | public ArrayMap<String, T> getMap() { |
| 1657 | return mMap; |
| 1658 | } |
| 1659 | |
| 1660 | public void clear() { |
| 1661 | mMap.clear(); |
| 1662 | mCurOverflow = null; |
| 1663 | mActiveOverflow = null; |
| 1664 | } |
| 1665 | |
| 1666 | public void add(String name, T obj) { |
| 1667 | mMap.put(name, obj); |
| 1668 | if (OVERFLOW_NAME.equals(name)) { |
| 1669 | mCurOverflow = obj; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | public void cleanup() { |
| 1674 | if (mActiveOverflow != null) { |
| 1675 | if (mActiveOverflow.size() == 0) { |
| 1676 | mActiveOverflow = null; |
| 1677 | } |
| 1678 | } |
| 1679 | if (mActiveOverflow == null) { |
| 1680 | // There is no currently active overflow, so we should no longer have |
| 1681 | // an overflow entry. |
| 1682 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1683 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1684 | + mMap.get(OVERFLOW_NAME)); |
| 1685 | mMap.remove(OVERFLOW_NAME); |
| 1686 | } |
| 1687 | mCurOverflow = null; |
| 1688 | } else { |
| 1689 | // There is currently active overflow, so we should still have an overflow entry. |
| 1690 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1691 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1692 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1693 | } |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | public T startObject(String name) { |
| 1698 | T obj = mMap.get(name); |
| 1699 | if (obj != null) { |
| 1700 | return obj; |
| 1701 | } |
| 1702 | |
| 1703 | // No object exists for the given name, but do we currently have it |
| 1704 | // running as part of the overflow? |
| 1705 | if (mActiveOverflow != null) { |
| 1706 | MutableInt over = mActiveOverflow.get(name); |
| 1707 | if (over != null) { |
| 1708 | // We are already actively counting this name in the overflow object. |
| 1709 | obj = mCurOverflow; |
| 1710 | if (obj == null) { |
| 1711 | // Shouldn't be here, but we'll try to recover. |
| 1712 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1713 | obj = mCurOverflow = instantiateObject(); |
| 1714 | mMap.put(OVERFLOW_NAME, obj); |
| 1715 | } |
| 1716 | over.value++; |
| 1717 | return obj; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | // No object exists for given name nor in the overflow; we need to make |
| 1722 | // a new one. |
| 1723 | final int N = mMap.size(); |
| 1724 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1725 | // Went over the limit on number of objects to track; this one goes |
| 1726 | // in to the overflow. |
| 1727 | obj = mCurOverflow; |
| 1728 | if (obj == null) { |
| 1729 | // Need to start overflow now... |
| 1730 | obj = mCurOverflow = instantiateObject(); |
| 1731 | mMap.put(OVERFLOW_NAME, obj); |
| 1732 | } |
| 1733 | if (mActiveOverflow == null) { |
| 1734 | mActiveOverflow = new ArrayMap<>(); |
| 1735 | } |
| 1736 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1737 | return obj; |
| 1738 | } |
| 1739 | |
| 1740 | // Normal case where we just need to make a new object. |
| 1741 | obj = instantiateObject(); |
| 1742 | mMap.put(name, obj); |
| 1743 | return obj; |
| 1744 | } |
| 1745 | |
| 1746 | public T stopObject(String name) { |
| 1747 | T obj = mMap.get(name); |
| 1748 | if (obj != null) { |
| 1749 | return obj; |
| 1750 | } |
| 1751 | |
| 1752 | // No object exists for the given name, but do we currently have it |
| 1753 | // running as part of the overflow? |
| 1754 | if (mActiveOverflow != null) { |
| 1755 | MutableInt over = mActiveOverflow.get(name); |
| 1756 | if (over != null) { |
| 1757 | // We are already actively counting this name in the overflow object. |
| 1758 | obj = mCurOverflow; |
| 1759 | if (obj != null) { |
| 1760 | over.value--; |
| 1761 | if (over.value <= 0) { |
| 1762 | mActiveOverflow.remove(name); |
| 1763 | } |
| 1764 | return obj; |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | // Huh, they are stopping an active operation but we can't find one! |
| 1770 | // That's not good. |
| 1771 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1772 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1773 | + " curoverflow=" + mCurOverflow); |
| 1774 | return null; |
| 1775 | } |
| 1776 | |
| 1777 | public abstract T instantiateObject(); |
| 1778 | } |
| 1779 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1780 | /* |
| 1781 | * Get the wakeup reason counter, and create a new one if one |
| 1782 | * doesn't already exist. |
| 1783 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1784 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 1785 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 1786 | if (timer == null) { |
| 1787 | timer = new SamplingTimer(mOnBatteryTimeBase, true); |
| 1788 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1789 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1790 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1793 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1794 | * 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] | 1795 | * doesn't already exist. |
| 1796 | */ |
| 1797 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1798 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1799 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1800 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1801 | mKernelWakelockStats.put(name, kwlt); |
| 1802 | } |
| 1803 | return kwlt; |
| 1804 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1805 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1806 | private int getCurrentBluetoothPingCount() { |
| 1807 | if (mBtHeadset != null) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1808 | List<BluetoothDevice> deviceList = mBtHeadset.getConnectedDevices(); |
| 1809 | if (deviceList.size() > 0) { |
| 1810 | return mBtHeadset.getBatteryUsageHint(deviceList.get(0)); |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 1811 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1812 | } |
| 1813 | return -1; |
| 1814 | } |
| 1815 | |
| 1816 | public int getBluetoothPingCount() { |
| 1817 | if (mBluetoothPingStart == -1) { |
| 1818 | return mBluetoothPingCount; |
| 1819 | } else if (mBtHeadset != null) { |
| 1820 | return getCurrentBluetoothPingCount() - mBluetoothPingStart; |
| 1821 | } |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1822 | return 0; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | public void setBtHeadset(BluetoothHeadset headset) { |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1826 | if (headset != null && mBtHeadset == null && isOnBattery() && mBluetoothPingStart == -1) { |
| 1827 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 1828 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1829 | mBtHeadset = headset; |
| 1830 | } |
| 1831 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1832 | private int writeHistoryTag(HistoryTag tag) { |
| 1833 | Integer idxObj = mHistoryTagPool.get(tag); |
| 1834 | int idx; |
| 1835 | if (idxObj != null) { |
| 1836 | idx = idxObj; |
| 1837 | } else { |
| 1838 | idx = mNextHistoryTagIdx; |
| 1839 | HistoryTag key = new HistoryTag(); |
| 1840 | key.setTo(tag); |
| 1841 | tag.poolIdx = idx; |
| 1842 | mHistoryTagPool.put(key, idx); |
| 1843 | mNextHistoryTagIdx++; |
| 1844 | mNumHistoryTagChars += key.string.length() + 1; |
| 1845 | } |
| 1846 | return idx; |
| 1847 | } |
| 1848 | |
| 1849 | private void readHistoryTag(int index, HistoryTag tag) { |
| 1850 | tag.string = mReadHistoryStrings[index]; |
| 1851 | tag.uid = mReadHistoryUids[index]; |
| 1852 | tag.poolIdx = index; |
| 1853 | } |
| 1854 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1855 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1856 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 1857 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 1858 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 1859 | 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] | 1860 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1861 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1862 | // 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] | 1863 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 1864 | // Flag in delta int: a new full state2 int follows. |
| 1865 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1866 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1867 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1868 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1869 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1870 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1871 | static final int DELTA_STATE_MASK = 0xff000000; |
| 1872 | |
| 1873 | // These are the pieces of battery state that are packed in to the upper bits of |
| 1874 | // the state int that have been packed in to the first delta int. They must fit |
| 1875 | // in DELTA_STATE_MASK. |
| 1876 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 1877 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 1878 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 1879 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 1880 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 1881 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1882 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1883 | // We use the low bit of the battery state int to indicate that we have full details |
| 1884 | // from a battery level change. |
| 1885 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 1886 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1887 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1888 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1889 | dest.writeInt(DELTA_TIME_ABS); |
| 1890 | cur.writeToParcel(dest, 0); |
| 1891 | return; |
| 1892 | } |
| 1893 | |
| 1894 | final long deltaTime = cur.time - last.time; |
| 1895 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 1896 | final int lastStateInt = buildStateInt(last); |
| 1897 | |
| 1898 | int deltaTimeToken; |
| 1899 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 1900 | deltaTimeToken = DELTA_TIME_LONG; |
| 1901 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 1902 | deltaTimeToken = DELTA_TIME_INT; |
| 1903 | } else { |
| 1904 | deltaTimeToken = (int)deltaTime; |
| 1905 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1906 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1907 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 1908 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 1909 | final boolean computeStepDetails = includeStepDetails != 0 |
| 1910 | || mLastHistoryStepDetails == null; |
| 1911 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1912 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 1913 | if (batteryLevelIntChanged) { |
| 1914 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 1915 | } |
| 1916 | final int stateInt = buildStateInt(cur); |
| 1917 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 1918 | if (stateIntChanged) { |
| 1919 | firstToken |= DELTA_STATE_FLAG; |
| 1920 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1921 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 1922 | if (state2IntChanged) { |
| 1923 | firstToken |= DELTA_STATE2_FLAG; |
| 1924 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1925 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1926 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 1927 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1928 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 1929 | firstToken |= DELTA_EVENT_FLAG; |
| 1930 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1931 | dest.writeInt(firstToken); |
| 1932 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1933 | + " deltaTime=" + deltaTime); |
| 1934 | |
| 1935 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 1936 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 1937 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 1938 | dest.writeInt((int)deltaTime); |
| 1939 | } else { |
| 1940 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 1941 | dest.writeLong(deltaTime); |
| 1942 | } |
| 1943 | } |
| 1944 | if (batteryLevelIntChanged) { |
| 1945 | dest.writeInt(batteryLevelInt); |
| 1946 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 1947 | + Integer.toHexString(batteryLevelInt) |
| 1948 | + " batteryLevel=" + cur.batteryLevel |
| 1949 | + " batteryTemp=" + cur.batteryTemperature |
| 1950 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1951 | } |
| 1952 | if (stateIntChanged) { |
| 1953 | dest.writeInt(stateInt); |
| 1954 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 1955 | + Integer.toHexString(stateInt) |
| 1956 | + " batteryStatus=" + cur.batteryStatus |
| 1957 | + " batteryHealth=" + cur.batteryHealth |
| 1958 | + " batteryPlugType=" + cur.batteryPlugType |
| 1959 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1960 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1961 | if (state2IntChanged) { |
| 1962 | dest.writeInt(cur.states2); |
| 1963 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 1964 | + Integer.toHexString(cur.states2)); |
| 1965 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1966 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 1967 | int wakeLockIndex; |
| 1968 | int wakeReasonIndex; |
| 1969 | if (cur.wakelockTag != null) { |
| 1970 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 1971 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1972 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1973 | } else { |
| 1974 | wakeLockIndex = 0xffff; |
| 1975 | } |
| 1976 | if (cur.wakeReasonTag != null) { |
| 1977 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 1978 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1979 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1980 | } else { |
| 1981 | wakeReasonIndex = 0xffff; |
| 1982 | } |
| 1983 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1984 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1985 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1986 | int index = writeHistoryTag(cur.eventTag); |
| 1987 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1988 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1989 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 1990 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 1991 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1992 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1993 | if (computeStepDetails) { |
| 1994 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 1995 | if (includeStepDetails != 0) { |
| 1996 | mCurHistoryStepDetails.writeToParcel(dest); |
| 1997 | } |
| 1998 | cur.stepDetails = mCurHistoryStepDetails; |
| 1999 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2000 | } else { |
| 2001 | cur.stepDetails = null; |
| 2002 | } |
| 2003 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2004 | mLastHistoryStepDetails = null; |
| 2005 | } |
| 2006 | mLastHistoryStepLevel = cur.batteryLevel; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2010 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2011 | | ((((int)h.batteryTemperature)<<14)&0x01ff8000) |
| 2012 | | ((((int)h.batteryVoltage)<<1)&0x00007fff); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2016 | int plugType = 0; |
| 2017 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2018 | plugType = 1; |
| 2019 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2020 | plugType = 2; |
| 2021 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2022 | plugType = 3; |
| 2023 | } |
| 2024 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2025 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2026 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2027 | | (h.states&(~DELTA_STATE_MASK)); |
| 2028 | } |
| 2029 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2030 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2031 | final HistoryStepDetails last) { |
| 2032 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2033 | |
| 2034 | // Perform a CPU update right after we do this collection, so we have started |
| 2035 | // collecting good data for the next step. |
| 2036 | requestImmediateCpuUpdate(); |
| 2037 | |
| 2038 | if (last == null) { |
| 2039 | // We are not generating a delta, so all we need to do is reset the stats |
| 2040 | // we will later be doing a delta from. |
| 2041 | final int NU = mUidStats.size(); |
| 2042 | for (int i=0; i<NU; i++) { |
| 2043 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2044 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2045 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2046 | } |
| 2047 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2048 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2049 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2050 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2051 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2052 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2053 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2054 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2055 | tmp.clear(); |
| 2056 | return; |
| 2057 | } |
| 2058 | if (DEBUG) { |
| 2059 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2060 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2061 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2062 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2063 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2064 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2065 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2066 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2067 | } |
| 2068 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2069 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2070 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2071 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2072 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2073 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2074 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2075 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2076 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2077 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2078 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2079 | final int NU = mUidStats.size(); |
| 2080 | for (int i=0; i<NU; i++) { |
| 2081 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2082 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2083 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2084 | final int totalTime = totalUTime + totalSTime; |
| 2085 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2086 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2087 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2088 | continue; |
| 2089 | } |
| 2090 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2091 | out.appCpuUid3 = uid.mUid; |
| 2092 | out.appCpuUTime3 = totalUTime; |
| 2093 | out.appCpuSTime3 = totalSTime; |
| 2094 | } else { |
| 2095 | out.appCpuUid3 = out.appCpuUid2; |
| 2096 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2097 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2098 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2099 | out.appCpuUid2 = uid.mUid; |
| 2100 | out.appCpuUTime2 = totalUTime; |
| 2101 | out.appCpuSTime2 = totalSTime; |
| 2102 | } else { |
| 2103 | out.appCpuUid2 = out.appCpuUid1; |
| 2104 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2105 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2106 | out.appCpuUid1 = uid.mUid; |
| 2107 | out.appCpuUTime1 = totalUTime; |
| 2108 | out.appCpuSTime1 = totalSTime; |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2113 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2114 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2115 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2116 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2117 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2118 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2119 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2120 | } |
| 2121 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2122 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2123 | int firstToken = src.readInt(); |
| 2124 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2125 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2126 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2127 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2128 | + " deltaTimeToken=" + deltaTimeToken); |
| 2129 | |
| 2130 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2131 | cur.time += deltaTimeToken; |
| 2132 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2133 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2134 | cur.numReadInts += 2; |
| 2135 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2136 | cur.readFromParcel(src); |
| 2137 | return; |
| 2138 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2139 | int delta = src.readInt(); |
| 2140 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2141 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2142 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2143 | } else { |
| 2144 | long delta = src.readLong(); |
| 2145 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2146 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2147 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2150 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2151 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2152 | batteryLevelInt = src.readInt(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2153 | cur.batteryLevel = (byte)((batteryLevelInt>>25)&0x7f); |
| 2154 | cur.batteryTemperature = (short)((batteryLevelInt<<7)>>21); |
| 2155 | cur.batteryVoltage = (char)(batteryLevelInt&0x3fff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2156 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2157 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2158 | + Integer.toHexString(batteryLevelInt) |
| 2159 | + " batteryLevel=" + cur.batteryLevel |
| 2160 | + " batteryTemp=" + cur.batteryTemperature |
| 2161 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2162 | } else { |
| 2163 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2167 | int stateInt = src.readInt(); |
| 2168 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2169 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2170 | & STATE_BATTERY_STATUS_MASK); |
| 2171 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2172 | & STATE_BATTERY_HEALTH_MASK); |
| 2173 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2174 | & STATE_BATTERY_PLUG_MASK); |
| 2175 | switch (cur.batteryPlugType) { |
| 2176 | case 1: |
| 2177 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2178 | break; |
| 2179 | case 2: |
| 2180 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2181 | break; |
| 2182 | case 3: |
| 2183 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2184 | break; |
| 2185 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2186 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2187 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2188 | + Integer.toHexString(stateInt) |
| 2189 | + " batteryStatus=" + cur.batteryStatus |
| 2190 | + " batteryHealth=" + cur.batteryHealth |
| 2191 | + " batteryPlugType=" + cur.batteryPlugType |
| 2192 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2193 | } else { |
| 2194 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 2195 | } |
| 2196 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2197 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2198 | cur.states2 = src.readInt(); |
| 2199 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2200 | + Integer.toHexString(cur.states2)); |
| 2201 | } |
| 2202 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2203 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2204 | int indexes = src.readInt(); |
| 2205 | int wakeLockIndex = indexes&0xffff; |
| 2206 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2207 | if (wakeLockIndex != 0xffff) { |
| 2208 | cur.wakelockTag = cur.localWakelockTag; |
| 2209 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2210 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2211 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2212 | } else { |
| 2213 | cur.wakelockTag = null; |
| 2214 | } |
| 2215 | if (wakeReasonIndex != 0xffff) { |
| 2216 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2217 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2218 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2219 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2220 | } else { |
| 2221 | cur.wakeReasonTag = null; |
| 2222 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2223 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2224 | } else { |
| 2225 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2226 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2227 | } |
| 2228 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2229 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2230 | cur.eventTag = cur.localEventTag; |
| 2231 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2232 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2233 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2234 | readHistoryTag(index, cur.eventTag); |
| 2235 | cur.numReadInts += 1; |
| 2236 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2237 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2238 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2239 | } else { |
| 2240 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2241 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2242 | |
| 2243 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2244 | cur.stepDetails = mReadHistoryStepDetails; |
| 2245 | cur.stepDetails.readFromParcel(src); |
| 2246 | } else { |
| 2247 | cur.stepDetails = null; |
| 2248 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2249 | } |
| 2250 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2251 | @Override |
| 2252 | public void commitCurrentHistoryBatchLocked() { |
| 2253 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2254 | } |
| 2255 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2256 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2257 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2258 | return; |
| 2259 | } |
| 2260 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2261 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2262 | final int diffStates = mHistoryLastWritten.states^cur.states; |
| 2263 | final int diffStates2 = mHistoryLastWritten.states2^cur.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2264 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2265 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2266 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2267 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2268 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2269 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2270 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2271 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2272 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2273 | && (diffStates2&lastDiffStates2) == 0 |
| 2274 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2275 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2276 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2277 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2278 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2279 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2280 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2281 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2282 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2283 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2284 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2285 | // 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] | 2286 | // 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] | 2287 | // as long as no bit has changed both between now and the last entry, as |
| 2288 | // well as the last entry and the one before it (so we capture any toggles). |
| 2289 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2290 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2291 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2292 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2293 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2294 | // If the last written history had a wakelock tag, we need to retain it. |
| 2295 | // Note that the condition above made sure that we aren't in a case where |
| 2296 | // both it and the current history item have a wakelock tag. |
| 2297 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2298 | cur.wakelockTag = cur.localWakelockTag; |
| 2299 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2300 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2301 | // If the last written history had a wake reason tag, we need to retain it. |
| 2302 | // Note that the condition above made sure that we aren't in a case where |
| 2303 | // both it and the current history item have a wakelock tag. |
| 2304 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2305 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2306 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2307 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2308 | // If the last written history had an event, we need to retain it. |
| 2309 | // Note that the condition above made sure that we aren't in a case where |
| 2310 | // both it and the current history item have an event. |
| 2311 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2312 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2313 | cur.eventTag = cur.localEventTag; |
| 2314 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2315 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2316 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2320 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2321 | if (!mHistoryOverflow) { |
| 2322 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2323 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2324 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2325 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | // Once we've reached the maximum number of items, we only |
| 2329 | // record changes to the battery level and the most interesting states. |
| 2330 | // Once we've reached the maximum maximum number of items, we only |
| 2331 | // record changes to the battery level. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2332 | if (mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2333 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2334 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2335 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2336 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2337 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2338 | return; |
| 2339 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2340 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2341 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2342 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2345 | if (dataSize == 0) { |
| 2346 | // The history is currently empty; we need it to start with a time stamp. |
| 2347 | cur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | a7d0d55 | 2014-09-12 17:15:52 -0700 | [diff] [blame] | 2348 | mLastRecordedClockTime = cur.currentTime; |
| 2349 | mLastRecordedClockRealtime = elapsedRealtimeMs; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2350 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2351 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2352 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2355 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2356 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2357 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2358 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2359 | } |
| 2360 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2361 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2362 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2363 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2364 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2365 | cur.wakelockTag = null; |
| 2366 | cur.wakeReasonTag = null; |
| 2367 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2368 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2369 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2370 | + " now " + mHistoryBuffer.dataPosition() |
| 2371 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2374 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2375 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2376 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2377 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2378 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2379 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2380 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2381 | if (diffUptime < (diffElapsed-20)) { |
| 2382 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2383 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2384 | mHistoryAddTmp.wakelockTag = null; |
| 2385 | mHistoryAddTmp.wakeReasonTag = null; |
| 2386 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2387 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2388 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2389 | } |
| 2390 | } |
| 2391 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2392 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2393 | mTrackRunningHistoryUptime = uptimeMs; |
| 2394 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2395 | } |
| 2396 | |
| 2397 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2398 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2399 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2400 | if (!USE_OLD_HISTORY) { |
| 2401 | return; |
| 2402 | } |
| 2403 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2404 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2405 | return; |
| 2406 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2407 | |
| 2408 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2409 | // and no states have since the last recorded entry changed and |
| 2410 | // are now resetting back to their original value, then just collapse |
| 2411 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2412 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2413 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2414 | && ((mHistoryEnd.states^cur.states)&mChangedStates) == 0 |
| 2415 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2416 | // If the current is the same as the one before, then we no |
| 2417 | // longer need the entry. |
| 2418 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2419 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2420 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2421 | mHistoryLastEnd.next = null; |
| 2422 | mHistoryEnd.next = mHistoryCache; |
| 2423 | mHistoryCache = mHistoryEnd; |
| 2424 | mHistoryEnd = mHistoryLastEnd; |
| 2425 | mHistoryLastEnd = null; |
| 2426 | } else { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2427 | mChangedStates |= mHistoryEnd.states^cur.states; |
| 2428 | mChangedStates2 |= mHistoryEnd.states^cur.states2; |
| 2429 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2430 | } |
| 2431 | return; |
| 2432 | } |
| 2433 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2434 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2435 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2436 | |
| 2437 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2438 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2439 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2442 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2443 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2444 | // record changes to the battery level and the most interesting states. |
| 2445 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2446 | // record changes to the battery level. |
| 2447 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2448 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2449 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2450 | || ((mHistoryEnd.states^cur.states) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2451 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2452 | return; |
| 2453 | } |
| 2454 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2455 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2456 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2457 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2458 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2459 | void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
| 2460 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2461 | mHistoryCur.eventCode = code; |
| 2462 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2463 | mHistoryCur.eventTag.string = name; |
| 2464 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2465 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2466 | } |
| 2467 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2468 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2469 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2470 | if (rec != null) { |
| 2471 | mHistoryCache = rec.next; |
| 2472 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2473 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2474 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2475 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2476 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2477 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2478 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2479 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2480 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2481 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2482 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2483 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2484 | if (mHistoryEnd != null) { |
| 2485 | mHistoryEnd.next = rec; |
| 2486 | mHistoryEnd = rec; |
| 2487 | } else { |
| 2488 | mHistory = mHistoryEnd = rec; |
| 2489 | } |
| 2490 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2491 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2492 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2493 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2494 | if (USE_OLD_HISTORY) { |
| 2495 | if (mHistory != null) { |
| 2496 | mHistoryEnd.next = mHistoryCache; |
| 2497 | mHistoryCache = mHistory; |
| 2498 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2499 | } |
| 2500 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2501 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2502 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2503 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2504 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2505 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2506 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2507 | |
| 2508 | mHistoryBuffer.setDataSize(0); |
| 2509 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2510 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2511 | mHistoryLastLastWritten.clear(); |
| 2512 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2513 | mHistoryTagPool.clear(); |
| 2514 | mNextHistoryTagIdx = 0; |
| 2515 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2516 | mHistoryBufferLastPos = -1; |
| 2517 | mHistoryOverflow = false; |
Dianne Hackborn | a7d0d55 | 2014-09-12 17:15:52 -0700 | [diff] [blame] | 2518 | mLastRecordedClockTime = 0; |
| 2519 | mLastRecordedClockRealtime = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2520 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2521 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2522 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2523 | long realtime) { |
| 2524 | if (mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime)) { |
| 2525 | if (unplugged) { |
| 2526 | // Track bt headset ping count |
| 2527 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 2528 | mBluetoothPingCount = 0; |
| 2529 | } else { |
| 2530 | // Track bt headset ping count |
| 2531 | mBluetoothPingCount = getBluetoothPingCount(); |
| 2532 | mBluetoothPingStart = -1; |
| 2533 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2535 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2536 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2537 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2538 | updateKernelWakelocksLocked(); |
| 2539 | requestWakelockCpuUpdate(); |
| 2540 | if (!unpluggedScreenOff) { |
| 2541 | // We are switching to no longer tracking wake locks, but we want |
| 2542 | // the next CPU update we receive to take them in to account. |
| 2543 | mDistributeWakelockCpu = true; |
| 2544 | } |
| 2545 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | } |
| 2547 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2548 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2549 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2550 | mIsolatedUids.put(isolatedUid, appUid); |
| 2551 | } |
| 2552 | |
| 2553 | public void removeIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2554 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2555 | if (curUid == appUid) { |
| 2556 | mIsolatedUids.delete(isolatedUid); |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | public int mapUid(int uid) { |
| 2561 | int isolated = mIsolatedUids.get(uid, -1); |
| 2562 | return isolated > 0 ? isolated : uid; |
| 2563 | } |
| 2564 | |
| 2565 | public void noteEventLocked(int code, String name, int uid) { |
| 2566 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2567 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2568 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2569 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2570 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2571 | final long uptime = SystemClock.uptimeMillis(); |
| 2572 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2573 | } |
| 2574 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2575 | public void noteCurrentTimeChangedLocked() { |
| 2576 | final long currentTime = System.currentTimeMillis(); |
| 2577 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2578 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | a7d0d55 | 2014-09-12 17:15:52 -0700 | [diff] [blame] | 2579 | if (isStartClockTimeValid()) { |
| 2580 | // Has the time changed sufficiently that it is really worth recording? |
| 2581 | if (mLastRecordedClockTime != 0) { |
| 2582 | long expectedClockTime = mLastRecordedClockTime |
| 2583 | + (elapsedRealtime - mLastRecordedClockRealtime); |
| 2584 | if (currentTime >= (expectedClockTime-500) |
| 2585 | && currentTime <= (expectedClockTime+500)) { |
| 2586 | // Not sufficiently changed, skip! |
| 2587 | return; |
| 2588 | } |
| 2589 | } |
| 2590 | } |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2591 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
| 2592 | if (isStartClockTimeValid()) { |
| 2593 | mStartClockTime = currentTime; |
| 2594 | } |
| 2595 | } |
| 2596 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2597 | public void noteProcessStartLocked(String name, int uid) { |
| 2598 | uid = mapUid(uid); |
| 2599 | if (isOnBattery()) { |
| 2600 | Uid u = getUidStatsLocked(uid); |
| 2601 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2602 | } |
| 2603 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2604 | return; |
| 2605 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2606 | if (!mRecordAllHistory) { |
| 2607 | return; |
| 2608 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2609 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2610 | final long uptime = SystemClock.uptimeMillis(); |
| 2611 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2612 | } |
| 2613 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2614 | public void noteProcessCrashLocked(String name, int uid) { |
| 2615 | uid = mapUid(uid); |
| 2616 | if (isOnBattery()) { |
| 2617 | Uid u = getUidStatsLocked(uid); |
| 2618 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | public void noteProcessAnrLocked(String name, int uid) { |
| 2623 | uid = mapUid(uid); |
| 2624 | if (isOnBattery()) { |
| 2625 | Uid u = getUidStatsLocked(uid); |
| 2626 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2627 | } |
| 2628 | } |
| 2629 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2630 | public void noteProcessStateLocked(String name, int uid, int state) { |
| 2631 | uid = mapUid(uid); |
| 2632 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2633 | getUidStatsLocked(uid).updateProcessStateLocked(name, state, elapsedRealtime); |
| 2634 | } |
| 2635 | |
| 2636 | public void noteProcessFinishLocked(String name, int uid) { |
| 2637 | uid = mapUid(uid); |
| 2638 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2639 | return; |
| 2640 | } |
| 2641 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2642 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2643 | getUidStatsLocked(uid).updateProcessStateLocked(name, Uid.PROCESS_STATE_NONE, |
| 2644 | elapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2645 | if (!mRecordAllHistory) { |
| 2646 | return; |
| 2647 | } |
| 2648 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2651 | public void noteSyncStartLocked(String name, int uid) { |
| 2652 | uid = mapUid(uid); |
| 2653 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2654 | final long uptime = SystemClock.uptimeMillis(); |
| 2655 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2656 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2657 | return; |
| 2658 | } |
| 2659 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2660 | } |
| 2661 | |
| 2662 | public void noteSyncFinishLocked(String name, int uid) { |
| 2663 | uid = mapUid(uid); |
| 2664 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2665 | final long uptime = SystemClock.uptimeMillis(); |
| 2666 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2667 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2668 | return; |
| 2669 | } |
| 2670 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2671 | } |
| 2672 | |
| 2673 | public void noteJobStartLocked(String name, int uid) { |
| 2674 | uid = mapUid(uid); |
| 2675 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2676 | final long uptime = SystemClock.uptimeMillis(); |
| 2677 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2678 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2679 | return; |
| 2680 | } |
| 2681 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2682 | } |
| 2683 | |
| 2684 | public void noteJobFinishLocked(String name, int uid) { |
| 2685 | uid = mapUid(uid); |
| 2686 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2687 | final long uptime = SystemClock.uptimeMillis(); |
| 2688 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2689 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2690 | return; |
| 2691 | } |
| 2692 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2693 | } |
| 2694 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame^] | 2695 | public void noteAlarmStartLocked(String name, int uid) { |
| 2696 | if (!mRecordAllHistory) { |
| 2697 | return; |
| 2698 | } |
| 2699 | uid = mapUid(uid); |
| 2700 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2701 | final long uptime = SystemClock.uptimeMillis(); |
| 2702 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 2703 | return; |
| 2704 | } |
| 2705 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 2706 | } |
| 2707 | |
| 2708 | public void noteAlarmFinishLocked(String name, int uid) { |
| 2709 | if (!mRecordAllHistory) { |
| 2710 | return; |
| 2711 | } |
| 2712 | uid = mapUid(uid); |
| 2713 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2714 | final long uptime = SystemClock.uptimeMillis(); |
| 2715 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 2716 | return; |
| 2717 | } |
| 2718 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 2719 | } |
| 2720 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2721 | private void requestWakelockCpuUpdate() { |
| 2722 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2723 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2724 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2725 | } |
| 2726 | } |
| 2727 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2728 | private void requestImmediateCpuUpdate() { |
| 2729 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2730 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 2731 | } |
| 2732 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2733 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 2734 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2735 | if (!enabled) { |
| 2736 | // Clear out any existing state. |
| 2737 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame^] | 2738 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2739 | // Record the currently running processes as stopping, now that we are no |
| 2740 | // longer tracking them. |
| 2741 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2742 | HistoryItem.EVENT_PROC); |
| 2743 | if (active != null) { |
| 2744 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2745 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2746 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2747 | SparseIntArray uids = ent.getValue(); |
| 2748 | for (int j=0; j<uids.size(); j++) { |
| 2749 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2750 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 2751 | } |
| 2752 | } |
| 2753 | } |
| 2754 | } else { |
| 2755 | // Record the currently running processes as starting, now that we are tracking them. |
| 2756 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2757 | HistoryItem.EVENT_PROC); |
| 2758 | if (active != null) { |
| 2759 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2760 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2761 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2762 | SparseIntArray uids = ent.getValue(); |
| 2763 | for (int j=0; j<uids.size(); j++) { |
| 2764 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2765 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 2766 | } |
| 2767 | } |
| 2768 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2772 | public void setNoAutoReset(boolean enabled) { |
| 2773 | mNoAutoReset = enabled; |
| 2774 | } |
| 2775 | |
| 2776 | private String mInitialAcquireWakeName; |
| 2777 | private int mInitialAcquireWakeUid = -1; |
| 2778 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2779 | 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] | 2780 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2781 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2782 | if (type == WAKE_TYPE_PARTIAL) { |
| 2783 | // Only care about partial wake locks, since full wake locks |
| 2784 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2785 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2786 | if (historyName == null) { |
| 2787 | historyName = name; |
| 2788 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2789 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2790 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 2791 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2792 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2793 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2794 | } |
| 2795 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2796 | if (mWakeLockNesting == 0) { |
| 2797 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2798 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 2799 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2800 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2801 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2802 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2803 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2804 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2805 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 2806 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2807 | if (mHistoryLastWritten.wakelockTag != null) { |
| 2808 | // We'll try to update the last tag. |
| 2809 | mHistoryLastWritten.wakelockTag = null; |
| 2810 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2811 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2812 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2813 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2814 | } |
| 2815 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2816 | } |
| 2817 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2818 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2819 | if (uid >= 0) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2820 | //if (uid == 0) { |
| 2821 | // Slog.wtf(TAG, "Acquiring wake lock from root: " + name); |
| 2822 | //} |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2823 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2824 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2825 | } |
| 2826 | } |
| 2827 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2828 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 2829 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2830 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2831 | if (type == WAKE_TYPE_PARTIAL) { |
| 2832 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2833 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2834 | if (historyName == null) { |
| 2835 | historyName = name; |
| 2836 | } |
| 2837 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 2838 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2839 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2840 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2841 | } |
| 2842 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2843 | if (mWakeLockNesting == 0) { |
| 2844 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2845 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 2846 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2847 | mInitialAcquireWakeName = null; |
| 2848 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2849 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2850 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2851 | } |
| 2852 | if (uid >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2853 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2854 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2855 | } |
| 2856 | } |
| 2857 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2858 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2859 | String historyName, int type, boolean unimportantForLogging) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2860 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2861 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2862 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2863 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2864 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2865 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2869 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 2870 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2871 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
| 2872 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2873 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2874 | // For correct semantics, we start the need worksources first, so that we won't |
| 2875 | // make inappropriate history items as if all wake locks went away and new ones |
| 2876 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2877 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2878 | for (int i=0; i<NN; i++) { |
| 2879 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2880 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2881 | } |
| 2882 | final int NO = ws.size(); |
| 2883 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2884 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2885 | } |
| 2886 | } |
| 2887 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2888 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2889 | String historyName, int type) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2890 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2891 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2892 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2893 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2894 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2895 | } |
| 2896 | } |
| 2897 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2898 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 2899 | if (mLastWakeupReason != null) { |
| 2900 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2901 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
| 2902 | timer.addCurrentReportedCount(1); |
| 2903 | timer.addCurrentReportedTotalTime(deltaUptime * 1000); // time is in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2904 | mLastWakeupReason = null; |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | public void noteWakeupReasonLocked(String reason) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2909 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2910 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2911 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2912 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2913 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2914 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 2915 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2916 | mHistoryCur.wakeReasonTag.uid = 0; |
| 2917 | mLastWakeupReason = reason; |
| 2918 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2919 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2920 | } |
| 2921 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2922 | public int startAddingCpuLocked() { |
| 2923 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2924 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2925 | if (!mOnBatteryInternal) { |
| 2926 | return -1; |
| 2927 | } |
| 2928 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2929 | final int N = mPartialTimers.size(); |
| 2930 | if (N == 0) { |
| 2931 | mLastPartialTimers.clear(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2932 | mDistributeWakelockCpu = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2933 | return 0; |
| 2934 | } |
| 2935 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2936 | if (!mOnBatteryScreenOffTimeBase.isRunning() && !mDistributeWakelockCpu) { |
| 2937 | return 0; |
| 2938 | } |
| 2939 | |
| 2940 | mDistributeWakelockCpu = false; |
| 2941 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2942 | // How many timers should consume CPU? Only want to include ones |
| 2943 | // that have already been in the list. |
| 2944 | for (int i=0; i<N; i++) { |
| 2945 | StopwatchTimer st = mPartialTimers.get(i); |
| 2946 | if (st.mInList) { |
| 2947 | Uid uid = st.mUid; |
| 2948 | // We don't include the system UID, because it so often |
| 2949 | // holds wake locks at one request or another of an app. |
| 2950 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2951 | return 50; |
| 2952 | } |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | return 0; |
| 2957 | } |
| 2958 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2959 | public void finishAddingCpuLocked(int perc, int remainUTime, int remainSTtime, |
| 2960 | int totalUTime, int totalSTime, int statUserTime, int statSystemTime, |
| 2961 | int statIOWaitTime, int statIrqTime, int statSoftIrqTime, int statIdleTime, |
| 2962 | long[] cpuSpeedTimes) { |
| 2963 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 2964 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 2965 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 2966 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 2967 | mCurStepCpuUserTime += totalUTime; |
| 2968 | mCurStepCpuSystemTime += totalSTime; |
| 2969 | mCurStepStatUserTime += statUserTime; |
| 2970 | mCurStepStatSystemTime += statSystemTime; |
| 2971 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 2972 | mCurStepStatIrqTime += statIrqTime; |
| 2973 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 2974 | mCurStepStatIdleTime += statIdleTime; |
| 2975 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2976 | final int N = mPartialTimers.size(); |
| 2977 | if (perc != 0) { |
| 2978 | int num = 0; |
| 2979 | for (int i=0; i<N; i++) { |
| 2980 | StopwatchTimer st = mPartialTimers.get(i); |
| 2981 | if (st.mInList) { |
| 2982 | Uid uid = st.mUid; |
| 2983 | // We don't include the system UID, because it so often |
| 2984 | // holds wake locks at one request or another of an app. |
| 2985 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2986 | num++; |
| 2987 | } |
| 2988 | } |
| 2989 | } |
| 2990 | if (num != 0) { |
| 2991 | for (int i=0; i<N; i++) { |
| 2992 | StopwatchTimer st = mPartialTimers.get(i); |
| 2993 | if (st.mInList) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2994 | Uid uid = st.mUid; |
| 2995 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2996 | int myUTime = remainUTime/num; |
| 2997 | int mySTime = remainSTtime/num; |
| 2998 | remainUTime -= myUTime; |
| 2999 | remainSTtime -= mySTime; |
Dianne Hackborn | 618b8c1 | 2010-09-09 23:10:38 -0700 | [diff] [blame] | 3000 | num--; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3001 | Uid.Proc proc = uid.getProcessStatsLocked("*wakelock*"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3002 | proc.addCpuTimeLocked(myUTime, mySTime, cpuSpeedTimes); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | // Just in case, collect any lost CPU time. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3009 | if (remainUTime != 0 || remainSTtime != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3010 | Uid uid = getUidStatsLocked(Process.SYSTEM_UID); |
| 3011 | if (uid != null) { |
| 3012 | Uid.Proc proc = uid.getProcessStatsLocked("*lost*"); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3013 | proc.addCpuTimeLocked(remainUTime, remainSTtime, cpuSpeedTimes); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3014 | } |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | final int NL = mLastPartialTimers.size(); |
| 3019 | boolean diff = N != NL; |
| 3020 | for (int i=0; i<NL && !diff; i++) { |
| 3021 | diff |= mPartialTimers.get(i) != mLastPartialTimers.get(i); |
| 3022 | } |
| 3023 | if (!diff) { |
| 3024 | for (int i=0; i<NL; i++) { |
| 3025 | mPartialTimers.get(i).mInList = true; |
| 3026 | } |
| 3027 | return; |
| 3028 | } |
| 3029 | |
| 3030 | for (int i=0; i<NL; i++) { |
| 3031 | mLastPartialTimers.get(i).mInList = false; |
| 3032 | } |
| 3033 | mLastPartialTimers.clear(); |
| 3034 | for (int i=0; i<N; i++) { |
| 3035 | StopwatchTimer st = mPartialTimers.get(i); |
| 3036 | st.mInList = true; |
| 3037 | mLastPartialTimers.add(st); |
| 3038 | } |
| 3039 | } |
| 3040 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3041 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3042 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3043 | Uid u = mUidStats.get(uid); |
| 3044 | if (u != null) { |
| 3045 | u.mPids.remove(pid); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3050 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3051 | Uid u = mUidStats.get(uid); |
| 3052 | if (u != null) { |
| 3053 | Uid.Pid p = u.mPids.get(pid); |
| 3054 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3055 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | return 0; |
| 3059 | } |
| 3060 | |
| 3061 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3062 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3063 | Uid u = mUidStats.get(uid); |
| 3064 | if (u != null) { |
| 3065 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3066 | } |
| 3067 | } |
| 3068 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3069 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3070 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3071 | Uid u = mUidStats.get(uid); |
| 3072 | if (u != null) { |
| 3073 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3074 | } |
| 3075 | } |
| 3076 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3077 | int mSensorNesting; |
| 3078 | |
| 3079 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3080 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3081 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3082 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3083 | if (mSensorNesting == 0) { |
| 3084 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3085 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3086 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3087 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3088 | } |
| 3089 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3090 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3094 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3095 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3096 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3097 | mSensorNesting--; |
| 3098 | if (mSensorNesting == 0) { |
| 3099 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3100 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3101 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3102 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3103 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3104 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3107 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3108 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3109 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3110 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3111 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3112 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3113 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3114 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3115 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3116 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3117 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3118 | } |
| 3119 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3120 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3122 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3123 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3124 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3125 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3126 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3127 | mGpsNesting--; |
| 3128 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3129 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3130 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3131 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3132 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3133 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3134 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3136 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3137 | public void noteScreenStateLocked(int state) { |
| 3138 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3139 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3140 | final int oldState = mScreenState; |
| 3141 | mScreenState = state; |
| 3142 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3143 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3144 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3145 | if (state != Display.STATE_UNKNOWN) { |
| 3146 | int stepState = state-1; |
| 3147 | if (stepState < 4) { |
| 3148 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3149 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3150 | } else { |
| 3151 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3152 | } |
| 3153 | } |
| 3154 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3155 | if (state == Display.STATE_ON) { |
| 3156 | // Screen turning on. |
| 3157 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3158 | final long uptime = SystemClock.uptimeMillis(); |
| 3159 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3160 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3161 | + Integer.toHexString(mHistoryCur.states)); |
| 3162 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3163 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3164 | if (mScreenBrightnessBin >= 0) { |
| 3165 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3166 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3167 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3168 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
| 3169 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3170 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3171 | // Fake a wake lock, so we consider the device waked as long |
| 3172 | // as the screen is on. |
| 3173 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3174 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3175 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3176 | // Update discharge amounts. |
| 3177 | if (mOnBatteryInternal) { |
| 3178 | updateDischargeScreenLevelsLocked(false, true); |
| 3179 | } |
| 3180 | } else if (oldState == Display.STATE_ON) { |
| 3181 | // Screen turning off or dozing. |
| 3182 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3183 | final long uptime = SystemClock.uptimeMillis(); |
| 3184 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3185 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3186 | + Integer.toHexString(mHistoryCur.states)); |
| 3187 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3188 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3189 | if (mScreenBrightnessBin >= 0) { |
| 3190 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3191 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3192 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3193 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3194 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3195 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3196 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
| 3197 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3198 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3199 | // Update discharge amounts. |
| 3200 | if (mOnBatteryInternal) { |
| 3201 | updateDischargeScreenLevelsLocked(true, false); |
| 3202 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3203 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3204 | } |
| 3205 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3206 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3207 | public void noteScreenBrightnessLocked(int brightness) { |
| 3208 | // Bin the brightness. |
| 3209 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3210 | if (bin < 0) bin = 0; |
| 3211 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3212 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3213 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3214 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3215 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3216 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3217 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3218 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3219 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3220 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3221 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3222 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3223 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3224 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3225 | } |
| 3226 | mScreenBrightnessBin = bin; |
| 3227 | } |
| 3228 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3229 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3230 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3231 | if (mOnBatteryInternal) { |
| 3232 | uid = mapUid(uid); |
| 3233 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3236 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3237 | public void noteInteractiveLocked(boolean interactive) { |
| 3238 | if (mInteractive != interactive) { |
| 3239 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3240 | mInteractive = interactive; |
| 3241 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3242 | if (interactive) { |
| 3243 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3244 | } else { |
| 3245 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3250 | public void noteConnectivityChangedLocked(int type, String extra) { |
| 3251 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3252 | final long uptime = SystemClock.uptimeMillis(); |
| 3253 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3254 | extra, type); |
| 3255 | mNumConnectivityChange++; |
| 3256 | } |
| 3257 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3258 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
| 3259 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3260 | final long uptime = SystemClock.uptimeMillis(); |
| 3261 | if (mMobileRadioPowerState != powerState) { |
| 3262 | long realElapsedRealtimeMs; |
| 3263 | final boolean active = |
| 3264 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3265 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3266 | if (active) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3267 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3268 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3269 | } else { |
| 3270 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3271 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3272 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3273 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3274 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3275 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3276 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3277 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3278 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3279 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3280 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3281 | } |
| 3282 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3283 | + Integer.toHexString(mHistoryCur.states)); |
| 3284 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3285 | mMobileRadioPowerState = powerState; |
| 3286 | if (active) { |
| 3287 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3288 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3289 | } else { |
| 3290 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3291 | updateMobileRadioStateLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3292 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3293 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3294 | } |
| 3295 | } |
| 3296 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3297 | public void notePowerSaveMode(boolean enabled) { |
| 3298 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3299 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3300 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3301 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3302 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3303 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3304 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3305 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3306 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3307 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3308 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3309 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3310 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3311 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3312 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3313 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3314 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3315 | } |
| 3316 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3317 | } |
| 3318 | } |
| 3319 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3320 | public void noteDeviceIdleModeLocked(boolean enabled, boolean fromActive, boolean fromMotion) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3321 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3322 | final long uptime = SystemClock.uptimeMillis(); |
| 3323 | boolean nowIdling = enabled; |
| 3324 | if (mDeviceIdling && !enabled && !fromActive && !fromMotion) { |
| 3325 | // We don't go out of general idling mode until explicitly taken out of |
| 3326 | // device idle through going active or significant motion. |
| 3327 | nowIdling = true; |
| 3328 | } |
| 3329 | if (mDeviceIdling != nowIdling) { |
| 3330 | mDeviceIdling = nowIdling; |
| 3331 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3332 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3333 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
| 3334 | if (enabled) { |
| 3335 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3336 | } else { |
| 3337 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3338 | } |
| 3339 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3340 | if (mDeviceIdleModeEnabled != enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3341 | mDeviceIdleModeEnabled = enabled; |
| 3342 | if (fromMotion) { |
| 3343 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SIGNIFICANT_MOTION, |
| 3344 | "", 0); |
| 3345 | } |
| 3346 | if (fromActive) { |
| 3347 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3348 | "", 0); |
| 3349 | } |
| 3350 | if (enabled) { |
| 3351 | mHistoryCur.states2 |= HistoryItem.STATE2_DEVICE_IDLE_FLAG; |
| 3352 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode enabled to: " |
| 3353 | + Integer.toHexString(mHistoryCur.states2)); |
| 3354 | mDeviceIdleModeEnabledTimer.startRunningLocked(elapsedRealtime); |
| 3355 | } else { |
| 3356 | mHistoryCur.states2 &= ~HistoryItem.STATE2_DEVICE_IDLE_FLAG; |
| 3357 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode disabled to: " |
| 3358 | + Integer.toHexString(mHistoryCur.states2)); |
| 3359 | mDeviceIdleModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
| 3360 | } |
| 3361 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
| 3366 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3367 | final long uptime = SystemClock.uptimeMillis(); |
| 3368 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3369 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3370 | PackageChange pc = new PackageChange(); |
| 3371 | pc.mPackageName = pkgName; |
| 3372 | pc.mUpdate = true; |
| 3373 | pc.mVersionCode = versionCode; |
| 3374 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | public void notePackageUninstalledLocked(String pkgName) { |
| 3378 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3379 | final long uptime = SystemClock.uptimeMillis(); |
| 3380 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3381 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3382 | PackageChange pc = new PackageChange(); |
| 3383 | pc.mPackageName = pkgName; |
| 3384 | pc.mUpdate = true; |
| 3385 | addPackageChange(pc); |
| 3386 | } |
| 3387 | |
| 3388 | private void addPackageChange(PackageChange pc) { |
| 3389 | if (mDailyPackageChanges == null) { |
| 3390 | mDailyPackageChanges = new ArrayList<>(); |
| 3391 | } |
| 3392 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3395 | public void notePhoneOnLocked() { |
| 3396 | if (!mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3397 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3398 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3399 | mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3400 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3401 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3402 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3404 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3405 | } |
| 3406 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | public void notePhoneOffLocked() { |
| 3409 | if (mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3410 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3411 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3412 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3413 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3414 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3415 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3417 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | } |
| 3419 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3420 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3421 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3422 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3423 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3424 | if (i == except) { |
| 3425 | continue; |
| 3426 | } |
| 3427 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3428 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3429 | } |
| 3430 | } |
| 3431 | } |
| 3432 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3433 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3434 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3435 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3436 | // to infer that we are scanning from other data. |
| 3437 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3438 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3439 | state = ServiceState.STATE_IN_SERVICE; |
| 3440 | } |
| 3441 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3442 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3443 | return state; |
| 3444 | } |
| 3445 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3446 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3447 | boolean scanning = false; |
| 3448 | boolean newHistory = false; |
| 3449 | |
| 3450 | mPhoneServiceStateRaw = state; |
| 3451 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3452 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3453 | |
| 3454 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3455 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3456 | |
| 3457 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3458 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3459 | // to infer that we are scanning from other data. |
| 3460 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3461 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3462 | state = ServiceState.STATE_IN_SERVICE; |
| 3463 | } |
| 3464 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3465 | |
| 3466 | // If the phone is powered off, stop all timers. |
| 3467 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3468 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3469 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3470 | // If we are in service, make sure the correct signal string timer is running. |
| 3471 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3472 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3473 | |
| 3474 | // If we're out of service, we are in the lowest signal strength |
| 3475 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3476 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3477 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3478 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3479 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3480 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3481 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3482 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3483 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3484 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3485 | } |
| 3486 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3487 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3488 | if (!scanning) { |
| 3489 | // If we are no longer scanning, then stop the scanning timer. |
| 3490 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3491 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3492 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3493 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3494 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3495 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3496 | } |
| 3497 | } |
| 3498 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3499 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3500 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3501 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3502 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3503 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3504 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3505 | mPhoneServiceState = state; |
| 3506 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3507 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3508 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3509 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3510 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3511 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3512 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3513 | if (strengthBin >= 0) { |
| 3514 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3515 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3516 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3517 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3518 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3519 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3520 | + Integer.toHexString(mHistoryCur.states)); |
| 3521 | newHistory = true; |
| 3522 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3523 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3524 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3525 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3529 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | /** |
| 3534 | * Telephony stack updates the phone state. |
| 3535 | * @param state phone state from ServiceState.getState() |
| 3536 | */ |
| 3537 | public void notePhoneStateLocked(int state, int simState) { |
| 3538 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3541 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3542 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3543 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3544 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3545 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3546 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3547 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3548 | int bin = DATA_CONNECTION_NONE; |
| 3549 | if (hasData) { |
| 3550 | switch (dataType) { |
| 3551 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3552 | bin = DATA_CONNECTION_EDGE; |
| 3553 | break; |
| 3554 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3555 | bin = DATA_CONNECTION_GPRS; |
| 3556 | break; |
| 3557 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3558 | bin = DATA_CONNECTION_UMTS; |
| 3559 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3560 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3561 | bin = DATA_CONNECTION_CDMA; |
| 3562 | break; |
| 3563 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3564 | bin = DATA_CONNECTION_EVDO_0; |
| 3565 | break; |
| 3566 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3567 | bin = DATA_CONNECTION_EVDO_A; |
| 3568 | break; |
| 3569 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3570 | bin = DATA_CONNECTION_1xRTT; |
| 3571 | break; |
| 3572 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3573 | bin = DATA_CONNECTION_HSDPA; |
| 3574 | break; |
| 3575 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3576 | bin = DATA_CONNECTION_HSUPA; |
| 3577 | break; |
| 3578 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3579 | bin = DATA_CONNECTION_HSPA; |
| 3580 | break; |
| 3581 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3582 | bin = DATA_CONNECTION_IDEN; |
| 3583 | break; |
| 3584 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3585 | bin = DATA_CONNECTION_EVDO_B; |
| 3586 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3587 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3588 | bin = DATA_CONNECTION_LTE; |
| 3589 | break; |
| 3590 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3591 | bin = DATA_CONNECTION_EHRPD; |
| 3592 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3593 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3594 | bin = DATA_CONNECTION_HSPAP; |
| 3595 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3596 | default: |
| 3597 | bin = DATA_CONNECTION_OTHER; |
| 3598 | break; |
| 3599 | } |
| 3600 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3601 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3602 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3603 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3604 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3605 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3606 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3607 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3608 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3609 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3610 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3611 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3612 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3613 | } |
| 3614 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3615 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3616 | } |
| 3617 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3618 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3619 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3620 | if (!mWifiOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3621 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3622 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3623 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3624 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3625 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3626 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3627 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3628 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3629 | scheduleSyncExternalStatsLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3630 | } |
| 3631 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3632 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3633 | public void noteWifiOffLocked() { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3634 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3635 | final long uptime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3636 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3637 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3638 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3639 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3640 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3641 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3642 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3643 | scheduleSyncExternalStatsLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3644 | } |
| 3645 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3646 | |
| 3647 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3648 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3649 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3650 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3651 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3652 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3653 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3654 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3655 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3656 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3657 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3658 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3659 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3660 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3661 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3662 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3663 | if (mAudioOnNesting == 0) { |
| 3664 | return; |
| 3665 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3666 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3667 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3668 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3669 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3670 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3671 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3672 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3673 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3674 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3675 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3676 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3680 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3681 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3682 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3683 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3684 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3685 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3686 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3687 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3688 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3689 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3690 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3691 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3692 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3693 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3694 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3695 | if (mVideoOnNesting == 0) { |
| 3696 | return; |
| 3697 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3698 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3699 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3700 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3701 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3702 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3703 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3704 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3705 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3706 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3707 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3708 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3711 | public void noteResetAudioLocked() { |
| 3712 | if (mAudioOnNesting > 0) { |
| 3713 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3714 | final long uptime = SystemClock.uptimeMillis(); |
| 3715 | mAudioOnNesting = 0; |
| 3716 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3717 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3718 | + Integer.toHexString(mHistoryCur.states)); |
| 3719 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3720 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3721 | for (int i=0; i<mUidStats.size(); i++) { |
| 3722 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3723 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | public void noteResetVideoLocked() { |
| 3729 | if (mVideoOnNesting > 0) { |
| 3730 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3731 | final long uptime = SystemClock.uptimeMillis(); |
| 3732 | mAudioOnNesting = 0; |
| 3733 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3734 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3735 | + Integer.toHexString(mHistoryCur.states)); |
| 3736 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3737 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3738 | for (int i=0; i<mUidStats.size(); i++) { |
| 3739 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3740 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3741 | } |
| 3742 | } |
| 3743 | } |
| 3744 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3745 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3746 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3747 | getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3751 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3752 | getUidStatsLocked(uid).noteActivityPausedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3753 | } |
| 3754 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3755 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3756 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3757 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3758 | } |
| 3759 | |
| 3760 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3761 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3762 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3763 | } |
| 3764 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3765 | public void noteFlashlightOnLocked() { |
| 3766 | if (!mFlashlightOn) { |
| 3767 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3768 | final long uptime = SystemClock.uptimeMillis(); |
| 3769 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3770 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
| 3771 | + Integer.toHexString(mHistoryCur.states)); |
| 3772 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3773 | mFlashlightOn = true; |
| 3774 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3775 | } |
| 3776 | } |
| 3777 | |
| 3778 | public void noteFlashlightOffLocked() { |
| 3779 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3780 | final long uptime = SystemClock.uptimeMillis(); |
| 3781 | if (mFlashlightOn) { |
| 3782 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3783 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3784 | + Integer.toHexString(mHistoryCur.states)); |
| 3785 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3786 | mFlashlightOn = false; |
| 3787 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3788 | } |
| 3789 | } |
| 3790 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3791 | public void noteWifiRunningLocked(WorkSource ws) { |
| 3792 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3793 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3794 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3795 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3796 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 3797 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3798 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3799 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3800 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3801 | int N = ws.size(); |
| 3802 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3803 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3804 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3805 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3806 | scheduleSyncExternalStatsLocked(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3807 | } else { |
| 3808 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3812 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 3813 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3814 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3815 | int N = oldWs.size(); |
| 3816 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3817 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3818 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3819 | } |
| 3820 | N = newWs.size(); |
| 3821 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3822 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3823 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3824 | } |
| 3825 | } else { |
| 3826 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 3831 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3832 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3833 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3834 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3835 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 3836 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3837 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3838 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3839 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3840 | int N = ws.size(); |
| 3841 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3842 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3843 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3844 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3845 | scheduleSyncExternalStatsLocked(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3846 | } else { |
| 3847 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3848 | } |
| 3849 | } |
| 3850 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3851 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 3852 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 3853 | if (mWifiState != wifiState) { |
| 3854 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3855 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3856 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3857 | } |
| 3858 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3859 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3860 | scheduleSyncExternalStatsLocked(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3861 | } |
| 3862 | } |
| 3863 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3864 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 3865 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 3866 | if (mWifiSupplState != supplState) { |
| 3867 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3868 | final long uptime = SystemClock.uptimeMillis(); |
| 3869 | if (mWifiSupplState >= 0) { |
| 3870 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 3871 | } |
| 3872 | mWifiSupplState = supplState; |
| 3873 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 3874 | mHistoryCur.states2 = |
| 3875 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 3876 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 3877 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 3878 | + Integer.toHexString(mHistoryCur.states2)); |
| 3879 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
| 3884 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3885 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3886 | if (i == except) { |
| 3887 | continue; |
| 3888 | } |
| 3889 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 3890 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 3891 | } |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 3896 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 3897 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 3898 | if (mWifiSignalStrengthBin != strengthBin) { |
| 3899 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3900 | final long uptime = SystemClock.uptimeMillis(); |
| 3901 | if (mWifiSignalStrengthBin >= 0) { |
| 3902 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 3903 | elapsedRealtime); |
| 3904 | } |
| 3905 | if (strengthBin >= 0) { |
| 3906 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 3907 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 3908 | } |
| 3909 | mHistoryCur.states2 = |
| 3910 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 3911 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 3912 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 3913 | + Integer.toHexString(mHistoryCur.states2)); |
| 3914 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3915 | } else { |
| 3916 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 3917 | } |
| 3918 | mWifiSignalStrengthBin = strengthBin; |
| 3919 | } |
| 3920 | } |
| 3921 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3922 | public void noteBluetoothOnLocked() { |
| 3923 | if (!mBluetoothOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3924 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3925 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3926 | mHistoryCur.states |= HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3927 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth on to: " |
| 3928 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3929 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3930 | mBluetoothOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3931 | mBluetoothOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3932 | scheduleSyncExternalStatsLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3933 | } |
| 3934 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3935 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3936 | public void noteBluetoothOffLocked() { |
| 3937 | if (mBluetoothOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3938 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3939 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3940 | mHistoryCur.states &= ~HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3941 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth off to: " |
| 3942 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3943 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3944 | mBluetoothOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3945 | mBluetoothOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3946 | scheduleSyncExternalStatsLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3947 | } |
| 3948 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3949 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3950 | public void noteBluetoothStateLocked(int bluetoothState) { |
| 3951 | if (DEBUG) Log.i(TAG, "Bluetooth state -> " + bluetoothState); |
| 3952 | if (mBluetoothState != bluetoothState) { |
| 3953 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3954 | if (mBluetoothState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3955 | mBluetoothStateTimer[mBluetoothState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3956 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3957 | mBluetoothState = bluetoothState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3958 | mBluetoothStateTimer[bluetoothState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3962 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3963 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3964 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3965 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3966 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3967 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3968 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3969 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3970 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 3971 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3972 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3973 | } |
| 3974 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3975 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3979 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3980 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3981 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3982 | mWifiFullLockNesting--; |
| 3983 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3984 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3985 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 3986 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3987 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3988 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3989 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3992 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3993 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3994 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3995 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3996 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3997 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3998 | if (mWifiScanNesting == 0) { |
| 3999 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4000 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4001 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4002 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4003 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4004 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4005 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4008 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4009 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4010 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4011 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4012 | mWifiScanNesting--; |
| 4013 | if (mWifiScanNesting == 0) { |
| 4014 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4015 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4016 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4017 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4018 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4019 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4020 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4021 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4022 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4023 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4024 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4025 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4029 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4030 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4031 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4034 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4035 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4036 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4037 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4038 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4039 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4040 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4041 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4042 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4043 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4044 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4045 | } |
| 4046 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4047 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4051 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4052 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4053 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4054 | mWifiMulticastNesting--; |
| 4055 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4056 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4057 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4058 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4059 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4060 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4061 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4064 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4065 | int N = ws.size(); |
| 4066 | for (int i=0; i<N; i++) { |
| 4067 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4072 | int N = ws.size(); |
| 4073 | for (int i=0; i<N; i++) { |
| 4074 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4075 | } |
| 4076 | } |
| 4077 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4078 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4079 | int N = ws.size(); |
| 4080 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4081 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4082 | } |
| 4083 | } |
| 4084 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4085 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4086 | int N = ws.size(); |
| 4087 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4088 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4089 | } |
| 4090 | } |
| 4091 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4092 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4093 | int N = ws.size(); |
| 4094 | for (int i=0; i<N; i++) { |
| 4095 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4096 | } |
| 4097 | } |
| 4098 | |
| 4099 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4100 | int N = ws.size(); |
| 4101 | for (int i=0; i<N; i++) { |
| 4102 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4103 | } |
| 4104 | } |
| 4105 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4106 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4107 | int N = ws.size(); |
| 4108 | for (int i=0; i<N; i++) { |
| 4109 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4114 | int N = ws.size(); |
| 4115 | for (int i=0; i<N; i++) { |
| 4116 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4117 | } |
| 4118 | } |
| 4119 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4120 | private static String[] includeInStringArray(String[] array, String str) { |
| 4121 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4122 | return array; |
| 4123 | } |
| 4124 | String[] newArray = new String[array.length+1]; |
| 4125 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4126 | newArray[array.length] = str; |
| 4127 | return newArray; |
| 4128 | } |
| 4129 | |
| 4130 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4131 | int index = ArrayUtils.indexOf(array, str); |
| 4132 | if (index >= 0) { |
| 4133 | String[] newArray = new String[array.length-1]; |
| 4134 | if (index > 0) { |
| 4135 | System.arraycopy(array, 0, newArray, 0, index); |
| 4136 | } |
| 4137 | if (index < array.length-1) { |
| 4138 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4139 | } |
| 4140 | return newArray; |
| 4141 | } |
| 4142 | return array; |
| 4143 | } |
| 4144 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4145 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4146 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4147 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4148 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4149 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4150 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4151 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4152 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4153 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4154 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4155 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4156 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4157 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4158 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4159 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | public void noteNetworkStatsEnabledLocked() { |
| 4164 | // During device boot, qtaguid isn't enabled until after the inital |
| 4165 | // loading of battery stats. Now that they're enabled, take our initial |
| 4166 | // snapshot for future delta calculation. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4167 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 4168 | updateMobileRadioStateLocked(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4169 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4172 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4173 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4175 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4176 | @Override public int getScreenOnCount(int which) { |
| 4177 | return mScreenOnTimer.getCountLocked(which); |
| 4178 | } |
| 4179 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4180 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4181 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4182 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4183 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4184 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4185 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4186 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4187 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4188 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4189 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4190 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4191 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4194 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4195 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4196 | } |
| 4197 | |
| 4198 | @Override public long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4199 | return mDeviceIdleModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4200 | } |
| 4201 | |
| 4202 | @Override public int getDeviceIdleModeEnabledCount(int which) { |
| 4203 | return mDeviceIdleModeEnabledTimer.getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4206 | @Override public long getDeviceIdlingTime(long elapsedRealtimeUs, int which) { |
| 4207 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4208 | } |
| 4209 | |
| 4210 | @Override public int getDeviceIdlingCount(int which) { |
| 4211 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4212 | } |
| 4213 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4214 | @Override public int getNumConnectivityChange(int which) { |
| 4215 | int val = mNumConnectivityChange; |
| 4216 | if (which == STATS_CURRENT) { |
| 4217 | val -= mLoadedNumConnectivityChange; |
| 4218 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4219 | val -= mUnpluggedNumConnectivityChange; |
| 4220 | } |
| 4221 | return val; |
| 4222 | } |
| 4223 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4224 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4225 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4227 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4228 | @Override public int getPhoneOnCount(int which) { |
| 4229 | return mPhoneOnTimer.getCountLocked(which); |
| 4230 | } |
| 4231 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4232 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4233 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4234 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4235 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4236 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4237 | |
| 4238 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4239 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4240 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4241 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4242 | } |
| 4243 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4244 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4245 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4246 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4247 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4248 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4249 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4250 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4251 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4252 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4253 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4254 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4255 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4256 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4257 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4258 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4259 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4260 | } |
| 4261 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4262 | @Override public int getMobileRadioActiveCount(int which) { |
| 4263 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4264 | } |
| 4265 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4266 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4267 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4268 | } |
| 4269 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4270 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4271 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4272 | } |
| 4273 | |
| 4274 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4275 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4276 | } |
| 4277 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4278 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4279 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4280 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4281 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4282 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4283 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4286 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4287 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4288 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4289 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4293 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4294 | } |
| 4295 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4296 | @Override public long getWifiSupplStateTime(int state, |
| 4297 | long elapsedRealtimeUs, int which) { |
| 4298 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4299 | elapsedRealtimeUs, which); |
| 4300 | } |
| 4301 | |
| 4302 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4303 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4304 | } |
| 4305 | |
| 4306 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4307 | long elapsedRealtimeUs, int which) { |
| 4308 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4309 | elapsedRealtimeUs, which); |
| 4310 | } |
| 4311 | |
| 4312 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4313 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4314 | } |
| 4315 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4316 | @Override public long getBluetoothOnTime(long elapsedRealtimeUs, int which) { |
| 4317 | return mBluetoothOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4318 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4319 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4320 | @Override public long getBluetoothStateTime(int bluetoothState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4321 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4322 | return mBluetoothStateTimer[bluetoothState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4323 | elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4324 | } |
| 4325 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4326 | @Override public int getBluetoothStateCount(int bluetoothState, int which) { |
| 4327 | return mBluetoothStateTimer[bluetoothState].getCountLocked(which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4328 | } |
| 4329 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4330 | @Override public boolean hasBluetoothActivityReporting() { |
| 4331 | return mHasBluetoothEnergyReporting; |
| 4332 | } |
| 4333 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4334 | @Override public long getBluetoothControllerActivity(int type, int which) { |
| 4335 | if (type >= 0 && type < mBluetoothActivityCounters.length) { |
| 4336 | return mBluetoothActivityCounters[type].getCountLocked(which); |
| 4337 | } |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4341 | @Override public boolean hasWifiActivityReporting() { |
| 4342 | return mHasWifiEnergyReporting; |
| 4343 | } |
| 4344 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4345 | @Override public long getWifiControllerActivity(int type, int which) { |
| 4346 | if (type >= 0 && type < mWifiActivityCounters.length) { |
| 4347 | return mWifiActivityCounters[type].getCountLocked(which); |
| 4348 | } |
| 4349 | return 0; |
| 4350 | } |
| 4351 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4352 | @Override public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
| 4353 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4354 | } |
| 4355 | |
| 4356 | @Override public long getFlashlightOnCount(int which) { |
| 4357 | return mFlashlightOnTimer.getCountLocked(which); |
| 4358 | } |
| 4359 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4360 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4361 | public long getNetworkActivityBytes(int type, int which) { |
| 4362 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4363 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4364 | } else { |
| 4365 | return 0; |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | @Override |
| 4370 | public long getNetworkActivityPackets(int type, int which) { |
| 4371 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4372 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4373 | } else { |
| 4374 | return 0; |
| 4375 | } |
| 4376 | } |
| 4377 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4378 | boolean isStartClockTimeValid() { |
| 4379 | return mStartClockTime > 365*24*60*60*1000L; |
| 4380 | } |
| 4381 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4382 | @Override public long getStartClockTime() { |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4383 | if (!isStartClockTimeValid()) { |
| 4384 | // If the last clock time we got was very small, then we hadn't had a real |
| 4385 | // time yet, so try to get it again. |
| 4386 | mStartClockTime = System.currentTimeMillis(); |
| 4387 | if (isStartClockTimeValid()) { |
| 4388 | recordCurrentTimeChangeLocked(mStartClockTime, SystemClock.elapsedRealtime(), |
| 4389 | SystemClock.uptimeMillis()); |
| 4390 | } |
| 4391 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4392 | return mStartClockTime; |
| 4393 | } |
| 4394 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4395 | @Override public String getStartPlatformVersion() { |
| 4396 | return mStartPlatformVersion; |
| 4397 | } |
| 4398 | |
| 4399 | @Override public String getEndPlatformVersion() { |
| 4400 | return mEndPlatformVersion; |
| 4401 | } |
| 4402 | |
| 4403 | @Override public int getParcelVersion() { |
| 4404 | return VERSION; |
| 4405 | } |
| 4406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | @Override public boolean getIsOnBattery() { |
| 4408 | return mOnBattery; |
| 4409 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4412 | return mUidStats; |
| 4413 | } |
| 4414 | |
| 4415 | /** |
| 4416 | * The statistics associated with a particular uid. |
| 4417 | */ |
| 4418 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4421 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4422 | boolean mWifiRunning; |
| 4423 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4424 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4425 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4426 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4427 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4428 | boolean mWifiScanStarted; |
| 4429 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4430 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4431 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4432 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4433 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4434 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4435 | boolean mWifiMulticastEnabled; |
| 4436 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4437 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4438 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4439 | StopwatchTimer mVideoTurnedOnTimer; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4440 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4441 | StopwatchTimer mForegroundActivityTimer; |
| 4442 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4443 | static final int PROCESS_STATE_NONE = NUM_PROCESS_STATE; |
| 4444 | int mProcessState = PROCESS_STATE_NONE; |
| 4445 | StopwatchTimer[] mProcessStateTimer; |
| 4446 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4447 | BatchTimer mVibratorOnTimer; |
| 4448 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4449 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4450 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4451 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4452 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4453 | LongSamplingCounter mMobileRadioActiveTime; |
| 4454 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4457 | * The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode. |
| 4458 | */ |
| 4459 | LongSamplingCounter[] mWifiControllerTime = |
| 4460 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4461 | |
| 4462 | /** |
| 4463 | * The amount of time this uid has kept the Bluetooth controller in idle, tx, and rx mode. |
| 4464 | */ |
| 4465 | LongSamplingCounter[] mBluetoothControllerTime = |
| 4466 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4467 | |
| 4468 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4469 | * The CPU times we had at the last history details update. |
| 4470 | */ |
| 4471 | long mLastStepUserTime; |
| 4472 | long mLastStepSystemTime; |
| 4473 | long mCurStepUserTime; |
| 4474 | long mCurStepSystemTime; |
| 4475 | |
| 4476 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | * The statistics we have collected for this uid's wake locks. |
| 4478 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4479 | final OverflowArrayMap<Wakelock> mWakelockStats = new OverflowArrayMap<Wakelock>() { |
| 4480 | @Override public Wakelock instantiateObject() { return new Wakelock(); } |
| 4481 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | |
| 4483 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4484 | * The statistics we have collected for this uid's syncs. |
| 4485 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4486 | final OverflowArrayMap<StopwatchTimer> mSyncStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4487 | @Override public StopwatchTimer instantiateObject() { |
| 4488 | return new StopwatchTimer(Uid.this, SYNC, null, mOnBatteryTimeBase); |
| 4489 | } |
| 4490 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4491 | |
| 4492 | /** |
| 4493 | * The statistics we have collected for this uid's jobs. |
| 4494 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4495 | final OverflowArrayMap<StopwatchTimer> mJobStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4496 | @Override public StopwatchTimer instantiateObject() { |
| 4497 | return new StopwatchTimer(Uid.this, JOB, null, mOnBatteryTimeBase); |
| 4498 | } |
| 4499 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4500 | |
| 4501 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | * The statistics we have collected for this uid's sensor activations. |
| 4503 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4504 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | |
| 4506 | /** |
| 4507 | * The statistics we have collected for this uid's processes. |
| 4508 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4509 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | |
| 4511 | /** |
| 4512 | * The statistics we have collected for this uid's processes. |
| 4513 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4514 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4515 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4516 | /** |
| 4517 | * The transient wake stats we have collected for this uid's pids. |
| 4518 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4519 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | public Uid(int uid) { |
| 4522 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4523 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4524 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4525 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4526 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4527 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4528 | mWifiScanTimers, mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4529 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4530 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4531 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4532 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4536 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4537 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4541 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4542 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4546 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4547 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4551 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | return mSensorStats; |
| 4553 | } |
| 4554 | |
| 4555 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4556 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4557 | return mProcessStats; |
| 4558 | } |
| 4559 | |
| 4560 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4561 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | return mPackageStats; |
| 4563 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4564 | |
| 4565 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4566 | public int getUid() { |
| 4567 | return mUid; |
| 4568 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4569 | |
| 4570 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4571 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4572 | if (!mWifiRunning) { |
| 4573 | mWifiRunning = true; |
| 4574 | if (mWifiRunningTimer == null) { |
| 4575 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4576 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4577 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4578 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4579 | } |
| 4580 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4581 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4582 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4583 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4584 | if (mWifiRunning) { |
| 4585 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4586 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4587 | } |
| 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 |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4591 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4592 | if (!mFullWifiLockOut) { |
| 4593 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4594 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4595 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4596 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4597 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4598 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4599 | } |
| 4600 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4601 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4602 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4603 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4604 | if (mFullWifiLockOut) { |
| 4605 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4606 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4607 | } |
| 4608 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4609 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4610 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4611 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4612 | if (!mWifiScanStarted) { |
| 4613 | mWifiScanStarted = true; |
| 4614 | if (mWifiScanTimer == null) { |
| 4615 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4616 | mWifiScanTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4617 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4618 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4619 | } |
| 4620 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4621 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4622 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4623 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4624 | if (mWifiScanStarted) { |
| 4625 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4626 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4627 | } |
| 4628 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4629 | |
| 4630 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4631 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4632 | int bin = 0; |
| 4633 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS) { |
| 4634 | csph = csph >> 3; |
| 4635 | bin++; |
| 4636 | } |
| 4637 | |
| 4638 | if (mWifiBatchedScanBinStarted == bin) return; |
| 4639 | |
| 4640 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4641 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4642 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4643 | } |
| 4644 | mWifiBatchedScanBinStarted = bin; |
| 4645 | if (mWifiBatchedScanTimer[bin] == null) { |
| 4646 | makeWifiBatchedScanBin(bin, null); |
| 4647 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4648 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4652 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4653 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4654 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4655 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4656 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4657 | } |
| 4658 | } |
| 4659 | |
| 4660 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4661 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4662 | if (!mWifiMulticastEnabled) { |
| 4663 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4664 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4665 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4666 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4667 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4668 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4673 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4674 | if (mWifiMulticastEnabled) { |
| 4675 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4676 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4680 | public void noteWifiControllerActivityLocked(int type, long timeMs) { |
| 4681 | if (mWifiControllerTime[type] == null) { |
| 4682 | mWifiControllerTime[type] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4683 | } |
| 4684 | mWifiControllerTime[type].addCountLocked(timeMs); |
| 4685 | } |
| 4686 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4687 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 4688 | if (mAudioTurnedOnTimer == null) { |
| 4689 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4690 | mAudioTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4691 | } |
| 4692 | return mAudioTurnedOnTimer; |
| 4693 | } |
| 4694 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4695 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4696 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4697 | } |
| 4698 | |
| 4699 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 4700 | if (mAudioTurnedOnTimer != null) { |
| 4701 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4702 | } |
| 4703 | } |
| 4704 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4705 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 4706 | if (mAudioTurnedOnTimer != null) { |
| 4707 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4708 | } |
| 4709 | } |
| 4710 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4711 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 4712 | if (mVideoTurnedOnTimer == null) { |
| 4713 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4714 | mVideoTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4715 | } |
| 4716 | return mVideoTurnedOnTimer; |
| 4717 | } |
| 4718 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4719 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4720 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4721 | } |
| 4722 | |
| 4723 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 4724 | if (mVideoTurnedOnTimer != null) { |
| 4725 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4726 | } |
| 4727 | } |
| 4728 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4729 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 4730 | if (mVideoTurnedOnTimer != null) { |
| 4731 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4732 | } |
| 4733 | } |
| 4734 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4735 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 4736 | if (mForegroundActivityTimer == null) { |
| 4737 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4738 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4739 | } |
| 4740 | return mForegroundActivityTimer; |
| 4741 | } |
| 4742 | |
| 4743 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4744 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4745 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4746 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4750 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4751 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4752 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4756 | void updateUidProcessStateLocked(int state, long elapsedRealtimeMs) { |
| 4757 | if (mProcessState == state) return; |
| 4758 | |
| 4759 | if (mProcessState != PROCESS_STATE_NONE) { |
| 4760 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
| 4761 | } |
| 4762 | mProcessState = state; |
| 4763 | if (state != PROCESS_STATE_NONE) { |
| 4764 | if (mProcessStateTimer[state] == null) { |
| 4765 | makeProcessState(state, null); |
| 4766 | } |
| 4767 | mProcessStateTimer[state].startRunningLocked(elapsedRealtimeMs); |
| 4768 | } |
| 4769 | } |
| 4770 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4771 | public BatchTimer createVibratorOnTimerLocked() { |
| 4772 | if (mVibratorOnTimer == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4773 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4774 | } |
| 4775 | return mVibratorOnTimer; |
| 4776 | } |
| 4777 | |
| 4778 | public void noteVibratorOnLocked(long durationMillis) { |
| 4779 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 4780 | } |
| 4781 | |
| 4782 | public void noteVibratorOffLocked() { |
| 4783 | if (mVibratorOnTimer != null) { |
| 4784 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4785 | } |
| 4786 | } |
| 4787 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4788 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4789 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4790 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4791 | return 0; |
| 4792 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4793 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4794 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4795 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4796 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4797 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4798 | if (mFullWifiLockTimer == null) { |
| 4799 | return 0; |
| 4800 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4801 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4802 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4803 | |
| 4804 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4805 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4806 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4807 | return 0; |
| 4808 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4809 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4810 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4811 | |
| 4812 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4813 | public int getWifiScanCount(int which) { |
| 4814 | if (mWifiScanTimer == null) { |
| 4815 | return 0; |
| 4816 | } |
| 4817 | return mWifiScanTimer.getCountLocked(which); |
| 4818 | } |
| 4819 | |
| 4820 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4821 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4822 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4823 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4824 | return 0; |
| 4825 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4826 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4830 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 4831 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4832 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4833 | return 0; |
| 4834 | } |
| 4835 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 4836 | } |
| 4837 | |
| 4838 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4839 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4840 | if (mWifiMulticastTimer == null) { |
| 4841 | return 0; |
| 4842 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4843 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4844 | } |
| 4845 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4846 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4847 | public long getAudioTurnedOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4848 | if (mAudioTurnedOnTimer == null) { |
| 4849 | return 0; |
| 4850 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4851 | return mAudioTurnedOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4852 | } |
| 4853 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4854 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4855 | public long getVideoTurnedOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4856 | if (mVideoTurnedOnTimer == null) { |
| 4857 | return 0; |
| 4858 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4859 | return mVideoTurnedOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4860 | } |
| 4861 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4862 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4863 | public Timer getForegroundActivityTimer() { |
| 4864 | return mForegroundActivityTimer; |
| 4865 | } |
| 4866 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4867 | void makeProcessState(int i, Parcel in) { |
| 4868 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 4869 | |
| 4870 | if (in == null) { |
| 4871 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4872 | mOnBatteryTimeBase); |
| 4873 | } else { |
| 4874 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4875 | mOnBatteryTimeBase, in); |
| 4876 | } |
| 4877 | } |
| 4878 | |
| 4879 | @Override |
| 4880 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 4881 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 4882 | if (mProcessStateTimer[state] == null) { |
| 4883 | return 0; |
| 4884 | } |
| 4885 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4886 | } |
| 4887 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4888 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4889 | public Timer getVibratorOnTimer() { |
| 4890 | return mVibratorOnTimer; |
| 4891 | } |
| 4892 | |
| 4893 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4894 | public void noteUserActivityLocked(int type) { |
| 4895 | if (mUserActivityCounters == null) { |
| 4896 | initUserActivityLocked(); |
| 4897 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 4898 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 4899 | mUserActivityCounters[type].stepAtomic(); |
| 4900 | } else { |
| 4901 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 4902 | new Throwable()); |
| 4903 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4904 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4905 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4906 | @Override |
| 4907 | public boolean hasUserActivity() { |
| 4908 | return mUserActivityCounters != null; |
| 4909 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4910 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4911 | @Override |
| 4912 | public int getUserActivityCount(int type, int which) { |
| 4913 | if (mUserActivityCounters == null) { |
| 4914 | return 0; |
| 4915 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4916 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4917 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4918 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4919 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 4920 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 4921 | |
| 4922 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 4923 | if (collected == null) { |
| 4924 | collected = new ArrayList<StopwatchTimer>(); |
| 4925 | mWifiBatchedScanTimers.put(i, collected); |
| 4926 | } |
| 4927 | if (in == null) { |
| 4928 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4929 | mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4930 | } else { |
| 4931 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4932 | mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4937 | void initUserActivityLocked() { |
| 4938 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4939 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4940 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4941 | } |
| 4942 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4943 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4944 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 4945 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4946 | initNetworkActivityLocked(); |
| 4947 | } |
| 4948 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4949 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 4950 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4951 | } else { |
| 4952 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 4953 | new Throwable()); |
| 4954 | } |
| 4955 | } |
| 4956 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4957 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 4958 | if (mNetworkByteActivityCounters == null) { |
| 4959 | initNetworkActivityLocked(); |
| 4960 | } |
| 4961 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 4962 | mMobileRadioActiveCount.addCountLocked(1); |
| 4963 | } |
| 4964 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4965 | @Override |
| 4966 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4967 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4971 | public long getNetworkActivityBytes(int type, int which) { |
| 4972 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 4973 | && type < mNetworkByteActivityCounters.length) { |
| 4974 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4975 | } else { |
| 4976 | return 0; |
| 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | @Override |
| 4981 | public long getNetworkActivityPackets(int type, int which) { |
| 4982 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 4983 | && type < mNetworkPacketActivityCounters.length) { |
| 4984 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4985 | } else { |
| 4986 | return 0; |
| 4987 | } |
| 4988 | } |
| 4989 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4990 | @Override |
| 4991 | public long getMobileRadioActiveTime(int which) { |
| 4992 | return mMobileRadioActiveTime != null |
| 4993 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 4994 | } |
| 4995 | |
| 4996 | @Override |
| 4997 | public int getMobileRadioActiveCount(int which) { |
| 4998 | return mMobileRadioActiveCount != null |
| 4999 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5000 | } |
| 5001 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5002 | @Override |
| 5003 | public long getWifiControllerActivity(int type, int which) { |
| 5004 | if (type >= 0 && type < NUM_CONTROLLER_ACTIVITY_TYPES && |
| 5005 | mWifiControllerTime[type] != null) { |
| 5006 | return mWifiControllerTime[type].getCountLocked(which); |
| 5007 | } |
| 5008 | return 0; |
| 5009 | } |
| 5010 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5011 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5012 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5013 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5014 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5015 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5016 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5017 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5018 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5019 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5020 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5021 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5022 | /** |
| 5023 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5024 | * inactive so can be dropped. |
| 5025 | */ |
| 5026 | boolean reset() { |
| 5027 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5028 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5029 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5030 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5031 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5032 | } |
| 5033 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5034 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5035 | active |= mFullWifiLockOut; |
| 5036 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5037 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5038 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5039 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5040 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5041 | if (mWifiBatchedScanTimer != null) { |
| 5042 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5043 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5044 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5048 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5049 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5050 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5051 | active |= mWifiMulticastEnabled; |
| 5052 | } |
| 5053 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5054 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5055 | } |
| 5056 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5057 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5058 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5059 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5060 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5061 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5062 | if (mProcessStateTimer != null) { |
| 5063 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5064 | if (mProcessStateTimer[i] != null) { |
| 5065 | active |= !mProcessStateTimer[i].reset(false); |
| 5066 | } |
| 5067 | } |
| 5068 | active |= (mProcessState != PROCESS_STATE_NONE); |
| 5069 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5070 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5071 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5072 | mVibratorOnTimer.detach(); |
| 5073 | mVibratorOnTimer = null; |
| 5074 | } else { |
| 5075 | active = true; |
| 5076 | } |
| 5077 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5078 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5079 | if (mUserActivityCounters != null) { |
| 5080 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5081 | mUserActivityCounters[i].reset(false); |
| 5082 | } |
| 5083 | } |
| 5084 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5085 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5086 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5087 | mNetworkByteActivityCounters[i].reset(false); |
| 5088 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5089 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5090 | mMobileRadioActiveTime.reset(false); |
| 5091 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5094 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5095 | if (mWifiControllerTime[i] != null) { |
| 5096 | mWifiControllerTime[i].reset(false); |
| 5097 | } |
| 5098 | |
| 5099 | if (mBluetoothControllerTime[i] != null) { |
| 5100 | mBluetoothControllerTime[i].reset(false); |
| 5101 | } |
| 5102 | } |
| 5103 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5104 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5105 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5106 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5107 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5108 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5109 | } else { |
| 5110 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5111 | } |
| 5112 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5113 | mWakelockStats.cleanup(); |
| 5114 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5115 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5116 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5117 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5118 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5119 | timer.detach(); |
| 5120 | } else { |
| 5121 | active = true; |
| 5122 | } |
| 5123 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5124 | mSyncStats.cleanup(); |
| 5125 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5126 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5127 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5128 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5129 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5130 | timer.detach(); |
| 5131 | } else { |
| 5132 | active = true; |
| 5133 | } |
| 5134 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5135 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5136 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5137 | Sensor s = mSensorStats.valueAt(ise); |
| 5138 | if (s.reset()) { |
| 5139 | mSensorStats.removeAt(ise); |
| 5140 | } else { |
| 5141 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5142 | } |
| 5143 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5144 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5145 | Proc proc = mProcessStats.valueAt(ip); |
| 5146 | if (proc.mProcessState == PROCESS_STATE_NONE) { |
| 5147 | proc.detach(); |
| 5148 | mProcessStats.removeAt(ip); |
| 5149 | } else { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5150 | proc.reset(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5151 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5152 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5153 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5154 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5155 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5156 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5157 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5158 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5159 | } else { |
| 5160 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5161 | } |
| 5162 | } |
| 5163 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5164 | if (mPackageStats.size() > 0) { |
| 5165 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5166 | while (it.hasNext()) { |
| 5167 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5168 | Pkg p = pkgEntry.getValue(); |
| 5169 | p.detach(); |
| 5170 | if (p.mServiceStats.size() > 0) { |
| 5171 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5172 | = p.mServiceStats.entrySet().iterator(); |
| 5173 | while (it2.hasNext()) { |
| 5174 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5175 | servEntry.getValue().detach(); |
| 5176 | } |
| 5177 | } |
| 5178 | } |
| 5179 | mPackageStats.clear(); |
| 5180 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5181 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5182 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5183 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5184 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5185 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5186 | if (mWifiRunningTimer != null) { |
| 5187 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5188 | } |
| 5189 | if (mFullWifiLockTimer != null) { |
| 5190 | mFullWifiLockTimer.detach(); |
| 5191 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5192 | if (mWifiScanTimer != null) { |
| 5193 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5194 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5195 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5196 | if (mWifiBatchedScanTimer[i] != null) { |
| 5197 | mWifiBatchedScanTimer[i].detach(); |
| 5198 | } |
| 5199 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5200 | if (mWifiMulticastTimer != null) { |
| 5201 | mWifiMulticastTimer.detach(); |
| 5202 | } |
| 5203 | if (mAudioTurnedOnTimer != null) { |
| 5204 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5205 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5206 | } |
| 5207 | if (mVideoTurnedOnTimer != null) { |
| 5208 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5209 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5210 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5211 | if (mForegroundActivityTimer != null) { |
| 5212 | mForegroundActivityTimer.detach(); |
| 5213 | mForegroundActivityTimer = null; |
| 5214 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5215 | if (mUserActivityCounters != null) { |
| 5216 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5217 | mUserActivityCounters[i].detach(); |
| 5218 | } |
| 5219 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5220 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5221 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5222 | mNetworkByteActivityCounters[i].detach(); |
| 5223 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5224 | } |
| 5225 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5226 | |
| 5227 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5228 | if (mWifiControllerTime[i] != null) { |
| 5229 | mWifiControllerTime[i].detach(); |
| 5230 | } |
| 5231 | |
| 5232 | if (mBluetoothControllerTime[i] != null) { |
| 5233 | mBluetoothControllerTime[i].detach(); |
| 5234 | } |
| 5235 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5236 | mPids.clear(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5237 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5238 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5239 | return !active; |
| 5240 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5241 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5242 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5243 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5244 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5245 | out.writeInt(NW); |
| 5246 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5247 | out.writeString(wakeStats.keyAt(iw)); |
| 5248 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5249 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5250 | } |
| 5251 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5252 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5253 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5254 | out.writeInt(NS); |
| 5255 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5256 | out.writeString(syncStats.keyAt(is)); |
| 5257 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5258 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5259 | } |
| 5260 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5261 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5262 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5263 | out.writeInt(NJ); |
| 5264 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5265 | out.writeString(jobStats.keyAt(ij)); |
| 5266 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5267 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5268 | } |
| 5269 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5270 | int NSE = mSensorStats.size(); |
| 5271 | out.writeInt(NSE); |
| 5272 | for (int ise=0; ise<NSE; ise++) { |
| 5273 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5274 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5275 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5276 | } |
| 5277 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5278 | int NP = mProcessStats.size(); |
| 5279 | out.writeInt(NP); |
| 5280 | for (int ip=0; ip<NP; ip++) { |
| 5281 | out.writeString(mProcessStats.keyAt(ip)); |
| 5282 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5283 | proc.writeToParcelLocked(out); |
| 5284 | } |
| 5285 | |
| 5286 | out.writeInt(mPackageStats.size()); |
| 5287 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5288 | out.writeString(pkgEntry.getKey()); |
| 5289 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5290 | pkg.writeToParcelLocked(out); |
| 5291 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5292 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5293 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5294 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5295 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5296 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5297 | out.writeInt(0); |
| 5298 | } |
| 5299 | if (mFullWifiLockTimer != null) { |
| 5300 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5301 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5302 | } else { |
| 5303 | out.writeInt(0); |
| 5304 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5305 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5306 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5307 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5308 | } else { |
| 5309 | out.writeInt(0); |
| 5310 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5311 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5312 | if (mWifiBatchedScanTimer[i] != null) { |
| 5313 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5314 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5315 | } else { |
| 5316 | out.writeInt(0); |
| 5317 | } |
| 5318 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5319 | if (mWifiMulticastTimer != null) { |
| 5320 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5321 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5322 | } else { |
| 5323 | out.writeInt(0); |
| 5324 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5325 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5326 | if (mAudioTurnedOnTimer != null) { |
| 5327 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5328 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5329 | } else { |
| 5330 | out.writeInt(0); |
| 5331 | } |
| 5332 | if (mVideoTurnedOnTimer != null) { |
| 5333 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5334 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5335 | } else { |
| 5336 | out.writeInt(0); |
| 5337 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5338 | if (mForegroundActivityTimer != null) { |
| 5339 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5340 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5341 | } else { |
| 5342 | out.writeInt(0); |
| 5343 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5344 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5345 | if (mProcessStateTimer[i] != null) { |
| 5346 | out.writeInt(1); |
| 5347 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 5348 | } else { |
| 5349 | out.writeInt(0); |
| 5350 | } |
| 5351 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5352 | if (mVibratorOnTimer != null) { |
| 5353 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5354 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5355 | } else { |
| 5356 | out.writeInt(0); |
| 5357 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5358 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5359 | out.writeInt(1); |
| 5360 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5361 | mUserActivityCounters[i].writeToParcel(out); |
| 5362 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5363 | } else { |
| 5364 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5365 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5366 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5367 | out.writeInt(1); |
| 5368 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5369 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 5370 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5371 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5372 | mMobileRadioActiveTime.writeToParcel(out); |
| 5373 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5374 | } else { |
| 5375 | out.writeInt(0); |
| 5376 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5377 | |
| 5378 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5379 | if (mWifiControllerTime[i] != null) { |
| 5380 | out.writeInt(1); |
| 5381 | mWifiControllerTime[i].writeToParcel(out); |
| 5382 | } else { |
| 5383 | out.writeInt(0); |
| 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5388 | if (mBluetoothControllerTime[i] != null) { |
| 5389 | out.writeInt(1); |
| 5390 | mBluetoothControllerTime[i].writeToParcel(out); |
| 5391 | } else { |
| 5392 | out.writeInt(0); |
| 5393 | } |
| 5394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5395 | } |
| 5396 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5397 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5398 | int numWakelocks = in.readInt(); |
| 5399 | mWakelockStats.clear(); |
| 5400 | for (int j = 0; j < numWakelocks; j++) { |
| 5401 | String wakelockName = in.readString(); |
| 5402 | Uid.Wakelock wakelock = new Wakelock(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5403 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5404 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5405 | } |
| 5406 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5407 | int numSyncs = in.readInt(); |
| 5408 | mSyncStats.clear(); |
| 5409 | for (int j = 0; j < numSyncs; j++) { |
| 5410 | String syncName = in.readString(); |
| 5411 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5412 | mSyncStats.add(syncName, |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5413 | new StopwatchTimer(Uid.this, SYNC, null, timeBase, in)); |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | int numJobs = in.readInt(); |
| 5418 | mJobStats.clear(); |
| 5419 | for (int j = 0; j < numJobs; j++) { |
| 5420 | String jobName = in.readString(); |
| 5421 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5422 | mJobStats.add(jobName, new StopwatchTimer(Uid.this, JOB, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5423 | } |
| 5424 | } |
| 5425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5426 | int numSensors = in.readInt(); |
| 5427 | mSensorStats.clear(); |
| 5428 | for (int k = 0; k < numSensors; k++) { |
| 5429 | int sensorNumber = in.readInt(); |
| 5430 | Uid.Sensor sensor = new Sensor(sensorNumber); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5431 | sensor.readFromParcelLocked(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | mSensorStats.put(sensorNumber, sensor); |
| 5433 | } |
| 5434 | |
| 5435 | int numProcs = in.readInt(); |
| 5436 | mProcessStats.clear(); |
| 5437 | for (int k = 0; k < numProcs; k++) { |
| 5438 | String processName = in.readString(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5439 | Uid.Proc proc = new Proc(processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | proc.readFromParcelLocked(in); |
| 5441 | mProcessStats.put(processName, proc); |
| 5442 | } |
| 5443 | |
| 5444 | int numPkgs = in.readInt(); |
| 5445 | mPackageStats.clear(); |
| 5446 | for (int l = 0; l < numPkgs; l++) { |
| 5447 | String packageName = in.readString(); |
| 5448 | Uid.Pkg pkg = new Pkg(); |
| 5449 | pkg.readFromParcelLocked(in); |
| 5450 | mPackageStats.put(packageName, pkg); |
| 5451 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5452 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5453 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5454 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5455 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5456 | mWifiRunningTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5457 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5458 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5459 | } |
| 5460 | mFullWifiLockOut = false; |
| 5461 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5462 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5463 | mFullWifiLockTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5464 | } else { |
| 5465 | mFullWifiLockTimer = null; |
| 5466 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5467 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5468 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5469 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5470 | mWifiScanTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5471 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5472 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5473 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5474 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5475 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5476 | if (in.readInt() != 0) { |
| 5477 | makeWifiBatchedScanBin(i, in); |
| 5478 | } else { |
| 5479 | mWifiBatchedScanTimer[i] = null; |
| 5480 | } |
| 5481 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5482 | mWifiMulticastEnabled = false; |
| 5483 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5484 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5485 | mWifiMulticastTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5486 | } else { |
| 5487 | mWifiMulticastTimer = null; |
| 5488 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5489 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5490 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5491 | mAudioTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5492 | } else { |
| 5493 | mAudioTurnedOnTimer = null; |
| 5494 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5495 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5496 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5497 | mVideoTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5498 | } else { |
| 5499 | mVideoTurnedOnTimer = null; |
| 5500 | } |
| 5501 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5502 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5503 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5504 | } else { |
| 5505 | mForegroundActivityTimer = null; |
| 5506 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5507 | mProcessState = PROCESS_STATE_NONE; |
| 5508 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5509 | if (in.readInt() != 0) { |
| 5510 | makeProcessState(i, in); |
| 5511 | } else { |
| 5512 | mProcessStateTimer[i] = null; |
| 5513 | } |
| 5514 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5515 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5516 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5517 | } else { |
| 5518 | mVibratorOnTimer = null; |
| 5519 | } |
| 5520 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5521 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5522 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5523 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5524 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5525 | } else { |
| 5526 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5527 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5528 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5529 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5530 | mNetworkPacketActivityCounters |
| 5531 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5532 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5533 | mNetworkByteActivityCounters[i] |
| 5534 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5535 | mNetworkPacketActivityCounters[i] |
| 5536 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5537 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5538 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5539 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5540 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5541 | mNetworkByteActivityCounters = null; |
| 5542 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5543 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5544 | |
| 5545 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5546 | if (in.readInt() != 0) { |
| 5547 | mWifiControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5548 | } else { |
| 5549 | mWifiControllerTime[i] = null; |
| 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5554 | if (in.readInt() != 0) { |
| 5555 | mBluetoothControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5556 | } else { |
| 5557 | mBluetoothControllerTime[i] = null; |
| 5558 | } |
| 5559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | /** |
| 5563 | * The statistics associated with a particular wake lock. |
| 5564 | */ |
| 5565 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 5566 | /** |
| 5567 | * How long (in ms) this uid has been keeping the device partially awake. |
| 5568 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5569 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5570 | |
| 5571 | /** |
| 5572 | * How long (in ms) this uid has been keeping the device fully awake. |
| 5573 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5574 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | |
| 5576 | /** |
| 5577 | * How long (in ms) this uid has had a window keeping the device awake. |
| 5578 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5579 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | |
| 5581 | /** |
| 5582 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 5583 | * proper timer pool from the given BatteryStatsImpl object. |
| 5584 | * |
| 5585 | * @param in the Parcel to be read from. |
| 5586 | * return a new Timer, or null. |
| 5587 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5588 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5589 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5590 | if (in.readInt() == 0) { |
| 5591 | return null; |
| 5592 | } |
| 5593 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5594 | return new StopwatchTimer(Uid.this, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | } |
| 5596 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5597 | boolean reset() { |
| 5598 | boolean wlactive = false; |
| 5599 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5600 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5601 | } |
| 5602 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5603 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5604 | } |
| 5605 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5606 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5607 | } |
| 5608 | if (!wlactive) { |
| 5609 | if (mTimerFull != null) { |
| 5610 | mTimerFull.detach(); |
| 5611 | mTimerFull = null; |
| 5612 | } |
| 5613 | if (mTimerPartial != null) { |
| 5614 | mTimerPartial.detach(); |
| 5615 | mTimerPartial = null; |
| 5616 | } |
| 5617 | if (mTimerWindow != null) { |
| 5618 | mTimerWindow.detach(); |
| 5619 | mTimerWindow = null; |
| 5620 | } |
| 5621 | } |
| 5622 | return !wlactive; |
| 5623 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5624 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5625 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5627 | mPartialTimers, screenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5628 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5629 | mFullTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5631 | mWindowTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | } |
| 5633 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5634 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5635 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 5636 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 5637 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | @Override |
| 5641 | public Timer getWakeTime(int type) { |
| 5642 | switch (type) { |
| 5643 | case WAKE_TYPE_FULL: return mTimerFull; |
| 5644 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 5645 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
| 5646 | default: throw new IllegalArgumentException("type = " + type); |
| 5647 | } |
| 5648 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5649 | |
| 5650 | public StopwatchTimer getStopwatchTimer(int type) { |
| 5651 | StopwatchTimer t; |
| 5652 | switch (type) { |
| 5653 | case WAKE_TYPE_PARTIAL: |
| 5654 | t = mTimerPartial; |
| 5655 | if (t == null) { |
| 5656 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
| 5657 | mPartialTimers, mOnBatteryScreenOffTimeBase); |
| 5658 | mTimerPartial = t; |
| 5659 | } |
| 5660 | return t; |
| 5661 | case WAKE_TYPE_FULL: |
| 5662 | t = mTimerFull; |
| 5663 | if (t == null) { |
| 5664 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
| 5665 | mFullTimers, mOnBatteryTimeBase); |
| 5666 | mTimerFull = t; |
| 5667 | } |
| 5668 | return t; |
| 5669 | case WAKE_TYPE_WINDOW: |
| 5670 | t = mTimerWindow; |
| 5671 | if (t == null) { |
| 5672 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
| 5673 | mWindowTimers, mOnBatteryTimeBase); |
| 5674 | mTimerWindow = t; |
| 5675 | } |
| 5676 | return t; |
| 5677 | default: |
| 5678 | throw new IllegalArgumentException("type=" + type); |
| 5679 | } |
| 5680 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5681 | } |
| 5682 | |
| 5683 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 5684 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5685 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5687 | public Sensor(int handle) { |
| 5688 | mHandle = handle; |
| 5689 | } |
| 5690 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5691 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5692 | if (in.readInt() == 0) { |
| 5693 | return null; |
| 5694 | } |
| 5695 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5696 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5698 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5699 | mSensorTimers.put(mHandle, pool); |
| 5700 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5701 | return new StopwatchTimer(Uid.this, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | } |
| 5703 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5704 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5705 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5706 | mTimer = null; |
| 5707 | return true; |
| 5708 | } |
| 5709 | return false; |
| 5710 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5711 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5712 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 5713 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5714 | } |
| 5715 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5716 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5717 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | @Override |
| 5721 | public Timer getSensorTime() { |
| 5722 | return mTimer; |
| 5723 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5724 | |
| 5725 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | public int getHandle() { |
| 5727 | return mHandle; |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | /** |
| 5732 | * The statistics associated with a particular process. |
| 5733 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5734 | public final class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5736 | * The name of this process. |
| 5737 | */ |
| 5738 | final String mName; |
| 5739 | |
| 5740 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5741 | * Remains true until removed from the stats. |
| 5742 | */ |
| 5743 | boolean mActive = true; |
| 5744 | |
| 5745 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5746 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5747 | */ |
| 5748 | long mUserTime; |
| 5749 | |
| 5750 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5751 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5752 | */ |
| 5753 | long mSystemTime; |
| 5754 | |
| 5755 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5756 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5757 | */ |
| 5758 | long mForegroundTime; |
| 5759 | |
| 5760 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5761 | * Number of times the process has been started. |
| 5762 | */ |
| 5763 | int mStarts; |
| 5764 | |
| 5765 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5766 | * Number of times the process has crashed. |
| 5767 | */ |
| 5768 | int mNumCrashes; |
| 5769 | |
| 5770 | /** |
| 5771 | * Number of times the process has had an ANR. |
| 5772 | */ |
| 5773 | int mNumAnrs; |
| 5774 | |
| 5775 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5776 | * The amount of user time loaded from a previous save. |
| 5777 | */ |
| 5778 | long mLoadedUserTime; |
| 5779 | |
| 5780 | /** |
| 5781 | * The amount of system time loaded from a previous save. |
| 5782 | */ |
| 5783 | long mLoadedSystemTime; |
| 5784 | |
| 5785 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5786 | * The amount of foreground time loaded from a previous save. |
| 5787 | */ |
| 5788 | long mLoadedForegroundTime; |
| 5789 | |
| 5790 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5791 | * The number of times the process has started from a previous save. |
| 5792 | */ |
| 5793 | int mLoadedStarts; |
| 5794 | |
| 5795 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5796 | * 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] | 5797 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5798 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | |
| 5800 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5801 | * 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] | 5802 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5803 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5804 | |
| 5805 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | * The amount of user time when last unplugged. |
| 5807 | */ |
| 5808 | long mUnpluggedUserTime; |
| 5809 | |
| 5810 | /** |
| 5811 | * The amount of system time when last unplugged. |
| 5812 | */ |
| 5813 | long mUnpluggedSystemTime; |
| 5814 | |
| 5815 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5816 | * The amount of foreground time since unplugged. |
| 5817 | */ |
| 5818 | long mUnpluggedForegroundTime; |
| 5819 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5820 | /** |
| 5821 | * The number of times the process has started before unplugged. |
| 5822 | */ |
| 5823 | int mUnpluggedStarts; |
| 5824 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5825 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5826 | * Number of times the process has crashed before unplugged. |
| 5827 | */ |
| 5828 | int mUnpluggedNumCrashes; |
| 5829 | |
| 5830 | /** |
| 5831 | * Number of times the process has had an ANR before unplugged. |
| 5832 | */ |
| 5833 | int mUnpluggedNumAnrs; |
| 5834 | |
| 5835 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5836 | * Current process state. |
| 5837 | */ |
| 5838 | int mProcessState = PROCESS_STATE_NONE; |
| 5839 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5840 | SamplingCounter[] mSpeedBins; |
| 5841 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5842 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5843 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5844 | Proc(String name) { |
| 5845 | mName = name; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5846 | mOnBatteryTimeBase.add(this); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5847 | mSpeedBins = new SamplingCounter[getCpuSpeedSteps()]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5848 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5849 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5850 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | mUnpluggedUserTime = mUserTime; |
| 5852 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5853 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5854 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5855 | mUnpluggedNumCrashes = mNumCrashes; |
| 5856 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | } |
| 5858 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5859 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5861 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5862 | void reset() { |
| 5863 | mUserTime = mSystemTime = mForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5864 | mStarts = mNumCrashes = mNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5865 | mLoadedUserTime = mLoadedSystemTime = mLoadedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5866 | mLoadedStarts = mLoadedNumCrashes = mLoadedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5867 | mUnpluggedUserTime = mUnpluggedSystemTime = mUnpluggedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5868 | mUnpluggedStarts = mUnpluggedNumCrashes = mUnpluggedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5869 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5870 | SamplingCounter c = mSpeedBins[i]; |
| 5871 | if (c != null) { |
| 5872 | c.reset(false); |
| 5873 | } |
| 5874 | } |
| 5875 | mExcessivePower = null; |
| 5876 | } |
| 5877 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5878 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5879 | mActive = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5880 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5881 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5882 | SamplingCounter c = mSpeedBins[i]; |
| 5883 | if (c != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5884 | mOnBatteryTimeBase.remove(c); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5885 | mSpeedBins[i] = null; |
| 5886 | } |
| 5887 | } |
| 5888 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5889 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5890 | public int countExcessivePowers() { |
| 5891 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5894 | public ExcessivePower getExcessivePower(int i) { |
| 5895 | if (mExcessivePower != null) { |
| 5896 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5897 | } |
| 5898 | return null; |
| 5899 | } |
| 5900 | |
| 5901 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5902 | if (mExcessivePower == null) { |
| 5903 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5904 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5905 | ExcessivePower ew = new ExcessivePower(); |
| 5906 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5907 | ew.overTime = overTime; |
| 5908 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5909 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5912 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 5913 | if (mExcessivePower == null) { |
| 5914 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 5915 | } |
| 5916 | ExcessivePower ew = new ExcessivePower(); |
| 5917 | ew.type = ExcessivePower.TYPE_CPU; |
| 5918 | ew.overTime = overTime; |
| 5919 | ew.usedTime = usedTime; |
| 5920 | mExcessivePower.add(ew); |
| 5921 | } |
| 5922 | |
| 5923 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 5924 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5925 | out.writeInt(0); |
| 5926 | return; |
| 5927 | } |
| 5928 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5929 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5930 | out.writeInt(N); |
| 5931 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5932 | ExcessivePower ew = mExcessivePower.get(i); |
| 5933 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5934 | out.writeLong(ew.overTime); |
| 5935 | out.writeLong(ew.usedTime); |
| 5936 | } |
| 5937 | } |
| 5938 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5939 | boolean readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5940 | final int N = in.readInt(); |
| 5941 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5942 | mExcessivePower = null; |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5943 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5944 | } |
| 5945 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5946 | if (N > 10000) { |
| 5947 | Slog.w(TAG, "File corrupt: too many excessive power entries " + N); |
| 5948 | return false; |
| 5949 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 5950 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5951 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5952 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5953 | ExcessivePower ew = new ExcessivePower(); |
| 5954 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5955 | ew.overTime = in.readLong(); |
| 5956 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5957 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5958 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5959 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5960 | } |
| 5961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5962 | void writeToParcelLocked(Parcel out) { |
| 5963 | out.writeLong(mUserTime); |
| 5964 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5965 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5966 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5967 | out.writeInt(mNumCrashes); |
| 5968 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5969 | out.writeLong(mLoadedUserTime); |
| 5970 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5971 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5972 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5973 | out.writeInt(mLoadedNumCrashes); |
| 5974 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5975 | out.writeLong(mUnpluggedUserTime); |
| 5976 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5977 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5978 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5979 | out.writeInt(mUnpluggedNumCrashes); |
| 5980 | out.writeInt(mUnpluggedNumAnrs); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5981 | |
| 5982 | out.writeInt(mSpeedBins.length); |
| 5983 | for (int i = 0; i < mSpeedBins.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5984 | SamplingCounter c = mSpeedBins[i]; |
| 5985 | if (c != null) { |
| 5986 | out.writeInt(1); |
| 5987 | c.writeToParcel(out); |
| 5988 | } else { |
| 5989 | out.writeInt(0); |
| 5990 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5991 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5992 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5993 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | void readFromParcelLocked(Parcel in) { |
| 5997 | mUserTime = in.readLong(); |
| 5998 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5999 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6001 | mNumCrashes = in.readInt(); |
| 6002 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | mLoadedUserTime = in.readLong(); |
| 6004 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6005 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6007 | mLoadedNumCrashes = in.readInt(); |
| 6008 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6009 | mUnpluggedUserTime = in.readLong(); |
| 6010 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6011 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6012 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6013 | mUnpluggedNumCrashes = in.readInt(); |
| 6014 | mUnpluggedNumAnrs = in.readInt(); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6015 | |
| 6016 | int bins = in.readInt(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6017 | int steps = getCpuSpeedSteps(); |
| 6018 | mSpeedBins = new SamplingCounter[bins >= steps ? bins : steps]; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6019 | for (int i = 0; i < bins; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6020 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6021 | mSpeedBins[i] = new SamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6022 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6023 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6024 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6025 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | } |
| 6027 | |
| 6028 | public BatteryStatsImpl getBatteryStats() { |
| 6029 | return BatteryStatsImpl.this; |
| 6030 | } |
| 6031 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6032 | public void addCpuTimeLocked(int utime, int stime, long[] speedStepBins) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | mUserTime += utime; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6034 | mCurStepUserTime += utime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6035 | mSystemTime += stime; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6036 | mCurStepSystemTime += stime; |
| 6037 | |
| 6038 | for (int i = 0; i < mSpeedBins.length && i < speedStepBins.length; i++) { |
| 6039 | long amt = speedStepBins[i]; |
| 6040 | if (amt != 0) { |
| 6041 | SamplingCounter c = mSpeedBins[i]; |
| 6042 | if (c == null) { |
| 6043 | mSpeedBins[i] = c = new SamplingCounter(mOnBatteryTimeBase); |
| 6044 | } |
| 6045 | c.addCountAtomic(speedStepBins[i]); |
| 6046 | } |
| 6047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6048 | } |
| 6049 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6050 | public void addForegroundTimeLocked(long ttime) { |
| 6051 | mForegroundTime += ttime; |
| 6052 | } |
| 6053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6054 | public void incStartsLocked() { |
| 6055 | mStarts++; |
| 6056 | } |
| 6057 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6058 | public void incNumCrashesLocked() { |
| 6059 | mNumCrashes++; |
| 6060 | } |
| 6061 | |
| 6062 | public void incNumAnrsLocked() { |
| 6063 | mNumAnrs++; |
| 6064 | } |
| 6065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6067 | public boolean isActive() { |
| 6068 | return mActive; |
| 6069 | } |
| 6070 | |
| 6071 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6072 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6073 | long val = mUserTime; |
| 6074 | if (which == STATS_CURRENT) { |
| 6075 | val -= mLoadedUserTime; |
| 6076 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6077 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | } |
| 6079 | return val; |
| 6080 | } |
| 6081 | |
| 6082 | @Override |
| 6083 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6084 | long val = mSystemTime; |
| 6085 | if (which == STATS_CURRENT) { |
| 6086 | val -= mLoadedSystemTime; |
| 6087 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6088 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | } |
| 6090 | return val; |
| 6091 | } |
| 6092 | |
| 6093 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6094 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6095 | long val = mForegroundTime; |
| 6096 | if (which == STATS_CURRENT) { |
| 6097 | val -= mLoadedForegroundTime; |
| 6098 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6099 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6100 | } |
| 6101 | return val; |
| 6102 | } |
| 6103 | |
| 6104 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6105 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6106 | int val = mStarts; |
| 6107 | if (which == STATS_CURRENT) { |
| 6108 | val -= mLoadedStarts; |
| 6109 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6110 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | } |
| 6112 | return val; |
| 6113 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6114 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6115 | @Override |
| 6116 | public int getNumCrashes(int which) { |
| 6117 | int val = mNumCrashes; |
| 6118 | if (which == STATS_CURRENT) { |
| 6119 | val -= mLoadedNumCrashes; |
| 6120 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6121 | val -= mUnpluggedNumCrashes; |
| 6122 | } |
| 6123 | return val; |
| 6124 | } |
| 6125 | |
| 6126 | @Override |
| 6127 | public int getNumAnrs(int which) { |
| 6128 | int val = mNumAnrs; |
| 6129 | if (which == STATS_CURRENT) { |
| 6130 | val -= mLoadedNumAnrs; |
| 6131 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6132 | val -= mUnpluggedNumAnrs; |
| 6133 | } |
| 6134 | return val; |
| 6135 | } |
| 6136 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6137 | @Override |
| 6138 | public long getTimeAtCpuSpeedStep(int speedStep, int which) { |
| 6139 | if (speedStep < mSpeedBins.length) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6140 | SamplingCounter c = mSpeedBins[speedStep]; |
| 6141 | return c != null ? c.getCountLocked(which) : 0; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6142 | } else { |
| 6143 | return 0; |
| 6144 | } |
| 6145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
| 6148 | /** |
| 6149 | * The statistics associated with a particular package. |
| 6150 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6151 | public final class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6153 | * 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] | 6154 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6155 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | |
| 6157 | /** |
| 6158 | * The statics we have collected for this package's services. |
| 6159 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6160 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | |
| 6162 | Pkg() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6163 | mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6165 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6166 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6167 | } |
| 6168 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6169 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6171 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6172 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6173 | mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6174 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6176 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6177 | int numWA = in.readInt(); |
| 6178 | mWakeupAlarms.clear(); |
| 6179 | for (int i=0; i<numWA; i++) { |
| 6180 | String tag = in.readString(); |
| 6181 | mWakeupAlarms.put(tag, new Counter(mOnBatteryTimeBase, in)); |
| 6182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6183 | |
| 6184 | int numServs = in.readInt(); |
| 6185 | mServiceStats.clear(); |
| 6186 | for (int m = 0; m < numServs; m++) { |
| 6187 | String serviceName = in.readString(); |
| 6188 | Uid.Pkg.Serv serv = new Serv(); |
| 6189 | mServiceStats.put(serviceName, serv); |
| 6190 | |
| 6191 | serv.readFromParcelLocked(in); |
| 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6196 | int numWA = mWakeupAlarms.size(); |
| 6197 | out.writeInt(numWA); |
| 6198 | for (int i=0; i<numWA; i++) { |
| 6199 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6200 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6201 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6203 | final int NS = mServiceStats.size(); |
| 6204 | out.writeInt(NS); |
| 6205 | for (int i=0; i<NS; i++) { |
| 6206 | out.writeString(mServiceStats.keyAt(i)); |
| 6207 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6208 | serv.writeToParcelLocked(out); |
| 6209 | } |
| 6210 | } |
| 6211 | |
| 6212 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6213 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6214 | return mWakeupAlarms; |
| 6215 | } |
| 6216 | |
| 6217 | public void noteWakeupAlarmLocked(String tag) { |
| 6218 | Counter c = mWakeupAlarms.get(tag); |
| 6219 | if (c == null) { |
| 6220 | c = new Counter(mOnBatteryTimeBase); |
| 6221 | mWakeupAlarms.put(tag, c); |
| 6222 | } |
| 6223 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6227 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6228 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | /** |
| 6232 | * The statistics associated with a particular service. |
| 6233 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6234 | public final class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6235 | /** |
| 6236 | * Total time (ms in battery uptime) the service has been left started. |
| 6237 | */ |
| 6238 | long mStartTime; |
| 6239 | |
| 6240 | /** |
| 6241 | * If service has been started and not yet stopped, this is |
| 6242 | * when it was started. |
| 6243 | */ |
| 6244 | long mRunningSince; |
| 6245 | |
| 6246 | /** |
| 6247 | * True if we are currently running. |
| 6248 | */ |
| 6249 | boolean mRunning; |
| 6250 | |
| 6251 | /** |
| 6252 | * Total number of times startService() has been called. |
| 6253 | */ |
| 6254 | int mStarts; |
| 6255 | |
| 6256 | /** |
| 6257 | * Total time (ms in battery uptime) the service has been left launched. |
| 6258 | */ |
| 6259 | long mLaunchedTime; |
| 6260 | |
| 6261 | /** |
| 6262 | * If service has been launched and not yet exited, this is |
| 6263 | * when it was launched (ms in battery uptime). |
| 6264 | */ |
| 6265 | long mLaunchedSince; |
| 6266 | |
| 6267 | /** |
| 6268 | * True if we are currently launched. |
| 6269 | */ |
| 6270 | boolean mLaunched; |
| 6271 | |
| 6272 | /** |
| 6273 | * Total number times the service has been launched. |
| 6274 | */ |
| 6275 | int mLaunches; |
| 6276 | |
| 6277 | /** |
| 6278 | * The amount of time spent started loaded from a previous save |
| 6279 | * (ms in battery uptime). |
| 6280 | */ |
| 6281 | long mLoadedStartTime; |
| 6282 | |
| 6283 | /** |
| 6284 | * The number of starts loaded from a previous save. |
| 6285 | */ |
| 6286 | int mLoadedStarts; |
| 6287 | |
| 6288 | /** |
| 6289 | * The number of launches loaded from a previous save. |
| 6290 | */ |
| 6291 | int mLoadedLaunches; |
| 6292 | |
| 6293 | /** |
| 6294 | * The amount of time spent started as of the last run (ms |
| 6295 | * in battery uptime). |
| 6296 | */ |
| 6297 | long mLastStartTime; |
| 6298 | |
| 6299 | /** |
| 6300 | * The number of starts as of the last run. |
| 6301 | */ |
| 6302 | int mLastStarts; |
| 6303 | |
| 6304 | /** |
| 6305 | * The number of launches as of the last run. |
| 6306 | */ |
| 6307 | int mLastLaunches; |
| 6308 | |
| 6309 | /** |
| 6310 | * The amount of time spent started when last unplugged (ms |
| 6311 | * in battery uptime). |
| 6312 | */ |
| 6313 | long mUnpluggedStartTime; |
| 6314 | |
| 6315 | /** |
| 6316 | * The number of starts when last unplugged. |
| 6317 | */ |
| 6318 | int mUnpluggedStarts; |
| 6319 | |
| 6320 | /** |
| 6321 | * The number of launches when last unplugged. |
| 6322 | */ |
| 6323 | int mUnpluggedLaunches; |
| 6324 | |
| 6325 | Serv() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6326 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6328 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6329 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 6330 | long baseRealtime) { |
| 6331 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | mUnpluggedStarts = mStarts; |
| 6333 | mUnpluggedLaunches = mLaunches; |
| 6334 | } |
| 6335 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6336 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 6337 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6339 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6340 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6341 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6342 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | void readFromParcelLocked(Parcel in) { |
| 6345 | mStartTime = in.readLong(); |
| 6346 | mRunningSince = in.readLong(); |
| 6347 | mRunning = in.readInt() != 0; |
| 6348 | mStarts = in.readInt(); |
| 6349 | mLaunchedTime = in.readLong(); |
| 6350 | mLaunchedSince = in.readLong(); |
| 6351 | mLaunched = in.readInt() != 0; |
| 6352 | mLaunches = in.readInt(); |
| 6353 | mLoadedStartTime = in.readLong(); |
| 6354 | mLoadedStarts = in.readInt(); |
| 6355 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6356 | mLastStartTime = 0; |
| 6357 | mLastStarts = 0; |
| 6358 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | mUnpluggedStartTime = in.readLong(); |
| 6360 | mUnpluggedStarts = in.readInt(); |
| 6361 | mUnpluggedLaunches = in.readInt(); |
| 6362 | } |
| 6363 | |
| 6364 | void writeToParcelLocked(Parcel out) { |
| 6365 | out.writeLong(mStartTime); |
| 6366 | out.writeLong(mRunningSince); |
| 6367 | out.writeInt(mRunning ? 1 : 0); |
| 6368 | out.writeInt(mStarts); |
| 6369 | out.writeLong(mLaunchedTime); |
| 6370 | out.writeLong(mLaunchedSince); |
| 6371 | out.writeInt(mLaunched ? 1 : 0); |
| 6372 | out.writeInt(mLaunches); |
| 6373 | out.writeLong(mLoadedStartTime); |
| 6374 | out.writeInt(mLoadedStarts); |
| 6375 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | out.writeLong(mUnpluggedStartTime); |
| 6377 | out.writeInt(mUnpluggedStarts); |
| 6378 | out.writeInt(mUnpluggedLaunches); |
| 6379 | } |
| 6380 | |
| 6381 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 6382 | if (!mLaunched) return mLaunchedTime; |
| 6383 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 6384 | } |
| 6385 | |
| 6386 | long getStartTimeToNowLocked(long batteryUptime) { |
| 6387 | if (!mRunning) return mStartTime; |
| 6388 | return mStartTime + batteryUptime - mRunningSince; |
| 6389 | } |
| 6390 | |
| 6391 | public void startLaunchedLocked() { |
| 6392 | if (!mLaunched) { |
| 6393 | mLaunches++; |
| 6394 | mLaunchedSince = getBatteryUptimeLocked(); |
| 6395 | mLaunched = true; |
| 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | public void stopLaunchedLocked() { |
| 6400 | if (mLaunched) { |
| 6401 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 6402 | if (time > 0) { |
| 6403 | mLaunchedTime += time; |
| 6404 | } else { |
| 6405 | mLaunches--; |
| 6406 | } |
| 6407 | mLaunched = false; |
| 6408 | } |
| 6409 | } |
| 6410 | |
| 6411 | public void startRunningLocked() { |
| 6412 | if (!mRunning) { |
| 6413 | mStarts++; |
| 6414 | mRunningSince = getBatteryUptimeLocked(); |
| 6415 | mRunning = true; |
| 6416 | } |
| 6417 | } |
| 6418 | |
| 6419 | public void stopRunningLocked() { |
| 6420 | if (mRunning) { |
| 6421 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 6422 | if (time > 0) { |
| 6423 | mStartTime += time; |
| 6424 | } else { |
| 6425 | mStarts--; |
| 6426 | } |
| 6427 | mRunning = false; |
| 6428 | } |
| 6429 | } |
| 6430 | |
| 6431 | public BatteryStatsImpl getBatteryStats() { |
| 6432 | return BatteryStatsImpl.this; |
| 6433 | } |
| 6434 | |
| 6435 | @Override |
| 6436 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6437 | int val = mLaunches; |
| 6438 | if (which == STATS_CURRENT) { |
| 6439 | val -= mLoadedLaunches; |
| 6440 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6441 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6443 | return val; |
| 6444 | } |
| 6445 | |
| 6446 | @Override |
| 6447 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6448 | long val = getStartTimeToNowLocked(now); |
| 6449 | if (which == STATS_CURRENT) { |
| 6450 | val -= mLoadedStartTime; |
| 6451 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6452 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6454 | return val; |
| 6455 | } |
| 6456 | |
| 6457 | @Override |
| 6458 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6459 | int val = mStarts; |
| 6460 | if (which == STATS_CURRENT) { |
| 6461 | val -= mLoadedStarts; |
| 6462 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6463 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | return val; |
| 6467 | } |
| 6468 | } |
| 6469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | final Serv newServiceStatsLocked() { |
| 6471 | return new Serv(); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | /** |
| 6476 | * Retrieve the statistics object for a particular process, creating |
| 6477 | * if needed. |
| 6478 | */ |
| 6479 | public Proc getProcessStatsLocked(String name) { |
| 6480 | Proc ps = mProcessStats.get(name); |
| 6481 | if (ps == null) { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6482 | ps = new Proc(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | mProcessStats.put(name, ps); |
| 6484 | } |
| 6485 | |
| 6486 | return ps; |
| 6487 | } |
| 6488 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6489 | public void updateProcessStateLocked(String procName, int state, long elapsedRealtimeMs) { |
| 6490 | int procState; |
| 6491 | if (state <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 6492 | procState = PROCESS_STATE_FOREGROUND; |
| 6493 | } else if (state <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 6494 | procState = PROCESS_STATE_ACTIVE; |
| 6495 | } else { |
| 6496 | procState = PROCESS_STATE_RUNNING; |
| 6497 | } |
| 6498 | updateRealProcessStateLocked(procName, procState, elapsedRealtimeMs); |
| 6499 | } |
| 6500 | |
| 6501 | public void updateRealProcessStateLocked(String procName, int procState, |
| 6502 | long elapsedRealtimeMs) { |
| 6503 | Proc proc = getProcessStatsLocked(procName); |
| 6504 | if (proc.mProcessState != procState) { |
| 6505 | boolean changed; |
| 6506 | if (procState < proc.mProcessState) { |
| 6507 | // Has this process become more important? If so, |
| 6508 | // we may need to change the uid if the currrent uid proc state |
| 6509 | // is not as important as what we are now setting. |
| 6510 | changed = mProcessState > procState; |
| 6511 | } else { |
| 6512 | // Has this process become less important? If so, |
| 6513 | // we may need to change the uid if the current uid proc state |
| 6514 | // is the same importance as the old setting. |
| 6515 | changed = mProcessState == proc.mProcessState; |
| 6516 | } |
| 6517 | proc.mProcessState = procState; |
| 6518 | if (changed) { |
| 6519 | // uid's state may have changed; compute what the new state should be. |
| 6520 | int uidProcState = PROCESS_STATE_NONE; |
| 6521 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6522 | proc = mProcessStats.valueAt(ip); |
| 6523 | if (proc.mProcessState < uidProcState) { |
| 6524 | uidProcState = proc.mProcessState; |
| 6525 | } |
| 6526 | } |
| 6527 | updateUidProcessStateLocked(uidProcState, elapsedRealtimeMs); |
| 6528 | } |
| 6529 | } |
| 6530 | } |
| 6531 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6532 | public SparseArray<? extends Pid> getPidStats() { |
| 6533 | return mPids; |
| 6534 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6535 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6536 | public Pid getPidStatsLocked(int pid) { |
| 6537 | Pid p = mPids.get(pid); |
| 6538 | if (p == null) { |
| 6539 | p = new Pid(); |
| 6540 | mPids.put(pid, p); |
| 6541 | } |
| 6542 | return p; |
| 6543 | } |
| 6544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6545 | /** |
| 6546 | * Retrieve the statistics object for a particular service, creating |
| 6547 | * if needed. |
| 6548 | */ |
| 6549 | public Pkg getPackageStatsLocked(String name) { |
| 6550 | Pkg ps = mPackageStats.get(name); |
| 6551 | if (ps == null) { |
| 6552 | ps = new Pkg(); |
| 6553 | mPackageStats.put(name, ps); |
| 6554 | } |
| 6555 | |
| 6556 | return ps; |
| 6557 | } |
| 6558 | |
| 6559 | /** |
| 6560 | * Retrieve the statistics object for a particular service, creating |
| 6561 | * if needed. |
| 6562 | */ |
| 6563 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 6564 | Pkg ps = getPackageStatsLocked(pkg); |
| 6565 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 6566 | if (ss == null) { |
| 6567 | ss = ps.newServiceStatsLocked(); |
| 6568 | ps.mServiceStats.put(serv, ss); |
| 6569 | } |
| 6570 | |
| 6571 | return ss; |
| 6572 | } |
| 6573 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6574 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 6575 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 6576 | timer.readSummaryFromParcelLocked(in); |
| 6577 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6578 | } |
| 6579 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6580 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 6581 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 6582 | timer.readSummaryFromParcelLocked(in); |
| 6583 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6584 | } |
| 6585 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6586 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
| 6587 | Wakelock wl = new Wakelock(); |
| 6588 | mWakelockStats.add(wlName, wl); |
| 6589 | if (in.readInt() != 0) { |
| 6590 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6592 | if (in.readInt() != 0) { |
| 6593 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 6594 | } |
| 6595 | if (in.readInt() != 0) { |
| 6596 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6597 | } |
| 6598 | } |
| 6599 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6600 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | Sensor se = mSensorStats.get(sensor); |
| 6602 | if (se == null) { |
| 6603 | if (!create) { |
| 6604 | return null; |
| 6605 | } |
| 6606 | se = new Sensor(sensor); |
| 6607 | mSensorStats.put(sensor, se); |
| 6608 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6609 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | if (t != null) { |
| 6611 | return t; |
| 6612 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6613 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6614 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6615 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6616 | mSensorTimers.put(sensor, timers); |
| 6617 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6618 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | se.mTimer = t; |
| 6620 | return t; |
| 6621 | } |
| 6622 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6623 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6624 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6625 | if (t != null) { |
| 6626 | t.startRunningLocked(elapsedRealtimeMs); |
| 6627 | } |
| 6628 | } |
| 6629 | |
| 6630 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6631 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6632 | if (t != null) { |
| 6633 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 6638 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6639 | if (t != null) { |
| 6640 | t.startRunningLocked(elapsedRealtimeMs); |
| 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6645 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6646 | if (t != null) { |
| 6647 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6648 | } |
| 6649 | } |
| 6650 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6651 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6652 | Wakelock wl = mWakelockStats.startObject(name); |
| 6653 | if (wl != null) { |
| 6654 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6656 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6657 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6658 | if (p.mWakeNesting++ == 0) { |
| 6659 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 6660 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6661 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6662 | } |
| 6663 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6664 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6665 | Wakelock wl = mWakelockStats.stopObject(name); |
| 6666 | if (wl != null) { |
| 6667 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6668 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6669 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6670 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6671 | if (p != null && p.mWakeNesting > 0) { |
| 6672 | if (p.mWakeNesting-- == 1) { |
| 6673 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 6674 | p.mWakeStartMs = 0; |
| 6675 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6676 | } |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 6681 | Proc p = getProcessStatsLocked(proc); |
| 6682 | if (p != null) { |
| 6683 | p.addExcessiveWake(overTime, usedTime); |
| 6684 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6686 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6687 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 6688 | Proc p = getProcessStatsLocked(proc); |
| 6689 | if (p != null) { |
| 6690 | p.addExcessiveCpu(overTime, usedTime); |
| 6691 | } |
| 6692 | } |
| 6693 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6694 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6695 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6697 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6698 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | } |
| 6700 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6701 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6703 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6704 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6705 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6707 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6708 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6709 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6710 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6711 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6712 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6713 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6714 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6715 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6716 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6717 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6718 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6719 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | public BatteryStatsImpl getBatteryStats() { |
| 6724 | return BatteryStatsImpl.this; |
| 6725 | } |
| 6726 | } |
| 6727 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6728 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6729 | if (systemDir != null) { |
| 6730 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 6731 | new File(systemDir, "batterystats.bin.tmp")); |
| 6732 | } else { |
| 6733 | mFile = null; |
| 6734 | } |
| 6735 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6736 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6737 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 6738 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6739 | mStartCount++; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6740 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6741 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6742 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6743 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6744 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase); |
| 6745 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase); |
| 6746 | mDeviceIdleModeEnabledTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6747 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6748 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6749 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6750 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, |
| 6751 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6752 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6753 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6754 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6755 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, |
| 6756 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6757 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6758 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6759 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6760 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6761 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6762 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 6763 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6764 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6765 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6766 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); |
| 6767 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6768 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6769 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6770 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6771 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase); |
| 6772 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6773 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6774 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6775 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6776 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 6777 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, null, mOnBatteryTimeBase); |
| 6778 | } |
| 6779 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 6780 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, null, |
| 6781 | mOnBatteryTimeBase); |
| 6782 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6783 | mBluetoothOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6784 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6785 | mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6786 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6787 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
| 6788 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6789 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6790 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6791 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 6792 | long realtime = SystemClock.elapsedRealtime() * 1000; |
| 6793 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6794 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6795 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6796 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6797 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6798 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6799 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6800 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6801 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6802 | updateDailyDeadlineLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6803 | } |
| 6804 | |
| 6805 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6806 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6807 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6808 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6809 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6810 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6811 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6812 | readFromParcel(p); |
| 6813 | } |
| 6814 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6815 | public void setPowerProfile(PowerProfile profile) { |
| 6816 | synchronized (this) { |
| 6817 | mPowerProfile = profile; |
| 6818 | } |
| 6819 | } |
| 6820 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6821 | public void setCallback(BatteryCallback cb) { |
| 6822 | mCallback = cb; |
| 6823 | } |
| 6824 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6825 | public void setNumSpeedSteps(int steps) { |
| 6826 | if (sNumSpeedSteps == 0) sNumSpeedSteps = steps; |
| 6827 | } |
| 6828 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6829 | public void setRadioScanningTimeout(long timeout) { |
| 6830 | if (mPhoneSignalScanningTimer != null) { |
| 6831 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 6832 | } |
| 6833 | } |
| 6834 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6835 | public void updateDailyDeadlineLocked() { |
| 6836 | // Get the current time. |
| 6837 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 6838 | Calendar calDeadline = Calendar.getInstance(); |
| 6839 | calDeadline.setTimeInMillis(currentTime); |
| 6840 | |
| 6841 | // Move time up to the next day, ranging from 1am to 3pm. |
| 6842 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 6843 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 6844 | calDeadline.set(Calendar.SECOND, 0); |
| 6845 | calDeadline.set(Calendar.MINUTE, 0); |
| 6846 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 6847 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 6848 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 6849 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 6850 | } |
| 6851 | |
| 6852 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 6853 | long currentTime = System.currentTimeMillis(); |
| 6854 | if (currentTime >= mNextMaxDailyDeadline) { |
| 6855 | recordDailyStatsLocked(); |
| 6856 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 6857 | recordDailyStatsLocked(); |
| 6858 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 6859 | recordDailyStatsLocked(); |
| 6860 | } |
| 6861 | } |
| 6862 | |
| 6863 | public void recordDailyStatsLocked() { |
| 6864 | DailyItem item = new DailyItem(); |
| 6865 | item.mStartTime = mDailyStartTime; |
| 6866 | item.mEndTime = System.currentTimeMillis(); |
| 6867 | boolean hasData = false; |
| 6868 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 6869 | hasData = true; |
| 6870 | item.mDischargeSteps = new LevelStepTracker( |
| 6871 | mDailyDischargeStepTracker.mNumStepDurations, |
| 6872 | mDailyDischargeStepTracker.mStepDurations); |
| 6873 | } |
| 6874 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 6875 | hasData = true; |
| 6876 | item.mChargeSteps = new LevelStepTracker( |
| 6877 | mDailyChargeStepTracker.mNumStepDurations, |
| 6878 | mDailyChargeStepTracker.mStepDurations); |
| 6879 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6880 | if (mDailyPackageChanges != null) { |
| 6881 | hasData = true; |
| 6882 | item.mPackageChanges = mDailyPackageChanges; |
| 6883 | mDailyPackageChanges = null; |
| 6884 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6885 | mDailyDischargeStepTracker.init(); |
| 6886 | mDailyChargeStepTracker.init(); |
| 6887 | updateDailyDeadlineLocked(); |
| 6888 | |
| 6889 | if (hasData) { |
| 6890 | mDailyItems.add(item); |
| 6891 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 6892 | mDailyItems.remove(0); |
| 6893 | } |
| 6894 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 6895 | try { |
| 6896 | XmlSerializer out = new FastXmlSerializer(); |
| 6897 | out.setOutput(memStream, "utf-8"); |
| 6898 | writeDailyItemsLocked(out); |
| 6899 | BackgroundThread.getHandler().post(new Runnable() { |
| 6900 | @Override |
| 6901 | public void run() { |
| 6902 | synchronized (mCheckinFile) { |
| 6903 | FileOutputStream stream = null; |
| 6904 | try { |
| 6905 | stream = mDailyFile.startWrite(); |
| 6906 | memStream.writeTo(stream); |
| 6907 | stream.flush(); |
| 6908 | FileUtils.sync(stream); |
| 6909 | stream.close(); |
| 6910 | mDailyFile.finishWrite(stream); |
| 6911 | } catch (IOException e) { |
| 6912 | Slog.w("BatteryStats", |
| 6913 | "Error writing battery daily items", e); |
| 6914 | mDailyFile.failWrite(stream); |
| 6915 | } |
| 6916 | } |
| 6917 | } |
| 6918 | }); |
| 6919 | } catch (IOException e) { |
| 6920 | } |
| 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 6925 | StringBuilder sb = new StringBuilder(64); |
| 6926 | out.startDocument(null, true); |
| 6927 | out.startTag(null, "daily-items"); |
| 6928 | for (int i=0; i<mDailyItems.size(); i++) { |
| 6929 | final DailyItem dit = mDailyItems.get(i); |
| 6930 | out.startTag(null, "item"); |
| 6931 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 6932 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 6933 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 6934 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6935 | if (dit.mPackageChanges != null) { |
| 6936 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 6937 | PackageChange pc = dit.mPackageChanges.get(j); |
| 6938 | if (pc.mUpdate) { |
| 6939 | out.startTag(null, "upd"); |
| 6940 | out.attribute(null, "pkg", pc.mPackageName); |
| 6941 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 6942 | out.endTag(null, "upd"); |
| 6943 | } else { |
| 6944 | out.startTag(null, "rem"); |
| 6945 | out.attribute(null, "pkg", pc.mPackageName); |
| 6946 | out.endTag(null, "rem"); |
| 6947 | } |
| 6948 | } |
| 6949 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6950 | out.endTag(null, "item"); |
| 6951 | } |
| 6952 | out.endTag(null, "daily-items"); |
| 6953 | out.endDocument(); |
| 6954 | } |
| 6955 | |
| 6956 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 6957 | StringBuilder tmpBuilder) throws IOException { |
| 6958 | if (steps != null) { |
| 6959 | out.startTag(null, tag); |
| 6960 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 6961 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 6962 | out.startTag(null, "s"); |
| 6963 | tmpBuilder.setLength(0); |
| 6964 | steps.encodeEntryAt(i, tmpBuilder); |
| 6965 | out.attribute(null, "v", tmpBuilder.toString()); |
| 6966 | out.endTag(null, "s"); |
| 6967 | } |
| 6968 | out.endTag(null, tag); |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | public void readDailyStatsLocked() { |
| 6973 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 6974 | mDailyItems.clear(); |
| 6975 | FileInputStream stream; |
| 6976 | try { |
| 6977 | stream = mDailyFile.openRead(); |
| 6978 | } catch (FileNotFoundException e) { |
| 6979 | return; |
| 6980 | } |
| 6981 | try { |
| 6982 | XmlPullParser parser = Xml.newPullParser(); |
| 6983 | parser.setInput(stream, null); |
| 6984 | readDailyItemsLocked(parser); |
| 6985 | } catch (XmlPullParserException e) { |
| 6986 | } finally { |
| 6987 | try { |
| 6988 | stream.close(); |
| 6989 | } catch (IOException e) { |
| 6990 | } |
| 6991 | } |
| 6992 | } |
| 6993 | |
| 6994 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 6995 | try { |
| 6996 | int type; |
| 6997 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 6998 | && type != XmlPullParser.END_DOCUMENT) { |
| 6999 | ; |
| 7000 | } |
| 7001 | |
| 7002 | if (type != XmlPullParser.START_TAG) { |
| 7003 | throw new IllegalStateException("no start tag found"); |
| 7004 | } |
| 7005 | |
| 7006 | int outerDepth = parser.getDepth(); |
| 7007 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7008 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7009 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7010 | continue; |
| 7011 | } |
| 7012 | |
| 7013 | String tagName = parser.getName(); |
| 7014 | if (tagName.equals("item")) { |
| 7015 | readDailyItemTagLocked(parser); |
| 7016 | } else { |
| 7017 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7018 | + parser.getName()); |
| 7019 | XmlUtils.skipCurrentTag(parser); |
| 7020 | } |
| 7021 | } |
| 7022 | |
| 7023 | } catch (IllegalStateException e) { |
| 7024 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7025 | } catch (NullPointerException e) { |
| 7026 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7027 | } catch (NumberFormatException e) { |
| 7028 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7029 | } catch (XmlPullParserException e) { |
| 7030 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7031 | } catch (IOException e) { |
| 7032 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7033 | } catch (IndexOutOfBoundsException e) { |
| 7034 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7035 | } |
| 7036 | } |
| 7037 | |
| 7038 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7039 | XmlPullParserException, IOException { |
| 7040 | DailyItem dit = new DailyItem(); |
| 7041 | String attr = parser.getAttributeValue(null, "start"); |
| 7042 | if (attr != null) { |
| 7043 | dit.mStartTime = Long.parseLong(attr); |
| 7044 | } |
| 7045 | attr = parser.getAttributeValue(null, "end"); |
| 7046 | if (attr != null) { |
| 7047 | dit.mEndTime = Long.parseLong(attr); |
| 7048 | } |
| 7049 | int outerDepth = parser.getDepth(); |
| 7050 | int type; |
| 7051 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7052 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7053 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7054 | continue; |
| 7055 | } |
| 7056 | |
| 7057 | String tagName = parser.getName(); |
| 7058 | if (tagName.equals("dis")) { |
| 7059 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7060 | } else if (tagName.equals("chg")) { |
| 7061 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7062 | } else if (tagName.equals("upd")) { |
| 7063 | if (dit.mPackageChanges == null) { |
| 7064 | dit.mPackageChanges = new ArrayList<>(); |
| 7065 | } |
| 7066 | PackageChange pc = new PackageChange(); |
| 7067 | pc.mUpdate = true; |
| 7068 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7069 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7070 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7071 | dit.mPackageChanges.add(pc); |
| 7072 | XmlUtils.skipCurrentTag(parser); |
| 7073 | } else if (tagName.equals("rem")) { |
| 7074 | if (dit.mPackageChanges == null) { |
| 7075 | dit.mPackageChanges = new ArrayList<>(); |
| 7076 | } |
| 7077 | PackageChange pc = new PackageChange(); |
| 7078 | pc.mUpdate = false; |
| 7079 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7080 | dit.mPackageChanges.add(pc); |
| 7081 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7082 | } else { |
| 7083 | Slog.w(TAG, "Unknown element under <item>: " |
| 7084 | + parser.getName()); |
| 7085 | XmlUtils.skipCurrentTag(parser); |
| 7086 | } |
| 7087 | } |
| 7088 | mDailyItems.add(dit); |
| 7089 | } |
| 7090 | |
| 7091 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7092 | String tag) |
| 7093 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7094 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7095 | if (numAttr == null) { |
| 7096 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7097 | XmlUtils.skipCurrentTag(parser); |
| 7098 | return; |
| 7099 | } |
| 7100 | final int num = Integer.parseInt(numAttr); |
| 7101 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7102 | if (isCharge) { |
| 7103 | dit.mChargeSteps = steps; |
| 7104 | } else { |
| 7105 | dit.mDischargeSteps = steps; |
| 7106 | } |
| 7107 | int i = 0; |
| 7108 | int outerDepth = parser.getDepth(); |
| 7109 | int type; |
| 7110 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7111 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7112 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7113 | continue; |
| 7114 | } |
| 7115 | |
| 7116 | String tagName = parser.getName(); |
| 7117 | if ("s".equals(tagName)) { |
| 7118 | if (i < num) { |
| 7119 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7120 | if (valueAttr != null) { |
| 7121 | steps.decodeEntryAt(i, valueAttr); |
| 7122 | i++; |
| 7123 | } |
| 7124 | } |
| 7125 | } else { |
| 7126 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7127 | + parser.getName()); |
| 7128 | XmlUtils.skipCurrentTag(parser); |
| 7129 | } |
| 7130 | } |
| 7131 | steps.mNumStepDurations = i; |
| 7132 | } |
| 7133 | |
| 7134 | @Override |
| 7135 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7136 | int index = mDailyItems.size()-1-daysAgo; |
| 7137 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7138 | } |
| 7139 | |
| 7140 | @Override |
| 7141 | public long getCurrentDailyStartTime() { |
| 7142 | return mDailyStartTime; |
| 7143 | } |
| 7144 | |
| 7145 | @Override |
| 7146 | public long getNextMinDailyDeadline() { |
| 7147 | return mNextMinDailyDeadline; |
| 7148 | } |
| 7149 | |
| 7150 | @Override |
| 7151 | public long getNextMaxDailyDeadline() { |
| 7152 | return mNextMaxDailyDeadline; |
| 7153 | } |
| 7154 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7155 | @Override |
| 7156 | public boolean startIteratingOldHistoryLocked() { |
| 7157 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7158 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7159 | if ((mHistoryIterator = mHistory) == null) { |
| 7160 | return false; |
| 7161 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7162 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7163 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7164 | mReadOverflow = false; |
| 7165 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7166 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7167 | } |
| 7168 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7169 | @Override |
| 7170 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7171 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7172 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7173 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7174 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7175 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7176 | HistoryItem cur = mHistoryIterator; |
| 7177 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7178 | if (!mReadOverflow && !end) { |
| 7179 | Slog.w(TAG, "Old history ends before new history!"); |
| 7180 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7181 | return false; |
| 7182 | } |
| 7183 | out.setTo(cur); |
| 7184 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7185 | if (!mReadOverflow) { |
| 7186 | if (end) { |
| 7187 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7188 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7189 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7190 | pw.println("Histories differ!"); |
| 7191 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7192 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7193 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7194 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7195 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7196 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7197 | } |
| 7198 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7199 | return true; |
| 7200 | } |
| 7201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7202 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7203 | public void finishIteratingOldHistoryLocked() { |
| 7204 | mIteratingHistory = false; |
| 7205 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7206 | mHistoryIterator = null; |
| 7207 | } |
| 7208 | |
| 7209 | public int getHistoryTotalSize() { |
| 7210 | return MAX_HISTORY_BUFFER; |
| 7211 | } |
| 7212 | |
| 7213 | public int getHistoryUsedSize() { |
| 7214 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | @Override |
| 7218 | public boolean startIteratingHistoryLocked() { |
| 7219 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7220 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7221 | if (mHistoryBuffer.dataSize() <= 0) { |
| 7222 | return false; |
| 7223 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7224 | mHistoryBuffer.setDataPosition(0); |
| 7225 | mReadOverflow = false; |
| 7226 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7227 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 7228 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 7229 | mReadHistoryChars = 0; |
| 7230 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7231 | final HistoryTag tag = ent.getKey(); |
| 7232 | final int idx = ent.getValue(); |
| 7233 | mReadHistoryStrings[idx] = tag.string; |
| 7234 | mReadHistoryUids[idx] = tag.uid; |
| 7235 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7236 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7237 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7238 | } |
| 7239 | |
| 7240 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7241 | public int getHistoryStringPoolSize() { |
| 7242 | return mReadHistoryStrings.length; |
| 7243 | } |
| 7244 | |
| 7245 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7246 | public int getHistoryStringPoolBytes() { |
| 7247 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 7248 | // Each string character is 2 bytes. |
| 7249 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 7250 | } |
| 7251 | |
| 7252 | @Override |
| 7253 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7254 | return mReadHistoryStrings[index]; |
| 7255 | } |
| 7256 | |
| 7257 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7258 | public int getHistoryTagPoolUid(int index) { |
| 7259 | return mReadHistoryUids[index]; |
| 7260 | } |
| 7261 | |
| 7262 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7263 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7264 | final int pos = mHistoryBuffer.dataPosition(); |
| 7265 | if (pos == 0) { |
| 7266 | out.clear(); |
| 7267 | } |
| 7268 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7269 | if (end) { |
| 7270 | return false; |
| 7271 | } |
| 7272 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7273 | final long lastRealtime = out.time; |
| 7274 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7275 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7276 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 7277 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7278 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 7279 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7280 | return true; |
| 7281 | } |
| 7282 | |
| 7283 | @Override |
| 7284 | public void finishIteratingHistoryLocked() { |
| 7285 | mIteratingHistory = false; |
| 7286 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7287 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7288 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7289 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7290 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7291 | public long getHistoryBaseTime() { |
| 7292 | return mHistoryBaseTime; |
| 7293 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7294 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7295 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7296 | public int getStartCount() { |
| 7297 | return mStartCount; |
| 7298 | } |
| 7299 | |
| 7300 | public boolean isOnBattery() { |
| 7301 | return mOnBattery; |
| 7302 | } |
| 7303 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7304 | public boolean isCharging() { |
| 7305 | return mCharging; |
| 7306 | } |
| 7307 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7308 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7309 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7310 | } |
| 7311 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7312 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7313 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7314 | mOnBatteryTimeBase.init(uptime, realtime); |
| 7315 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7316 | mRealtime = 0; |
| 7317 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7318 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7319 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7320 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7321 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7322 | void initDischarge() { |
| 7323 | mLowDischargeAmountSinceCharge = 0; |
| 7324 | mHighDischargeAmountSinceCharge = 0; |
| 7325 | mDischargeAmountScreenOn = 0; |
| 7326 | mDischargeAmountScreenOnSinceCharge = 0; |
| 7327 | mDischargeAmountScreenOff = 0; |
| 7328 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7329 | mDischargeStepTracker.init(); |
| 7330 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7331 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7332 | |
| 7333 | public void resetAllStatsCmdLocked() { |
| 7334 | resetAllStatsLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7335 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 7336 | long uptime = mSecUptime * 1000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7337 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 7338 | long realtime = mSecRealtime * 1000; |
| 7339 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 7340 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7341 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7342 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 7343 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7344 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 7345 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 7346 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7347 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7348 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 7349 | mDischargeScreenOffUnplugLevel = 0; |
| 7350 | } else { |
| 7351 | mDischargeScreenOnUnplugLevel = 0; |
| 7352 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 7353 | } |
| 7354 | mDischargeAmountScreenOn = 0; |
| 7355 | mDischargeAmountScreenOff = 0; |
| 7356 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7357 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7358 | } |
| 7359 | |
| 7360 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7361 | mStartCount = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7362 | initTimes(SystemClock.uptimeMillis() * 1000, SystemClock.elapsedRealtime() * 1000); |
| 7363 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7364 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7365 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7366 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7367 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 7368 | mPowerSaveModeEnabledTimer.reset(false); |
| 7369 | mDeviceIdleModeEnabledTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7370 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7371 | mPhoneOnTimer.reset(false); |
| 7372 | mAudioOnTimer.reset(false); |
| 7373 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 7374 | mFlashlightOnTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7375 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7376 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7377 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7378 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7379 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7380 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7381 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7382 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7383 | mNetworkByteActivityCounters[i].reset(false); |
| 7384 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7385 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7386 | mMobileRadioActiveTimer.reset(false); |
| 7387 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7388 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7389 | mMobileRadioActiveUnknownTime.reset(false); |
| 7390 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7391 | mWifiOnTimer.reset(false); |
| 7392 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7393 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7394 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7395 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7396 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7397 | mWifiSupplStateTimer[i].reset(false); |
| 7398 | } |
| 7399 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7400 | mWifiSignalStrengthsTimer[i].reset(false); |
| 7401 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7402 | mBluetoothOnTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7403 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7404 | mBluetoothStateTimer[i].reset(false); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7405 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 7406 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 7407 | mBluetoothActivityCounters[i].reset(false); |
| 7408 | mWifiActivityCounters[i].reset(false); |
| 7409 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7410 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7411 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7412 | for (int i=0; i<mUidStats.size(); i++) { |
| 7413 | if (mUidStats.valueAt(i).reset()) { |
| 7414 | mUidStats.remove(mUidStats.keyAt(i)); |
| 7415 | i--; |
| 7416 | } |
| 7417 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7418 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7419 | if (mKernelWakelockStats.size() > 0) { |
| 7420 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7421 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7422 | } |
| 7423 | mKernelWakelockStats.clear(); |
| 7424 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7425 | |
| 7426 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7427 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 7428 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7429 | } |
| 7430 | mWakeupReasonStats.clear(); |
| 7431 | } |
| 7432 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 7433 | mLastHistoryStepDetails = null; |
| 7434 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 7435 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 7436 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 7437 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 7438 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 7439 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 7440 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 7441 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 7442 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 7443 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 7444 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7445 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7446 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7447 | clearHistoryLocked(); |
| 7448 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7449 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7450 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7451 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7452 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 7453 | // Not recording process starts/stops. |
| 7454 | continue; |
| 7455 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7456 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7457 | if (active == null) { |
| 7458 | continue; |
| 7459 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7460 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 7461 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7462 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7463 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 7464 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7465 | } |
| 7466 | } |
| 7467 | } |
| 7468 | } |
| 7469 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7470 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7471 | if (oldScreenOn) { |
| 7472 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 7473 | if (diff > 0) { |
| 7474 | mDischargeAmountScreenOn += diff; |
| 7475 | mDischargeAmountScreenOnSinceCharge += diff; |
| 7476 | } |
| 7477 | } else { |
| 7478 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 7479 | if (diff > 0) { |
| 7480 | mDischargeAmountScreenOff += diff; |
| 7481 | mDischargeAmountScreenOffSinceCharge += diff; |
| 7482 | } |
| 7483 | } |
| 7484 | if (newScreenOn) { |
| 7485 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 7486 | mDischargeScreenOffUnplugLevel = 0; |
| 7487 | } else { |
| 7488 | mDischargeScreenOnUnplugLevel = 0; |
| 7489 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 7490 | } |
| 7491 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7492 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7493 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7494 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7495 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 7496 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7497 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7498 | } |
| 7499 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7500 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 7501 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 7502 | |
| 7503 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 7504 | |
| 7505 | private static final int NETWORK_STATS_LAST = 0; |
| 7506 | private static final int NETWORK_STATS_NEXT = 1; |
| 7507 | private static final int NETWORK_STATS_DELTA = 2; |
| 7508 | |
| 7509 | private final NetworkStats[] mMobileNetworkStats = new NetworkStats[] { |
| 7510 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7511 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7512 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7513 | }; |
| 7514 | |
| 7515 | private final NetworkStats[] mWifiNetworkStats = new NetworkStats[] { |
| 7516 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7517 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7518 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7519 | }; |
| 7520 | |
| 7521 | /** |
| 7522 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 7523 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 7524 | */ |
| 7525 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 7526 | NetworkStats[] networkStatsBuffer) |
| 7527 | throws IOException { |
| 7528 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 7529 | false)) { |
| 7530 | return null; |
| 7531 | } |
| 7532 | |
| 7533 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 7534 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 7535 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 7536 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 7537 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 7538 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 7539 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 7540 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 7541 | } |
| 7542 | |
| 7543 | /** |
| 7544 | * Distribute WiFi energy info and network traffic to apps. |
| 7545 | * @param info The energy information from the WiFi controller. |
| 7546 | */ |
| 7547 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7548 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 7549 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7550 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7551 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 7552 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 7553 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7554 | } catch (IOException e) { |
| 7555 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 7556 | return; |
| 7557 | } |
| 7558 | |
| 7559 | if (!mOnBatteryInternal) { |
| 7560 | return; |
| 7561 | } |
| 7562 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7563 | SparseLongArray rxPackets = new SparseLongArray(); |
| 7564 | SparseLongArray txPackets = new SparseLongArray(); |
| 7565 | long totalTxPackets = 0; |
| 7566 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7567 | if (delta != null) { |
| 7568 | final int size = delta.size(); |
| 7569 | for (int i = 0; i < size; i++) { |
| 7570 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7571 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7572 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7573 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7574 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7575 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7576 | } |
| 7577 | |
| 7578 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7579 | continue; |
| 7580 | } |
| 7581 | |
| 7582 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7583 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 7584 | entry.rxPackets); |
| 7585 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 7586 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7587 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 7588 | txPackets.put(u.getUid(), entry.txPackets); |
| 7589 | |
| 7590 | // Sum the total number of packets so that the Rx Power and Tx Power can |
| 7591 | // be evenly distributed amongst the apps. |
| 7592 | totalRxPackets += entry.rxPackets; |
| 7593 | totalTxPackets += entry.txPackets; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7594 | |
| 7595 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7596 | entry.rxBytes); |
| 7597 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7598 | entry.txBytes); |
| 7599 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7600 | entry.rxPackets); |
| 7601 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7602 | entry.txPackets); |
| 7603 | } |
| 7604 | } |
| 7605 | |
| 7606 | if (info != null) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7607 | mHasWifiEnergyReporting = true; |
| 7608 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7609 | // Measured in mAms |
| 7610 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 7611 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 7612 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 7613 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 7614 | |
| 7615 | long leftOverRxTimeMs = rxTimeMs; |
| 7616 | |
| 7617 | if (DEBUG_ENERGY) { |
| 7618 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 7619 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 7620 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 7621 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 7622 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 7623 | } |
| 7624 | |
| 7625 | long totalWifiLockTimeMs = 0; |
| 7626 | long totalScanTimeMs = 0; |
| 7627 | |
| 7628 | // On the first pass, collect some totals so that we can normalize power |
| 7629 | // calculations if we need to. |
| 7630 | final int uidStatsSize = mUidStats.size(); |
| 7631 | for (int i = 0; i < uidStatsSize; i++) { |
| 7632 | final Uid uid = mUidStats.valueAt(i); |
| 7633 | |
| 7634 | // Sum the total scan power for all apps. |
| 7635 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7636 | elapsedRealtimeMs * 1000) / 1000; |
| 7637 | |
| 7638 | // Sum the total time holding wifi lock for all apps. |
| 7639 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7640 | elapsedRealtimeMs * 1000) / 1000; |
| 7641 | } |
| 7642 | |
| 7643 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 7644 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 7645 | + rxTimeMs + " ms). Normalizing scan time."); |
| 7646 | } |
| 7647 | |
| 7648 | // Actually assign and distribute power usage to apps. |
| 7649 | for (int i = 0; i < uidStatsSize; i++) { |
| 7650 | final Uid uid = mUidStats.valueAt(i); |
| 7651 | |
| 7652 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7653 | elapsedRealtimeMs * 1000) / 1000; |
| 7654 | if (scanTimeSinceMarkMs > 0) { |
| 7655 | // Set the new mark so that next time we get new data since this point. |
| 7656 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 7657 | |
| 7658 | if (totalScanTimeMs > rxTimeMs) { |
| 7659 | // Our total scan time is more than the reported Rx time. |
| 7660 | // This is possible because the cost of a scan is approximate. |
| 7661 | // Let's normalize the result so that we evenly blame each app |
| 7662 | // scanning. |
| 7663 | // |
| 7664 | // This means that we may have apps that received packets not be blamed |
| 7665 | // for this, but this is fine as scans are relatively more expensive. |
| 7666 | scanTimeSinceMarkMs = (rxTimeMs * scanTimeSinceMarkMs) / totalScanTimeMs; |
| 7667 | } |
| 7668 | |
| 7669 | if (DEBUG_ENERGY) { |
| 7670 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": " |
| 7671 | + scanTimeSinceMarkMs + " ms)"); |
| 7672 | } |
| 7673 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, scanTimeSinceMarkMs); |
| 7674 | leftOverRxTimeMs -= scanTimeSinceMarkMs; |
| 7675 | } |
| 7676 | |
| 7677 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 7678 | // lock. |
| 7679 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7680 | elapsedRealtimeMs * 1000) / 1000; |
| 7681 | if (wifiLockTimeSinceMarkMs > 0) { |
| 7682 | // Set the new mark so that next time we get new data since this point. |
| 7683 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 7684 | |
| 7685 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 7686 | / totalWifiLockTimeMs; |
| 7687 | if (DEBUG_ENERGY) { |
| 7688 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 7689 | + myIdleTimeMs + " ms"); |
| 7690 | } |
| 7691 | uid.noteWifiControllerActivityLocked(CONTROLLER_IDLE_TIME, myIdleTimeMs); |
| 7692 | } |
| 7693 | } |
| 7694 | |
| 7695 | if (DEBUG_ENERGY) { |
| 7696 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 7697 | } |
| 7698 | |
| 7699 | // Distribute the Tx power appropriately between all apps that transmitted packets. |
| 7700 | for (int i = 0; i < txPackets.size(); i++) { |
| 7701 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 7702 | final long myTxTimeMs = (txPackets.valueAt(i) * txTimeMs) / totalTxPackets; |
| 7703 | if (DEBUG_ENERGY) { |
| 7704 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 7705 | } |
| 7706 | uid.noteWifiControllerActivityLocked(CONTROLLER_TX_TIME, myTxTimeMs); |
| 7707 | } |
| 7708 | |
| 7709 | // Distribute the remaining Rx power appropriately between all apps that received |
| 7710 | // packets. |
| 7711 | for (int i = 0; i < rxPackets.size(); i++) { |
| 7712 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 7713 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 7714 | if (DEBUG_ENERGY) { |
| 7715 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 7716 | } |
| 7717 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, myRxTimeMs); |
| 7718 | } |
| 7719 | |
| 7720 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 7721 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7722 | // Update WiFi controller stats. |
| 7723 | mWifiActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7724 | info.getControllerRxTimeMillis()); |
| 7725 | mWifiActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7726 | info.getControllerTxTimeMillis()); |
| 7727 | mWifiActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7728 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7729 | |
| 7730 | final double powerDrainMaMs; |
| 7731 | if (mPowerProfile.getAveragePower( |
| 7732 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) == 0) { |
| 7733 | powerDrainMaMs = 0.0; |
| 7734 | } else { |
| 7735 | powerDrainMaMs = info.getControllerEnergyUsed() |
| 7736 | / mPowerProfile.getAveragePower( |
| 7737 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE); |
| 7738 | } |
| 7739 | mWifiActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked((long) powerDrainMaMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7740 | } |
| 7741 | } |
| 7742 | |
| 7743 | /** |
| 7744 | * Distribute Cell radio energy info and network traffic to apps. |
| 7745 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7746 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs) { |
| 7747 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7748 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7749 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 7750 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 7751 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7752 | } catch (IOException e) { |
| 7753 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 7754 | return; |
| 7755 | } |
| 7756 | |
| 7757 | if (delta == null || !mOnBatteryInternal) { |
| 7758 | return; |
| 7759 | } |
| 7760 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7761 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 7762 | elapsedRealtimeMs * 1000); |
| 7763 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7764 | long totalPackets = delta.getTotalPackets(); |
| 7765 | |
| 7766 | final int size = delta.size(); |
| 7767 | for (int i = 0; i < size; i++) { |
| 7768 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7769 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7770 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7771 | continue; |
| 7772 | } |
| 7773 | |
| 7774 | if (DEBUG_ENERGY) { |
| 7775 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 7776 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7777 | + " txPackets=" + entry.txPackets); |
| 7778 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7779 | |
| 7780 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7781 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 7782 | entry.rxPackets); |
| 7783 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 7784 | entry.txPackets); |
| 7785 | |
| 7786 | if (radioTime > 0) { |
| 7787 | // Distribute total radio active time in to this app. |
| 7788 | long appPackets = entry.rxPackets + entry.txPackets; |
| 7789 | long appRadioTime = (radioTime*appPackets)/totalPackets; |
| 7790 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 7791 | // Remove this app from the totals, so that we don't lose any time |
| 7792 | // due to rounding. |
| 7793 | radioTime -= appRadioTime; |
| 7794 | totalPackets -= appPackets; |
| 7795 | } |
| 7796 | |
| 7797 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 7798 | entry.rxBytes); |
| 7799 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 7800 | entry.txBytes); |
| 7801 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 7802 | entry.rxPackets); |
| 7803 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 7804 | entry.txPackets); |
| 7805 | } |
| 7806 | |
| 7807 | if (radioTime > 0) { |
| 7808 | // Whoops, there is some radio time we can't blame on an app! |
| 7809 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 7810 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 7811 | } |
| 7812 | } |
| 7813 | |
| 7814 | /** |
| 7815 | * Distribute Bluetooth energy info and network traffic to apps. |
| 7816 | * @param info The energy information from the bluetooth controller. |
| 7817 | */ |
| 7818 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7819 | if (info != null && mOnBatteryInternal && false) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7820 | mHasBluetoothEnergyReporting = true; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7821 | mBluetoothActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7822 | info.getControllerRxTimeMillis()); |
| 7823 | mBluetoothActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7824 | info.getControllerTxTimeMillis()); |
| 7825 | mBluetoothActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7826 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7827 | mBluetoothActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7828 | info.getControllerEnergyUsed()); |
| 7829 | } |
| 7830 | } |
| 7831 | |
| 7832 | /** |
| 7833 | * Read and distribute kernel wake lock use across apps. |
| 7834 | */ |
| 7835 | public void updateKernelWakelocksLocked() { |
| 7836 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 7837 | mTmpWakelockStats); |
| 7838 | if (wakelockStats == null) { |
| 7839 | // Not crashing might make board bringup easier. |
| 7840 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 7841 | return; |
| 7842 | } |
| 7843 | |
| 7844 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 7845 | String name = ent.getKey(); |
| 7846 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 7847 | |
| 7848 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 7849 | if (kwlt == null) { |
| 7850 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, |
| 7851 | true /* track reported val */); |
| 7852 | mKernelWakelockStats.put(name, kwlt); |
| 7853 | } |
| 7854 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 7855 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 7856 | kwlt.setUpdateVersion(kws.mVersion); |
| 7857 | } |
| 7858 | |
| 7859 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 7860 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 7861 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 7862 | SamplingTimer st = ent.getValue(); |
| 7863 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 7864 | st.setStale(); |
| 7865 | } |
| 7866 | } |
| 7867 | } |
| 7868 | } |
| 7869 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7870 | boolean setChargingLocked(boolean charging) { |
| 7871 | if (mCharging != charging) { |
| 7872 | mCharging = charging; |
| 7873 | if (charging) { |
| 7874 | mHistoryCur.states |= HistoryItem.STATE_CHARGING_FLAG; |
| 7875 | } else { |
| 7876 | mHistoryCur.states &= ~HistoryItem.STATE_CHARGING_FLAG; |
| 7877 | } |
| 7878 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 7879 | return true; |
| 7880 | } |
| 7881 | return false; |
| 7882 | } |
| 7883 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7884 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 7885 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7886 | boolean doWrite = false; |
| 7887 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 7888 | m.arg1 = onBattery ? 1 : 0; |
| 7889 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7890 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7891 | final long uptime = mSecUptime * 1000; |
| 7892 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7893 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7894 | if (onBattery) { |
| 7895 | // We will reset our status if we are unplugging after the |
| 7896 | // battery was last full, or the level is at 100, or |
| 7897 | // we have gone through a significant charge (from a very low |
| 7898 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7899 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 7900 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7901 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 7902 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 7903 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 7904 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 7905 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 7906 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 7907 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 7908 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7909 | // Before we write, collect a snapshot of the final aggregated |
| 7910 | // stats to be reported in the next checkin. Only do this if we have |
| 7911 | // a sufficient amount of data to make it interesting. |
| 7912 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 7913 | final Parcel parcel = Parcel.obtain(); |
| 7914 | writeSummaryToParcel(parcel, true); |
| 7915 | BackgroundThread.getHandler().post(new Runnable() { |
| 7916 | @Override public void run() { |
| 7917 | synchronized (mCheckinFile) { |
| 7918 | FileOutputStream stream = null; |
| 7919 | try { |
| 7920 | stream = mCheckinFile.startWrite(); |
| 7921 | stream.write(parcel.marshall()); |
| 7922 | stream.flush(); |
| 7923 | FileUtils.sync(stream); |
| 7924 | stream.close(); |
| 7925 | mCheckinFile.finishWrite(stream); |
| 7926 | } catch (IOException e) { |
| 7927 | Slog.w("BatteryStats", |
| 7928 | "Error writing checkin battery statistics", e); |
| 7929 | mCheckinFile.failWrite(stream); |
| 7930 | } finally { |
| 7931 | parcel.recycle(); |
| 7932 | } |
| 7933 | } |
| 7934 | } |
| 7935 | }); |
| 7936 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7937 | doWrite = true; |
| 7938 | resetAllStatsLocked(); |
| 7939 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7940 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7941 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7942 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7943 | if (mCharging) { |
| 7944 | setChargingLocked(false); |
| 7945 | } |
| 7946 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 7947 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7948 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 7949 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7950 | mDischargeStepTracker.clearTime(); |
| 7951 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7952 | mInitStepMode = mCurStepMode; |
| 7953 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7954 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7955 | mHistoryCur.batteryLevel = (byte)level; |
| 7956 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 7957 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 7958 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7959 | if (reset) { |
| 7960 | mRecordingHistory = true; |
| 7961 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 7962 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7963 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7964 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7965 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7966 | mDischargeScreenOnUnplugLevel = level; |
| 7967 | mDischargeScreenOffUnplugLevel = 0; |
| 7968 | } else { |
| 7969 | mDischargeScreenOnUnplugLevel = 0; |
| 7970 | mDischargeScreenOffUnplugLevel = level; |
| 7971 | } |
| 7972 | mDischargeAmountScreenOn = 0; |
| 7973 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7974 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7975 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7976 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 7977 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7978 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7979 | mHistoryCur.batteryLevel = (byte)level; |
| 7980 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 7981 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 7982 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7983 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7984 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7985 | if (level < mDischargeUnplugLevel) { |
| 7986 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 7987 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 7988 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7989 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 7990 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7991 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7992 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 7993 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7994 | mInitStepMode = mCurStepMode; |
| 7995 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7996 | } |
| 7997 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 7998 | if (mFile != null) { |
| 7999 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8000 | } |
| 8001 | } |
| 8002 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8003 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8004 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 8005 | boolean reset) { |
| 8006 | mRecordingHistory = true; |
| 8007 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | a7d0d55 | 2014-09-12 17:15:52 -0700 | [diff] [blame] | 8008 | mLastRecordedClockTime = mHistoryCur.currentTime; |
| 8009 | mLastRecordedClockRealtime = elapsedRealtimeMs; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8010 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 8011 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8012 | mHistoryCur); |
| 8013 | mHistoryCur.currentTime = 0; |
| 8014 | if (reset) { |
| 8015 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 8016 | } |
| 8017 | } |
| 8018 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 8019 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 8020 | final long uptimeMs) { |
| 8021 | if (mRecordingHistory) { |
| 8022 | mHistoryCur.currentTime = currentTime; |
Dianne Hackborn | a7d0d55 | 2014-09-12 17:15:52 -0700 | [diff] [blame] | 8023 | mLastRecordedClockTime = currentTime; |
| 8024 | mLastRecordedClockRealtime = elapsedRealtimeMs; |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 8025 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 8026 | mHistoryCur); |
| 8027 | mHistoryCur.currentTime = 0; |
| 8028 | } |
| 8029 | } |
| 8030 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8031 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 8032 | if (mRecordingHistory) { |
| 8033 | mHistoryCur.currentTime = System.currentTimeMillis(); |
| 8034 | mLastRecordedClockTime = mHistoryCur.currentTime; |
| 8035 | mLastRecordedClockRealtime = elapsedRealtimeMs; |
| 8036 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 8037 | mHistoryCur); |
| 8038 | mHistoryCur.currentTime = 0; |
| 8039 | } |
| 8040 | } |
| 8041 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8042 | private void scheduleSyncExternalStatsLocked() { |
| 8043 | if (mExternalSync != null) { |
| 8044 | mExternalSync.scheduleSync(); |
| 8045 | } |
| 8046 | } |
| 8047 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8048 | // 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] | 8049 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8050 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8051 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8052 | int temp, int volt) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8053 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 8054 | final long uptime = SystemClock.uptimeMillis(); |
| 8055 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8056 | if (!mHaveBatteryLevel) { |
| 8057 | mHaveBatteryLevel = true; |
| 8058 | // We start out assuming that the device is plugged in (not |
| 8059 | // on battery). If our first report is now that we are indeed |
| 8060 | // plugged in, then twiddle our state to correctly reflect that |
| 8061 | // since we won't be going through the full setOnBattery(). |
| 8062 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8063 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8064 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8065 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8066 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8067 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8068 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8069 | // Always start out assuming charging, that will be updated later. |
| 8070 | mHistoryCur.states |= HistoryItem.STATE_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8071 | mHistoryCur.batteryStatus = (byte)status; |
| 8072 | mHistoryCur.batteryLevel = (byte)level; |
| 8073 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 8074 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8075 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8076 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 8077 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 8078 | } |
| 8079 | int oldStatus = mHistoryCur.batteryStatus; |
| 8080 | if (onBattery) { |
| 8081 | mDischargeCurrentLevel = level; |
| 8082 | if (!mRecordingHistory) { |
| 8083 | mRecordingHistory = true; |
| 8084 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 8085 | } |
| 8086 | } else if (level < 96) { |
| 8087 | if (!mRecordingHistory) { |
| 8088 | mRecordingHistory = true; |
| 8089 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8090 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8091 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8092 | mCurrentBatteryLevel = level; |
| 8093 | if (mDischargePlugLevel < 0) { |
| 8094 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8095 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8096 | if (onBattery != mOnBattery) { |
| 8097 | mHistoryCur.batteryLevel = (byte)level; |
| 8098 | mHistoryCur.batteryStatus = (byte)status; |
| 8099 | mHistoryCur.batteryHealth = (byte)health; |
| 8100 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8101 | mHistoryCur.batteryTemperature = (short)temp; |
| 8102 | mHistoryCur.batteryVoltage = (char)volt; |
| 8103 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 8104 | } else { |
| 8105 | boolean changed = false; |
| 8106 | if (mHistoryCur.batteryLevel != level) { |
| 8107 | mHistoryCur.batteryLevel = (byte)level; |
| 8108 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8109 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8110 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 8111 | // which will pull external stats. |
| 8112 | scheduleSyncExternalStatsLocked(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8113 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8114 | if (mHistoryCur.batteryStatus != status) { |
| 8115 | mHistoryCur.batteryStatus = (byte)status; |
| 8116 | changed = true; |
| 8117 | } |
| 8118 | if (mHistoryCur.batteryHealth != health) { |
| 8119 | mHistoryCur.batteryHealth = (byte)health; |
| 8120 | changed = true; |
| 8121 | } |
| 8122 | if (mHistoryCur.batteryPlugType != plugType) { |
| 8123 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8124 | changed = true; |
| 8125 | } |
| 8126 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 8127 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 8128 | mHistoryCur.batteryTemperature = (short)temp; |
| 8129 | changed = true; |
| 8130 | } |
| 8131 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 8132 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 8133 | mHistoryCur.batteryVoltage = (char)volt; |
| 8134 | changed = true; |
| 8135 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8136 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 8137 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 8138 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 8139 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8140 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8141 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 8142 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8143 | modeBits, elapsedRealtime); |
| 8144 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8145 | modeBits, elapsedRealtime); |
| 8146 | mLastDischargeStepLevel = level; |
| 8147 | mMinDischargeStepLevel = level; |
| 8148 | mInitStepMode = mCurStepMode; |
| 8149 | mModStepMode = 0; |
| 8150 | } |
| 8151 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8152 | if (level >= 90) { |
| 8153 | // If the battery level is at least 90%, always consider the device to be |
| 8154 | // charging even if it happens to go down a level. |
| 8155 | changed |= setChargingLocked(true); |
| 8156 | mLastChargeStepLevel = level; |
| 8157 | } if (!mCharging) { |
| 8158 | if (mLastChargeStepLevel < level) { |
| 8159 | // We have not reporting that we are charging, but the level has now |
| 8160 | // gone up, so consider the state to be charging. |
| 8161 | changed |= setChargingLocked(true); |
| 8162 | mLastChargeStepLevel = level; |
| 8163 | } |
| 8164 | } else { |
| 8165 | if (mLastChargeStepLevel > level) { |
| 8166 | // We had reported that the device was charging, but here we are with |
| 8167 | // power connected and the level going down. Looks like the current |
| 8168 | // power supplied isn't enough, so consider the device to now be |
| 8169 | // discharging. |
| 8170 | changed |= setChargingLocked(false); |
| 8171 | mLastChargeStepLevel = level; |
| 8172 | } |
| 8173 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8174 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 8175 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8176 | modeBits, elapsedRealtime); |
| 8177 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8178 | modeBits, elapsedRealtime); |
| 8179 | mLastChargeStepLevel = level; |
| 8180 | mMaxChargeStepLevel = level; |
| 8181 | mInitStepMode = mCurStepMode; |
| 8182 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8183 | } |
| 8184 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8185 | if (changed) { |
| 8186 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 8187 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8188 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8189 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 8190 | // We don't record history while we are plugged in and fully charged. |
| 8191 | // The next time we are unplugged, history will be cleared. |
| 8192 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 8193 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8194 | } |
| 8195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8196 | public long getAwakeTimeBattery() { |
| 8197 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 8198 | } |
| 8199 | |
| 8200 | public long getAwakeTimePlugged() { |
| 8201 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 8202 | } |
| 8203 | |
| 8204 | @Override |
| 8205 | public long computeUptime(long curTime, int which) { |
| 8206 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8207 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8208 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8209 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8210 | } |
| 8211 | return 0; |
| 8212 | } |
| 8213 | |
| 8214 | @Override |
| 8215 | public long computeRealtime(long curTime, int which) { |
| 8216 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8217 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8218 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8219 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8220 | } |
| 8221 | return 0; |
| 8222 | } |
| 8223 | |
| 8224 | @Override |
| 8225 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8226 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8227 | } |
| 8228 | |
| 8229 | @Override |
| 8230 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8231 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | } |
| 8233 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8234 | @Override |
| 8235 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 8236 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 8237 | } |
| 8238 | |
| 8239 | @Override |
| 8240 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 8241 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8242 | } |
| 8243 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8244 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 8245 | // For now we'll do a simple average across all steps. |
| 8246 | if (numSteps <= 0) { |
| 8247 | return -1; |
| 8248 | } |
| 8249 | long total = 0; |
| 8250 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8251 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8252 | } |
| 8253 | return total / numSteps; |
| 8254 | /* |
| 8255 | long[] buckets = new long[numSteps]; |
| 8256 | int numBuckets = 0; |
| 8257 | int numToAverage = 4; |
| 8258 | int i = 0; |
| 8259 | while (i < numSteps) { |
| 8260 | long totalTime = 0; |
| 8261 | int num = 0; |
| 8262 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8263 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8264 | num++; |
| 8265 | } |
| 8266 | buckets[numBuckets] = totalTime / num; |
| 8267 | numBuckets++; |
| 8268 | numToAverage *= 2; |
| 8269 | i += num; |
| 8270 | } |
| 8271 | if (numBuckets < 1) { |
| 8272 | return -1; |
| 8273 | } |
| 8274 | long averageTime = buckets[numBuckets-1]; |
| 8275 | for (i=numBuckets-2; i>=0; i--) { |
| 8276 | averageTime = (averageTime + buckets[i]) / 2; |
| 8277 | } |
| 8278 | return averageTime; |
| 8279 | */ |
| 8280 | } |
| 8281 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8282 | @Override |
| 8283 | public long computeBatteryTimeRemaining(long curTime) { |
| 8284 | if (!mOnBattery) { |
| 8285 | return -1; |
| 8286 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8287 | /* Simple implementation just looks at the average discharge per level across the |
| 8288 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8289 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 8290 | if (discharge < 2) { |
| 8291 | return -1; |
| 8292 | } |
| 8293 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 8294 | if (duration < 1000*1000) { |
| 8295 | return -1; |
| 8296 | } |
| 8297 | long usPerLevel = duration/discharge; |
| 8298 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8299 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8300 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8301 | return -1; |
| 8302 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8303 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8304 | if (msPerLevel <= 0) { |
| 8305 | return -1; |
| 8306 | } |
| 8307 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8308 | } |
| 8309 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8310 | @Override |
| 8311 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 8312 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8313 | } |
| 8314 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8315 | @Override |
| 8316 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 8317 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8318 | } |
| 8319 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8320 | @Override |
| 8321 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8322 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8323 | // Not yet working. |
| 8324 | return -1; |
| 8325 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8326 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8327 | int curLevel = mCurrentBatteryLevel; |
| 8328 | int plugLevel = mDischargePlugLevel; |
| 8329 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 8330 | return -1; |
| 8331 | } |
| 8332 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 8333 | if (duration < 1000*1000) { |
| 8334 | return -1; |
| 8335 | } |
| 8336 | long usPerLevel = duration/(curLevel-plugLevel); |
| 8337 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8338 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8339 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8340 | return -1; |
| 8341 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8342 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8343 | if (msPerLevel <= 0) { |
| 8344 | return -1; |
| 8345 | } |
| 8346 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8347 | } |
| 8348 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8349 | @Override |
| 8350 | public LevelStepTracker getChargeLevelStepTracker() { |
| 8351 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8352 | } |
| 8353 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8354 | @Override |
| 8355 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 8356 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8357 | } |
| 8358 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8359 | @Override |
| 8360 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 8361 | return mDailyPackageChanges; |
| 8362 | } |
| 8363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8364 | long getBatteryUptimeLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8365 | return mOnBatteryTimeBase.getUptime(SystemClock.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8366 | } |
| 8367 | |
| 8368 | @Override |
| 8369 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8370 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | @Override |
| 8374 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8375 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8376 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 8377 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8378 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8379 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8380 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8381 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8382 | } |
| 8383 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8384 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8385 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8386 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8387 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8388 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8389 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8390 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8391 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8392 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8393 | } |
| 8394 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8395 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8396 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8397 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8400 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8401 | public int getLowDischargeAmountSinceCharge() { |
| 8402 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8403 | int val = mLowDischargeAmountSinceCharge; |
| 8404 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8405 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 8406 | } |
| 8407 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8408 | } |
| 8409 | } |
| 8410 | |
| 8411 | @Override |
| 8412 | public int getHighDischargeAmountSinceCharge() { |
| 8413 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8414 | int val = mHighDischargeAmountSinceCharge; |
| 8415 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8416 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 8417 | } |
| 8418 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8419 | } |
| 8420 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8421 | |
| 8422 | @Override |
| 8423 | public int getDischargeAmount(int which) { |
| 8424 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 8425 | ? getHighDischargeAmountSinceCharge() |
| 8426 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 8427 | if (dischargeAmount < 0) { |
| 8428 | dischargeAmount = 0; |
| 8429 | } |
| 8430 | return dischargeAmount; |
| 8431 | } |
| 8432 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8433 | public int getDischargeAmountScreenOn() { |
| 8434 | synchronized(this) { |
| 8435 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8436 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8437 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8438 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8439 | } |
| 8440 | return val; |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | public int getDischargeAmountScreenOnSinceCharge() { |
| 8445 | synchronized(this) { |
| 8446 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8447 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8448 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8449 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8450 | } |
| 8451 | return val; |
| 8452 | } |
| 8453 | } |
| 8454 | |
| 8455 | public int getDischargeAmountScreenOff() { |
| 8456 | synchronized(this) { |
| 8457 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8458 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8459 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8460 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8461 | } |
| 8462 | return val; |
| 8463 | } |
| 8464 | } |
| 8465 | |
| 8466 | public int getDischargeAmountScreenOffSinceCharge() { |
| 8467 | synchronized(this) { |
| 8468 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8469 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8470 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8471 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8472 | } |
| 8473 | return val; |
| 8474 | } |
| 8475 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8476 | |
| 8477 | @Override |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8478 | public int getCpuSpeedSteps() { |
| 8479 | return sNumSpeedSteps; |
| 8480 | } |
| 8481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8482 | /** |
| 8483 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 8484 | */ |
| 8485 | public Uid getUidStatsLocked(int uid) { |
| 8486 | Uid u = mUidStats.get(uid); |
| 8487 | if (u == null) { |
| 8488 | u = new Uid(uid); |
| 8489 | mUidStats.put(uid, u); |
| 8490 | } |
| 8491 | return u; |
| 8492 | } |
| 8493 | |
| 8494 | /** |
| 8495 | * Remove the statistics object for a particular uid. |
| 8496 | */ |
| 8497 | public void removeUidStatsLocked(int uid) { |
| 8498 | mUidStats.remove(uid); |
| 8499 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 8500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8501 | /** |
| 8502 | * Retrieve the statistics object for a particular process, creating |
| 8503 | * if needed. |
| 8504 | */ |
| 8505 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8506 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8507 | Uid u = getUidStatsLocked(uid); |
| 8508 | return u.getProcessStatsLocked(name); |
| 8509 | } |
| 8510 | |
| 8511 | /** |
| 8512 | * Retrieve the statistics object for a particular process, creating |
| 8513 | * if needed. |
| 8514 | */ |
| 8515 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8516 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | Uid u = getUidStatsLocked(uid); |
| 8518 | return u.getPackageStatsLocked(pkg); |
| 8519 | } |
| 8520 | |
| 8521 | /** |
| 8522 | * Retrieve the statistics object for a particular service, creating |
| 8523 | * if needed. |
| 8524 | */ |
| 8525 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8526 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8527 | Uid u = getUidStatsLocked(uid); |
| 8528 | return u.getServiceStatsLocked(pkg, name); |
| 8529 | } |
| 8530 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8531 | /** |
| 8532 | * Massage data to distribute any reasonable work down to more specific |
| 8533 | * owners. Must only be called on a dead BatteryStats object! |
| 8534 | */ |
| 8535 | public void distributeWorkLocked(int which) { |
| 8536 | // Aggregate all CPU time associated with WIFI. |
| 8537 | Uid wifiUid = mUidStats.get(Process.WIFI_UID); |
| 8538 | if (wifiUid != null) { |
| 8539 | long uSecTime = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8540 | for (int ip=wifiUid.mProcessStats.size()-1; ip>=0; ip--) { |
| 8541 | Uid.Proc proc = wifiUid.mProcessStats.valueAt(ip); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8542 | long totalRunningTime = getGlobalWifiRunningTime(uSecTime, which); |
| 8543 | for (int i=0; i<mUidStats.size(); i++) { |
| 8544 | Uid uid = mUidStats.valueAt(i); |
| 8545 | if (uid.mUid != Process.WIFI_UID) { |
| 8546 | long uidRunningTime = uid.getWifiRunningTime(uSecTime, which); |
| 8547 | if (uidRunningTime > 0) { |
| 8548 | Uid.Proc uidProc = uid.getProcessStatsLocked("*wifi*"); |
| 8549 | long time = proc.getUserTime(which); |
| 8550 | time = (time*uidRunningTime)/totalRunningTime; |
| 8551 | uidProc.mUserTime += time; |
| 8552 | proc.mUserTime -= time; |
| 8553 | time = proc.getSystemTime(which); |
| 8554 | time = (time*uidRunningTime)/totalRunningTime; |
| 8555 | uidProc.mSystemTime += time; |
| 8556 | proc.mSystemTime -= time; |
| 8557 | time = proc.getForegroundTime(which); |
| 8558 | time = (time*uidRunningTime)/totalRunningTime; |
| 8559 | uidProc.mForegroundTime += time; |
| 8560 | proc.mForegroundTime -= time; |
| 8561 | for (int sb=0; sb<proc.mSpeedBins.length; sb++) { |
| 8562 | SamplingCounter sc = proc.mSpeedBins[sb]; |
| 8563 | if (sc != null) { |
| 8564 | time = sc.getCountLocked(which); |
| 8565 | time = (time*uidRunningTime)/totalRunningTime; |
| 8566 | SamplingCounter uidSc = uidProc.mSpeedBins[sb]; |
| 8567 | if (uidSc == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8568 | uidSc = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8569 | uidProc.mSpeedBins[sb] = uidSc; |
| 8570 | } |
| 8571 | uidSc.mCount.addAndGet((int)time); |
| 8572 | sc.mCount.addAndGet((int)-time); |
| 8573 | } |
| 8574 | } |
| 8575 | totalRunningTime -= uidRunningTime; |
| 8576 | } |
| 8577 | } |
| 8578 | } |
| 8579 | } |
| 8580 | } |
| 8581 | } |
| 8582 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8583 | public void shutdownLocked() { |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8584 | recordShutdownLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8585 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8586 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8588 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8589 | Parcel mPendingWrite = null; |
| 8590 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 8591 | |
| 8592 | public void writeAsyncLocked() { |
| 8593 | writeLocked(false); |
| 8594 | } |
| 8595 | |
| 8596 | public void writeSyncLocked() { |
| 8597 | writeLocked(true); |
| 8598 | } |
| 8599 | |
| 8600 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8601 | if (mFile == null) { |
| 8602 | 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] | 8603 | return; |
| 8604 | } |
| 8605 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8606 | if (mShuttingDown) { |
| 8607 | return; |
| 8608 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8609 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8610 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8611 | writeSummaryToParcel(out, true); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8612 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 8613 | |
| 8614 | if (mPendingWrite != null) { |
| 8615 | mPendingWrite.recycle(); |
| 8616 | } |
| 8617 | mPendingWrite = out; |
| 8618 | |
| 8619 | if (sync) { |
| 8620 | commitPendingDataToDisk(); |
| 8621 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8622 | BackgroundThread.getHandler().post(new Runnable() { |
| 8623 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8624 | commitPendingDataToDisk(); |
| 8625 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8626 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8627 | } |
| 8628 | } |
| 8629 | |
| 8630 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 8631 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8632 | synchronized (this) { |
| 8633 | next = mPendingWrite; |
| 8634 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 8635 | if (next == null) { |
| 8636 | return; |
| 8637 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8638 | |
| 8639 | mWriteLock.lock(); |
| 8640 | } |
| 8641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8643 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8644 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 8646 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8647 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8648 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8649 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8650 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8651 | mFile.rollback(); |
| 8652 | } finally { |
| 8653 | next.recycle(); |
| 8654 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8655 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8656 | } |
| 8657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8658 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8659 | if (mDailyFile != null) { |
| 8660 | readDailyStatsLocked(); |
| 8661 | } |
| 8662 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8663 | if (mFile == null) { |
| 8664 | 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] | 8665 | return; |
| 8666 | } |
| 8667 | |
| 8668 | mUidStats.clear(); |
| 8669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8670 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8671 | File file = mFile.chooseForRead(); |
| 8672 | if (!file.exists()) { |
| 8673 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8674 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8675 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8676 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8677 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8678 | Parcel in = Parcel.obtain(); |
| 8679 | in.unmarshall(raw, 0, raw.length); |
| 8680 | in.setDataPosition(0); |
| 8681 | stream.close(); |
| 8682 | |
| 8683 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 8684 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8685 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8687 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8688 | mEndPlatformVersion = Build.ID; |
| 8689 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8690 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8691 | mRecordingHistory = true; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8692 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8693 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8694 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8695 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8696 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8697 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 8698 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8699 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8700 | |
| 8701 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8702 | } |
| 8703 | |
| 8704 | public int describeContents() { |
| 8705 | return 0; |
| 8706 | } |
| 8707 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8708 | void readHistory(Parcel in, boolean andOldHistory) { |
| 8709 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8710 | |
| 8711 | mHistoryBuffer.setDataSize(0); |
| 8712 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8713 | mHistoryTagPool.clear(); |
| 8714 | mNextHistoryTagIdx = 0; |
| 8715 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8716 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8717 | int numTags = in.readInt(); |
| 8718 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8719 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8720 | String str = in.readString(); |
| 8721 | int uid = in.readInt(); |
| 8722 | HistoryTag tag = new HistoryTag(); |
| 8723 | tag.string = str; |
| 8724 | tag.uid = uid; |
| 8725 | tag.poolIdx = idx; |
| 8726 | mHistoryTagPool.put(tag, idx); |
| 8727 | if (idx >= mNextHistoryTagIdx) { |
| 8728 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8729 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8730 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8731 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8732 | |
| 8733 | int bufSize = in.readInt(); |
| 8734 | int curPos = in.dataPosition(); |
| 8735 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
| 8736 | Slog.w(TAG, "File corrupt: history data buffer too large " + bufSize); |
| 8737 | } else if ((bufSize&~3) != bufSize) { |
| 8738 | Slog.w(TAG, "File corrupt: history data buffer not aligned " + bufSize); |
| 8739 | } else { |
| 8740 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 8741 | + " bytes at " + curPos); |
| 8742 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 8743 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8744 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8745 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8746 | if (andOldHistory) { |
| 8747 | readOldHistory(in); |
| 8748 | } |
| 8749 | |
| 8750 | if (DEBUG_HISTORY) { |
| 8751 | StringBuilder sb = new StringBuilder(128); |
| 8752 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 8753 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8754 | Slog.i(TAG, sb.toString()); |
| 8755 | } |
| 8756 | mHistoryBaseTime = historyBaseTime; |
| 8757 | if (DEBUG_HISTORY) { |
| 8758 | StringBuilder sb = new StringBuilder(128); |
| 8759 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 8760 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8761 | Slog.i(TAG, sb.toString()); |
| 8762 | } |
| 8763 | |
| 8764 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 8765 | // the last run until samples in this run. |
| 8766 | if (mHistoryBaseTime > 0) { |
| 8767 | long oldnow = SystemClock.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8768 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8769 | if (DEBUG_HISTORY) { |
| 8770 | StringBuilder sb = new StringBuilder(128); |
| 8771 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 8772 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8773 | Slog.i(TAG, sb.toString()); |
| 8774 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 8775 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8776 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8777 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8778 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8779 | if (!USE_OLD_HISTORY) { |
| 8780 | return; |
| 8781 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8782 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 8783 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 8784 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8785 | HistoryItem rec = new HistoryItem(time, in); |
| 8786 | addHistoryRecordLocked(rec); |
| 8787 | } |
| 8788 | } |
| 8789 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8790 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8791 | if (DEBUG_HISTORY) { |
| 8792 | StringBuilder sb = new StringBuilder(128); |
| 8793 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 8794 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8795 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 8796 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8797 | Slog.i(TAG, sb.toString()); |
| 8798 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8799 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8800 | if (!inclData) { |
| 8801 | out.writeInt(0); |
| 8802 | out.writeInt(0); |
| 8803 | return; |
| 8804 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8805 | out.writeInt(mHistoryTagPool.size()); |
| 8806 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8807 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8808 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8809 | out.writeString(tag.string); |
| 8810 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8811 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8812 | out.writeInt(mHistoryBuffer.dataSize()); |
| 8813 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 8814 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 8815 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8816 | |
| 8817 | if (andOldHistory) { |
| 8818 | writeOldHistory(out); |
| 8819 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8820 | } |
| 8821 | |
| 8822 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8823 | if (!USE_OLD_HISTORY) { |
| 8824 | return; |
| 8825 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8826 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8827 | while (rec != null) { |
| 8828 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 8829 | rec = rec.next; |
| 8830 | } |
| 8831 | out.writeLong(-1); |
| 8832 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8833 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8834 | public void readSummaryFromParcel(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8835 | final int version = in.readInt(); |
| 8836 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8837 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8838 | + ", expected " + VERSION + "; erasing old stats"); |
| 8839 | return; |
| 8840 | } |
| 8841 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8842 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8844 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8845 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8846 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8847 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8848 | mStartPlatformVersion = in.readString(); |
| 8849 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8850 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 8851 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8852 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8853 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8854 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8855 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8856 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 8857 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8858 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 8859 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8860 | mDischargeStepTracker.readFromParcel(in); |
| 8861 | mChargeStepTracker.readFromParcel(in); |
| 8862 | mDailyDischargeStepTracker.readFromParcel(in); |
| 8863 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8864 | int NPKG = in.readInt(); |
| 8865 | if (NPKG > 0) { |
| 8866 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 8867 | while (NPKG > 0) { |
| 8868 | NPKG--; |
| 8869 | PackageChange pc = new PackageChange(); |
| 8870 | pc.mPackageName = in.readString(); |
| 8871 | pc.mUpdate = in.readInt() != 0; |
| 8872 | pc.mVersionCode = in.readInt(); |
| 8873 | mDailyPackageChanges.add(pc); |
| 8874 | } |
| 8875 | } else { |
| 8876 | mDailyPackageChanges = null; |
| 8877 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8878 | mDailyStartTime = in.readLong(); |
| 8879 | mNextMinDailyDeadline = in.readLong(); |
| 8880 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8882 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8883 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8884 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8885 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8886 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 8887 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 8888 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8889 | mInteractive = false; |
| 8890 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8892 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
| 8893 | mDeviceIdleModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8894 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8896 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8897 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 8898 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8899 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8900 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 8901 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 8902 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8903 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8904 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 8905 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8906 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8907 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 8908 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8909 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8910 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8911 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 8912 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8913 | mWifiOn = false; |
| 8914 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8915 | mGlobalWifiRunning = false; |
| 8916 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8917 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 8918 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 8919 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8920 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8921 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 8922 | } |
| 8923 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8924 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 8925 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8926 | mBluetoothOn = false; |
| 8927 | mBluetoothOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8928 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 8929 | mBluetoothStateTimer[i].readSummaryFromParcelLocked(in); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 8930 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8931 | |
| 8932 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 8933 | mBluetoothActivityCounters[i].readSummaryFromParcelLocked(in); |
| 8934 | } |
| 8935 | |
| 8936 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 8937 | mWifiActivityCounters[i].readSummaryFromParcelLocked(in); |
| 8938 | } |
| 8939 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8940 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8941 | mFlashlightOn = false; |
| 8942 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8944 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8945 | if (NKW > 10000) { |
| 8946 | Slog.w(TAG, "File corrupt: too many kernel wake locks " + NKW); |
| 8947 | return; |
| 8948 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8949 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 8950 | if (in.readInt() != 0) { |
| 8951 | String kwltName = in.readString(); |
| 8952 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 8953 | } |
| 8954 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8955 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8956 | int NWR = in.readInt(); |
| 8957 | if (NWR > 10000) { |
| 8958 | Slog.w(TAG, "File corrupt: too many wakeup reasons " + NWR); |
| 8959 | return; |
| 8960 | } |
| 8961 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 8962 | if (in.readInt() != 0) { |
| 8963 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8964 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8965 | } |
| 8966 | } |
| 8967 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8968 | sNumSpeedSteps = in.readInt(); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 8969 | if (sNumSpeedSteps < 0 || sNumSpeedSteps > 100) { |
| 8970 | throw new BadParcelableException("Bad speed steps in data: " + sNumSpeedSteps); |
| 8971 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8973 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8974 | if (NU > 10000) { |
| 8975 | Slog.w(TAG, "File corrupt: too many uids " + NU); |
| 8976 | return; |
| 8977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8978 | for (int iu = 0; iu < NU; iu++) { |
| 8979 | int uid = in.readInt(); |
| 8980 | Uid u = new Uid(uid); |
| 8981 | mUidStats.put(uid, u); |
| 8982 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8983 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8984 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8985 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8986 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8987 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8988 | if (in.readInt() != 0) { |
| 8989 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 8990 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8991 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8992 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8993 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8994 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8995 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 8996 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8997 | if (in.readInt() != 0) { |
| 8998 | u.makeWifiBatchedScanBin(i, null); |
| 8999 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 9000 | } |
| 9001 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9002 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9003 | if (in.readInt() != 0) { |
| 9004 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 9005 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9006 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9007 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9008 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9009 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9010 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9011 | } |
| 9012 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9013 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 9014 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9015 | u.mProcessState = Uid.PROCESS_STATE_NONE; |
| 9016 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9017 | if (in.readInt() != 0) { |
| 9018 | u.makeProcessState(i, null); |
| 9019 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 9020 | } |
| 9021 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9022 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9023 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9024 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9025 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9026 | if (in.readInt() != 0) { |
| 9027 | if (u.mUserActivityCounters == null) { |
| 9028 | u.initUserActivityLocked(); |
| 9029 | } |
| 9030 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9031 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9032 | } |
| 9033 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9034 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9035 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9036 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9037 | u.initNetworkActivityLocked(); |
| 9038 | } |
| 9039 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9040 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9041 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9042 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9043 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 9044 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9045 | } |
| 9046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9047 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9048 | if (NW > 100) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9049 | Slog.w(TAG, "File corrupt: too many wake locks " + NW); |
| 9050 | return; |
| 9051 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9052 | for (int iw = 0; iw < NW; iw++) { |
| 9053 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9054 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9055 | } |
| 9056 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9057 | int NS = in.readInt(); |
| 9058 | if (NS > 100) { |
| 9059 | Slog.w(TAG, "File corrupt: too many syncs " + NS); |
| 9060 | return; |
| 9061 | } |
| 9062 | for (int is = 0; is < NS; is++) { |
| 9063 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9064 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9065 | } |
| 9066 | |
| 9067 | int NJ = in.readInt(); |
| 9068 | if (NJ > 100) { |
| 9069 | Slog.w(TAG, "File corrupt: too many job timers " + NJ); |
| 9070 | return; |
| 9071 | } |
| 9072 | for (int ij = 0; ij < NJ; ij++) { |
| 9073 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9074 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9075 | } |
| 9076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9077 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9078 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9079 | Slog.w(TAG, "File corrupt: too many sensors " + NP); |
| 9080 | return; |
| 9081 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9082 | for (int is = 0; is < NP; is++) { |
| 9083 | int seNumber = in.readInt(); |
| 9084 | if (in.readInt() != 0) { |
| 9085 | u.getSensorTimerLocked(seNumber, true) |
| 9086 | .readSummaryFromParcelLocked(in); |
| 9087 | } |
| 9088 | } |
| 9089 | |
| 9090 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9091 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9092 | Slog.w(TAG, "File corrupt: too many processes " + NP); |
| 9093 | return; |
| 9094 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | for (int ip = 0; ip < NP; ip++) { |
| 9096 | String procName = in.readString(); |
| 9097 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 9098 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9100 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9102 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 9103 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9104 | int NSB = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9105 | if (NSB > 100) { |
| 9106 | Slog.w(TAG, "File corrupt: too many speed bins " + NSB); |
| 9107 | return; |
| 9108 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9109 | p.mSpeedBins = new SamplingCounter[NSB]; |
| 9110 | for (int i=0; i<NSB; i++) { |
| 9111 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9112 | p.mSpeedBins[i] = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9113 | p.mSpeedBins[i].readSummaryFromParcelLocked(in); |
| 9114 | } |
| 9115 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9116 | if (!p.readExcessivePowerFromParcelLocked(in)) { |
| 9117 | return; |
| 9118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9119 | } |
| 9120 | |
| 9121 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9122 | if (NP > 10000) { |
| 9123 | Slog.w(TAG, "File corrupt: too many packages " + NP); |
| 9124 | return; |
| 9125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9126 | for (int ip = 0; ip < NP; ip++) { |
| 9127 | String pkgName = in.readString(); |
| 9128 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9129 | final int NWA = in.readInt(); |
| 9130 | if (NWA > 1000) { |
| 9131 | Slog.w(TAG, "File corrupt: too many wakeup alarms " + NWA); |
| 9132 | return; |
| 9133 | } |
| 9134 | p.mWakeupAlarms.clear(); |
| 9135 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9136 | String tag = in.readString(); |
| 9137 | Counter c = new Counter(mOnBatteryTimeBase); |
| 9138 | c.readSummaryFromParcelLocked(in); |
| 9139 | p.mWakeupAlarms.put(tag, c); |
| 9140 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9141 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9142 | if (NS > 1000) { |
| 9143 | Slog.w(TAG, "File corrupt: too many services " + NS); |
| 9144 | return; |
| 9145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9146 | for (int is = 0; is < NS; is++) { |
| 9147 | String servName = in.readString(); |
| 9148 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 9149 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9150 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9151 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | } |
| 9153 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | } |
| 9155 | } |
| 9156 | |
| 9157 | /** |
| 9158 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 9159 | * disk. This format does not allow a lossless round-trip. |
| 9160 | * |
| 9161 | * @param out the Parcel to be written to. |
| 9162 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9163 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9164 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9165 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9166 | // Pull the clock time. This may update the time and make a new history entry |
| 9167 | // if we had originally pulled a time before the RTC was set. |
| 9168 | long startClockTime = getStartClockTime(); |
| 9169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9170 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 9171 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9172 | |
| 9173 | out.writeInt(VERSION); |
| 9174 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9175 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9177 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9178 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9179 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9180 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9181 | out.writeString(mStartPlatformVersion); |
| 9182 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9183 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 9184 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9185 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9186 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9187 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9188 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9189 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 9190 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9191 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 9192 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9193 | mDischargeStepTracker.writeToParcel(out); |
| 9194 | mChargeStepTracker.writeToParcel(out); |
| 9195 | mDailyDischargeStepTracker.writeToParcel(out); |
| 9196 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9197 | if (mDailyPackageChanges != null) { |
| 9198 | final int NPKG = mDailyPackageChanges.size(); |
| 9199 | out.writeInt(NPKG); |
| 9200 | for (int i=0; i<NPKG; i++) { |
| 9201 | PackageChange pc = mDailyPackageChanges.get(i); |
| 9202 | out.writeString(pc.mPackageName); |
| 9203 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 9204 | out.writeInt(pc.mVersionCode); |
| 9205 | } |
| 9206 | } else { |
| 9207 | out.writeInt(0); |
| 9208 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9209 | out.writeLong(mDailyStartTime); |
| 9210 | out.writeLong(mNextMinDailyDeadline); |
| 9211 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9212 | |
| 9213 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9214 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9215 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9216 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9217 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9218 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9219 | mDeviceIdleModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9220 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9221 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9222 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9223 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9224 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9225 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9226 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9227 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9228 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9229 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9230 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9231 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9232 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9233 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9234 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9235 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9236 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 9237 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9238 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9239 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9240 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9241 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9242 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9243 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9244 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9245 | } |
| 9246 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9247 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9248 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9249 | mBluetoothOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9250 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9251 | mBluetoothStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9252 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9253 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9254 | mBluetoothActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9255 | } |
| 9256 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9257 | mWifiActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9258 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9259 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9260 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9261 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9262 | out.writeInt(mKernelWakelockStats.size()); |
| 9263 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9264 | Timer kwlt = ent.getValue(); |
| 9265 | if (kwlt != null) { |
| 9266 | out.writeInt(1); |
| 9267 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9268 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9269 | } else { |
| 9270 | out.writeInt(0); |
| 9271 | } |
| 9272 | } |
| 9273 | |
| 9274 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9275 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9276 | SamplingTimer timer = ent.getValue(); |
| 9277 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9278 | out.writeInt(1); |
| 9279 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9280 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9281 | } else { |
| 9282 | out.writeInt(0); |
| 9283 | } |
| 9284 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9285 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9286 | out.writeInt(sNumSpeedSteps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9287 | final int NU = mUidStats.size(); |
| 9288 | out.writeInt(NU); |
| 9289 | for (int iu = 0; iu < NU; iu++) { |
| 9290 | out.writeInt(mUidStats.keyAt(iu)); |
| 9291 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9292 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9293 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9294 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9295 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9296 | } else { |
| 9297 | out.writeInt(0); |
| 9298 | } |
| 9299 | if (u.mFullWifiLockTimer != null) { |
| 9300 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9301 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9302 | } else { |
| 9303 | out.writeInt(0); |
| 9304 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9305 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9306 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9307 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9308 | } else { |
| 9309 | out.writeInt(0); |
| 9310 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9311 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9312 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 9313 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9314 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9315 | } else { |
| 9316 | out.writeInt(0); |
| 9317 | } |
| 9318 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9319 | if (u.mWifiMulticastTimer != null) { |
| 9320 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9321 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9322 | } else { |
| 9323 | out.writeInt(0); |
| 9324 | } |
| 9325 | if (u.mAudioTurnedOnTimer != null) { |
| 9326 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9327 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9328 | } else { |
| 9329 | out.writeInt(0); |
| 9330 | } |
| 9331 | if (u.mVideoTurnedOnTimer != null) { |
| 9332 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9333 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9334 | } else { |
| 9335 | out.writeInt(0); |
| 9336 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9337 | if (u.mForegroundActivityTimer != null) { |
| 9338 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9339 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9340 | } else { |
| 9341 | out.writeInt(0); |
| 9342 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9343 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9344 | if (u.mProcessStateTimer[i] != null) { |
| 9345 | out.writeInt(1); |
| 9346 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9347 | } else { |
| 9348 | out.writeInt(0); |
| 9349 | } |
| 9350 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9351 | if (u.mVibratorOnTimer != null) { |
| 9352 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9353 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9354 | } else { |
| 9355 | out.writeInt(0); |
| 9356 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9357 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9358 | if (u.mUserActivityCounters == null) { |
| 9359 | out.writeInt(0); |
| 9360 | } else { |
| 9361 | out.writeInt(1); |
| 9362 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9363 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9364 | } |
| 9365 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9366 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9367 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9368 | out.writeInt(0); |
| 9369 | } else { |
| 9370 | out.writeInt(1); |
| 9371 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9372 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9373 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9374 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9375 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 9376 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9377 | } |
| 9378 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9379 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 9380 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9381 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9382 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9383 | out.writeString(wakeStats.keyAt(iw)); |
| 9384 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9385 | if (wl.mTimerFull != null) { |
| 9386 | out.writeInt(1); |
| 9387 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9388 | } else { |
| 9389 | out.writeInt(0); |
| 9390 | } |
| 9391 | if (wl.mTimerPartial != null) { |
| 9392 | out.writeInt(1); |
| 9393 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9394 | } else { |
| 9395 | out.writeInt(0); |
| 9396 | } |
| 9397 | if (wl.mTimerWindow != null) { |
| 9398 | out.writeInt(1); |
| 9399 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9400 | } else { |
| 9401 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9402 | } |
| 9403 | } |
| 9404 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9405 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 9406 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9407 | out.writeInt(NS); |
| 9408 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9409 | out.writeString(syncStats.keyAt(is)); |
| 9410 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9411 | } |
| 9412 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9413 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 9414 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9415 | out.writeInt(NJ); |
| 9416 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9417 | out.writeString(jobStats.keyAt(ij)); |
| 9418 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9419 | } |
| 9420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | int NSE = u.mSensorStats.size(); |
| 9422 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9423 | for (int ise=0; ise<NSE; ise++) { |
| 9424 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 9425 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 9426 | if (se.mTimer != null) { |
| 9427 | out.writeInt(1); |
| 9428 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9429 | } else { |
| 9430 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9431 | } |
| 9432 | } |
| 9433 | |
| 9434 | int NP = u.mProcessStats.size(); |
| 9435 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9436 | for (int ip=0; ip<NP; ip++) { |
| 9437 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 9438 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 9439 | out.writeLong(ps.mUserTime); |
| 9440 | out.writeLong(ps.mSystemTime); |
| 9441 | out.writeLong(ps.mForegroundTime); |
| 9442 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9443 | out.writeInt(ps.mNumCrashes); |
| 9444 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9445 | final int N = ps.mSpeedBins.length; |
| 9446 | out.writeInt(N); |
| 9447 | for (int i=0; i<N; i++) { |
| 9448 | if (ps.mSpeedBins[i] != null) { |
| 9449 | out.writeInt(1); |
| 9450 | ps.mSpeedBins[i].writeSummaryFromParcelLocked(out); |
| 9451 | } else { |
| 9452 | out.writeInt(0); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9453 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9454 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9455 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9456 | } |
| 9457 | |
| 9458 | NP = u.mPackageStats.size(); |
| 9459 | out.writeInt(NP); |
| 9460 | if (NP > 0) { |
| 9461 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 9462 | : u.mPackageStats.entrySet()) { |
| 9463 | out.writeString(ent.getKey()); |
| 9464 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9465 | final int NWA = ps.mWakeupAlarms.size(); |
| 9466 | out.writeInt(NWA); |
| 9467 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9468 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 9469 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 9470 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9471 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9472 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9473 | for (int is=0; is<NS; is++) { |
| 9474 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 9475 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 9476 | long time = ss.getStartTimeToNowLocked( |
| 9477 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 9478 | out.writeLong(time); |
| 9479 | out.writeInt(ss.mStarts); |
| 9480 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9481 | } |
| 9482 | } |
| 9483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | } |
| 9485 | } |
| 9486 | |
| 9487 | public void readFromParcel(Parcel in) { |
| 9488 | readFromParcelLocked(in); |
| 9489 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9491 | void readFromParcelLocked(Parcel in) { |
| 9492 | int magic = in.readInt(); |
| 9493 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9494 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | } |
| 9496 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9497 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9499 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9500 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9501 | mStartPlatformVersion = in.readString(); |
| 9502 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | mUptime = in.readLong(); |
| 9504 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | mRealtime = in.readLong(); |
| 9506 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | mOnBattery = in.readInt() != 0; |
| 9508 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9509 | mOnBatteryTimeBase.readFromParcel(in); |
| 9510 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 9511 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9512 | mScreenState = Display.STATE_UNKNOWN; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9513 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in); |
| 9514 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9515 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, |
| 9516 | in); |
| 9517 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9518 | mInteractive = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9519 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9520 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9521 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in); |
| 9522 | mDeviceIdleModeEnabledTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9523 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9524 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9525 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9526 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 9527 | null, mOnBatteryTimeBase, in); |
| 9528 | } |
| 9529 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase, in); |
| 9530 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9531 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 9532 | null, mOnBatteryTimeBase, in); |
| 9533 | } |
| 9534 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9535 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9536 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9537 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9538 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9539 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); |
| 9540 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, |
| 9541 | in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9542 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9543 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9544 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9545 | mWifiOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9546 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9547 | mGlobalWifiRunning = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9548 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9549 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9550 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, |
| 9551 | null, mOnBatteryTimeBase, in); |
| 9552 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9553 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9554 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, |
| 9555 | null, mOnBatteryTimeBase, in); |
| 9556 | } |
| 9557 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9558 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, |
| 9559 | null, mOnBatteryTimeBase, in); |
| 9560 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9561 | mBluetoothOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9562 | mBluetoothOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9563 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 9564 | mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, |
| 9565 | null, mOnBatteryTimeBase, in); |
| 9566 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9567 | |
| 9568 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9569 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9570 | } |
| 9571 | |
| 9572 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9573 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9574 | } |
| 9575 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9576 | mHasWifiEnergyReporting = in.readInt() != 0; |
| 9577 | mHasBluetoothEnergyReporting = in.readInt() != 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9578 | mNumConnectivityChange = in.readInt(); |
| 9579 | mLoadedNumConnectivityChange = in.readInt(); |
| 9580 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9581 | mAudioOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9582 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9583 | mVideoOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9584 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9585 | mFlashlightOn = false; |
| 9586 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9587 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9588 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9589 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9590 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9591 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9592 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9593 | mDischargeAmountScreenOn = in.readInt(); |
| 9594 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9595 | mDischargeAmountScreenOff = in.readInt(); |
| 9596 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9597 | mDischargeStepTracker.readFromParcel(in); |
| 9598 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | mLastWriteTime = in.readLong(); |
| 9600 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 9601 | mBluetoothPingCount = in.readInt(); |
| 9602 | mBluetoothPingStart = -1; |
| 9603 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9604 | mKernelWakelockStats.clear(); |
| 9605 | int NKW = in.readInt(); |
| 9606 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 9607 | if (in.readInt() != 0) { |
| 9608 | String wakelockName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9609 | SamplingTimer kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9610 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 9611 | } |
| 9612 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9613 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9614 | mWakeupReasonStats.clear(); |
| 9615 | int NWR = in.readInt(); |
| 9616 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 9617 | if (in.readInt() != 0) { |
| 9618 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9619 | SamplingTimer timer = new SamplingTimer(mOnBatteryTimeBase, in); |
| 9620 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9621 | } |
| 9622 | } |
| 9623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9624 | mPartialTimers.clear(); |
| 9625 | mFullTimers.clear(); |
| 9626 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9627 | mWifiRunningTimers.clear(); |
| 9628 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9629 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9630 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9631 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9632 | mAudioTurnedOnTimers.clear(); |
| 9633 | mVideoTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9635 | sNumSpeedSteps = in.readInt(); |
| 9636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9637 | int numUids = in.readInt(); |
| 9638 | mUidStats.clear(); |
| 9639 | for (int i = 0; i < numUids; i++) { |
| 9640 | int uid = in.readInt(); |
| 9641 | Uid u = new Uid(uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9642 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9643 | mUidStats.append(uid, u); |
| 9644 | } |
| 9645 | } |
| 9646 | |
| 9647 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9648 | writeToParcelLocked(out, true, flags); |
| 9649 | } |
| 9650 | |
| 9651 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 9652 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9653 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9654 | |
| 9655 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9656 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9657 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9658 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9659 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9660 | // Pull the clock time. This may update the time and make a new history entry |
| 9661 | // if we had originally pulled a time before the RTC was set. |
| 9662 | long startClockTime = getStartClockTime(); |
| 9663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9664 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 9665 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9666 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 9667 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9669 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9670 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9671 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9673 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9674 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9675 | out.writeString(mStartPlatformVersion); |
| 9676 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9677 | out.writeLong(mUptime); |
| 9678 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9679 | out.writeLong(mRealtime); |
| 9680 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9682 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 9683 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 9684 | |
| 9685 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 9686 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9687 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 9688 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9689 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9690 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
| 9691 | mDeviceIdleModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9692 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9693 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 9694 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9695 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 9696 | } |
| 9697 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 9698 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9699 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 9700 | } |
| 9701 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9702 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 9703 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 9704 | } |
| 9705 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 9706 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9707 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9708 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 9709 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 9710 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 9711 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 9712 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9713 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9714 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9715 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9716 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9717 | } |
| 9718 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9719 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 9720 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9721 | mBluetoothOnTimer.writeToParcel(out, uSecRealtime); |
| 9722 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 9723 | mBluetoothStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9724 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9725 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9726 | mBluetoothActivityCounters[i].writeToParcel(out); |
| 9727 | } |
| 9728 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9729 | mWifiActivityCounters[i].writeToParcel(out); |
| 9730 | } |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9731 | out.writeInt(mHasWifiEnergyReporting ? 1 : 0); |
| 9732 | out.writeInt(mHasBluetoothEnergyReporting ? 1 : 0); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9733 | out.writeInt(mNumConnectivityChange); |
| 9734 | out.writeInt(mLoadedNumConnectivityChange); |
| 9735 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9736 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9737 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9738 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9739 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9740 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9741 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 9742 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9743 | out.writeInt(mDischargeAmountScreenOn); |
| 9744 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 9745 | out.writeInt(mDischargeAmountScreenOff); |
| 9746 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9747 | mDischargeStepTracker.writeToParcel(out); |
| 9748 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9749 | out.writeLong(mLastWriteTime); |
| 9750 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 9751 | out.writeInt(getBluetoothPingCount()); |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 9752 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9753 | if (inclUids) { |
| 9754 | out.writeInt(mKernelWakelockStats.size()); |
| 9755 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9756 | SamplingTimer kwlt = ent.getValue(); |
| 9757 | if (kwlt != null) { |
| 9758 | out.writeInt(1); |
| 9759 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9760 | kwlt.writeToParcel(out, uSecRealtime); |
| 9761 | } else { |
| 9762 | out.writeInt(0); |
| 9763 | } |
| 9764 | } |
| 9765 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9766 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9767 | SamplingTimer timer = ent.getValue(); |
| 9768 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9769 | out.writeInt(1); |
| 9770 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9771 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9772 | } else { |
| 9773 | out.writeInt(0); |
| 9774 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9775 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9776 | } else { |
| 9777 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9778 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9779 | |
| 9780 | out.writeInt(sNumSpeedSteps); |
| 9781 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9782 | if (inclUids) { |
| 9783 | int size = mUidStats.size(); |
| 9784 | out.writeInt(size); |
| 9785 | for (int i = 0; i < size; i++) { |
| 9786 | out.writeInt(mUidStats.keyAt(i)); |
| 9787 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9789 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9790 | } |
| 9791 | } else { |
| 9792 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9793 | } |
| 9794 | } |
| 9795 | |
| 9796 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 9797 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 9798 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 9799 | return new BatteryStatsImpl(in); |
| 9800 | } |
| 9801 | |
| 9802 | public BatteryStatsImpl[] newArray(int size) { |
| 9803 | return new BatteryStatsImpl[size]; |
| 9804 | } |
| 9805 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9806 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9807 | public void prepareForDumpLocked() { |
| 9808 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9809 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9810 | |
| 9811 | // Pull the clock time. This may update the time and make a new history entry |
| 9812 | // if we had originally pulled a time before the RTC was set. |
| 9813 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9814 | } |
| 9815 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 9816 | 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] | 9817 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9818 | pw.println("mOnBatteryTimeBase:"); |
| 9819 | mOnBatteryTimeBase.dump(pw, " "); |
| 9820 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 9821 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9822 | Printer pr = new PrintWriterPrinter(pw); |
| 9823 | pr.println("*** Screen timer:"); |
| 9824 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9825 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9826 | pr.println("*** Screen brightness #" + i + ":"); |
| 9827 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9828 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9829 | pr.println("*** Interactive timer:"); |
| 9830 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9831 | pr.println("*** Power save mode timer:"); |
| 9832 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
| 9833 | pr.println("*** Device idle mode timer:"); |
| 9834 | mDeviceIdleModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9835 | pr.println("*** Device idling timer:"); |
| 9836 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9837 | pr.println("*** Phone timer:"); |
| 9838 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9839 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9840 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9841 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9842 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 9843 | pr.println("*** Signal scanning :"); |
| 9844 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9845 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9846 | pr.println("*** Data connection type #" + i + ":"); |
| 9847 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9848 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9849 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9850 | pr.println("*** Mobile network active timer:"); |
| 9851 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9852 | pr.println("*** Mobile network active adjusted timer:"); |
| 9853 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9854 | pr.println("*** Wifi timer:"); |
| 9855 | mWifiOnTimer.logState(pr, " "); |
| 9856 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9857 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9858 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9859 | pr.println("*** Wifi state #" + i + ":"); |
| 9860 | mWifiStateTimer[i].logState(pr, " "); |
| 9861 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9862 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9863 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 9864 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 9865 | } |
| 9866 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9867 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 9868 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 9869 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9870 | pr.println("*** Bluetooth timer:"); |
| 9871 | mBluetoothOnTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9872 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9873 | pr.println("*** Bluetooth active type #" + i + ":"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9874 | mBluetoothStateTimer[i].logState(pr, " "); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9875 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9876 | pr.println("*** Flashlight timer:"); |
| 9877 | mFlashlightOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9878 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 9879 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9880 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9881 | } |