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 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 19 | import static android.net.NetworkStats.UID_ALL; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 20 | import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 21 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothDevice; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 24 | import android.bluetooth.BluetoothHeadset; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 26 | import android.net.ConnectivityManager; |
| 27 | import android.net.NetworkStats; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 29 | import android.os.BadParcelableException; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 30 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.BatteryStats; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 32 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 34 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 35 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.ParcelFormatException; |
| 38 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 39 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 41 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 42 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 43 | import android.telephony.DataConnectionRealTimeInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 44 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 45 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 46 | import android.telephony.TelephonyManager; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 47 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 49 | import android.util.LogWriter; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 50 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 52 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 54 | import android.util.SparseIntArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 55 | import android.util.TimeUtils; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 56 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 58 | import com.android.internal.annotations.GuardedBy; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 59 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 60 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 61 | import com.android.internal.util.FastPrintWriter; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 62 | import com.android.internal.util.JournaledFile; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 63 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import java.io.File; |
| 65 | import java.io.FileInputStream; |
| 66 | import java.io.FileOutputStream; |
| 67 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 68 | import java.io.PrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import java.util.ArrayList; |
| 70 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 71 | import java.util.Iterator; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 72 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 74 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 75 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * All information we are collecting about things that can happen that impact |
| 79 | * battery life. All times are represented in microseconds except where indicated |
| 80 | * otherwise. |
| 81 | */ |
| 82 | public final class BatteryStatsImpl extends BatteryStats { |
| 83 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 84 | private static final boolean DEBUG = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 85 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 86 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 87 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 88 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | // 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] | 91 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | // Current on-disk Parcel version |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 94 | private static final int VERSION = 112 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 95 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 96 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 97 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 99 | // No, really, THIS is the maximum number of items we will record in the history. |
| 100 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 101 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 102 | // The maximum number of names wakelocks we will keep track of |
| 103 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 104 | // in to one common name. |
Dianne Hackborn | af17baa | 2013-05-09 15:27:47 -0700 | [diff] [blame] | 105 | private static final int MAX_WAKELOCKS_PER_UID = 50; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 106 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 107 | private static final String BATCHED_WAKELOCK_NAME = "*overflow*"; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 108 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 109 | private static int sNumSpeedSteps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 111 | private final JournaledFile mFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 113 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 114 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 115 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 116 | |
| 117 | public interface BatteryCallback { |
| 118 | public void batteryNeedsCpuUpdate(); |
| 119 | public void batteryPowerChanged(boolean onBattery); |
| 120 | } |
| 121 | |
| 122 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 123 | public MyHandler(Looper looper) { |
| 124 | super(looper, null, true); |
| 125 | } |
| 126 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 127 | @Override |
| 128 | public void handleMessage(Message msg) { |
| 129 | BatteryCallback cb = mCallback; |
| 130 | switch (msg.what) { |
| 131 | case MSG_UPDATE_WAKELOCKS: |
| 132 | if (cb != null) { |
| 133 | cb.batteryNeedsCpuUpdate(); |
| 134 | } |
| 135 | break; |
| 136 | case MSG_REPORT_POWER_CHANGE: |
| 137 | if (cb != null) { |
| 138 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 139 | } |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | private final MyHandler mHandler; |
| 146 | |
| 147 | private BatteryCallback mCallback; |
| 148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 150 | * Mapping isolated uids to the actual owning app uid. |
| 151 | */ |
| 152 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 153 | |
| 154 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | * The statistics we have collected organized by uids. |
| 156 | */ |
| 157 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 158 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 159 | |
| 160 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 161 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 162 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 163 | // changes. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 164 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<StopwatchTimer>(); |
| 165 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<StopwatchTimer>(); |
| 166 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<StopwatchTimer>(); |
| 167 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers |
| 168 | = new SparseArray<ArrayList<StopwatchTimer>>(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 169 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<StopwatchTimer>(); |
| 170 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<StopwatchTimer>(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 171 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<StopwatchTimer>(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 172 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 173 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = |
| 174 | new SparseArray<ArrayList<StopwatchTimer>>(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 175 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<StopwatchTimer>(); |
| 176 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 178 | // Last partial timers we use for distributing CPU usage. |
| 179 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); |
| 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | // These are the objects that will want to do something when the device |
| 182 | // is unplugged from power. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 183 | final TimeBase mOnBatteryTimeBase = new TimeBase(); |
| 184 | |
| 185 | // These are the objects that will want to do something when the device |
| 186 | // is unplugged from power *and* the screen is off. |
| 187 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 188 | |
| 189 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 190 | // CPU update, even if we aren't currently running wake locks. |
| 191 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 192 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 193 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 194 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 195 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 196 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 197 | long mHistoryBaseTime; |
| 198 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 199 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 200 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 201 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 202 | static final int MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 203 | static final int MAX_MAX_HISTORY_BUFFER = 144*1024; // 144KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 204 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 205 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 206 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 207 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 208 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 209 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<HistoryTag, Integer>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 210 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 211 | int[] mReadHistoryUids; |
| 212 | int mReadHistoryChars; |
| 213 | int mNextHistoryTagIdx = 0; |
| 214 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 215 | int mHistoryBufferLastPos = -1; |
| 216 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 217 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 218 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 219 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 220 | |
| 221 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 222 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 223 | HistoryItem mHistory; |
| 224 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 225 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 226 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 227 | |
| 228 | private HistoryItem mHistoryIterator; |
| 229 | private boolean mReadOverflow; |
| 230 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | int mStartCount; |
| 233 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 234 | long mStartClockTime; |
| 235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | long mUptime; |
| 237 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | long mRealtime; |
| 239 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 240 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 241 | int mWakeLockNesting; |
| 242 | boolean mWakeLockImportant; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 243 | boolean mRecordAllWakeLocks; |
| 244 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 245 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 246 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 247 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 248 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 249 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 250 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 251 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 252 | boolean mInteractive; |
| 253 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 254 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 255 | boolean mLowPowerModeEnabled; |
| 256 | StopwatchTimer mLowPowerModeEnabledTimer; |
| 257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 259 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 260 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 261 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 262 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 263 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 264 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 265 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 266 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 267 | boolean mFlashlightOn; |
| 268 | StopwatchTimer mFlashlightOnTimer; |
| 269 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 270 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 271 | int mPhoneSignalStrengthBinRaw = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 272 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 273 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 274 | |
| 275 | StopwatchTimer mPhoneSignalScanningTimer; |
| 276 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 277 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 278 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 279 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 280 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 281 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 282 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 283 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 284 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 285 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 286 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 287 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 288 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 289 | boolean mGlobalWifiRunning; |
| 290 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 291 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 292 | int mWifiState = -1; |
| 293 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 294 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 295 | int mWifiSupplState = -1; |
| 296 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 297 | |
| 298 | int mWifiSignalStrengthBin = -1; |
| 299 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 300 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 301 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 302 | boolean mBluetoothOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 303 | StopwatchTimer mBluetoothOnTimer; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 304 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 305 | int mBluetoothState = -1; |
| 306 | final StopwatchTimer[] mBluetoothStateTimer = new StopwatchTimer[NUM_BLUETOOTH_STATES]; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 307 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 308 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 309 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 310 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 311 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 312 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 313 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 314 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 315 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 316 | /** Bluetooth headset object */ |
| 317 | BluetoothHeadset mBtHeadset; |
| 318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | /** |
| 320 | * These provide time bases that discount the time the device is plugged |
| 321 | * in to power. |
| 322 | */ |
| 323 | boolean mOnBattery; |
| 324 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 326 | /* |
| 327 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 328 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 329 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 330 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 331 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 332 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 333 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 334 | int mLowDischargeAmountSinceCharge; |
| 335 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 336 | int mDischargeScreenOnUnplugLevel; |
| 337 | int mDischargeScreenOffUnplugLevel; |
| 338 | int mDischargeAmountScreenOn; |
| 339 | int mDischargeAmountScreenOnSinceCharge; |
| 340 | int mDischargeAmountScreenOff; |
| 341 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 343 | static final int MAX_LEVEL_STEPS = 100; |
| 344 | |
| 345 | int mLastDischargeStepLevel; |
| 346 | long mLastDischargeStepTime; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 347 | int mMinDischargeStepLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 348 | int mNumDischargeStepDurations; |
| 349 | final long[] mDischargeStepDurations = new long[MAX_LEVEL_STEPS]; |
| 350 | |
| 351 | int mLastChargeStepLevel; |
| 352 | long mLastChargeStepTime; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 353 | int mMaxChargeStepLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 354 | int mNumChargeStepDurations; |
| 355 | final long[] mChargeStepDurations = new long[MAX_LEVEL_STEPS]; |
| 356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 358 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 359 | private int mBluetoothPingCount; |
| 360 | private int mBluetoothPingStart = -1; |
| 361 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 362 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 363 | private int mPhoneServiceStateRaw = -1; |
| 364 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 365 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 366 | /* |
| 367 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 368 | */ |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 369 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 370 | new HashMap<String, SamplingTimer>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 371 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 372 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 373 | return mKernelWakelockStats; |
| 374 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 375 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 376 | private static int sKernelWakelockUpdateVersion = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 377 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 378 | String mLastWakeupReason = null; |
| 379 | long mLastWakeupUptimeMs = 0; |
| 380 | private final HashMap<String, LongSamplingCounter> mWakeupReasonStats = |
| 381 | new HashMap<String, LongSamplingCounter>(); |
| 382 | |
| 383 | public Map<String, ? extends LongCounter> getWakeupReasonStats() { |
| 384 | return mWakeupReasonStats; |
| 385 | } |
| 386 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 387 | private static final int[] PROC_WAKELOCKS_FORMAT = new int[] { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 388 | Process.PROC_TAB_TERM|Process.PROC_OUT_STRING| // 0: name |
| 389 | Process.PROC_QUOTES, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 390 | Process.PROC_TAB_TERM|Process.PROC_OUT_LONG, // 1: count |
| 391 | Process.PROC_TAB_TERM, |
| 392 | Process.PROC_TAB_TERM, |
| 393 | Process.PROC_TAB_TERM, |
| 394 | Process.PROC_TAB_TERM|Process.PROC_OUT_LONG, // 5: totalTime |
| 395 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 396 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 397 | private static final int[] WAKEUP_SOURCES_FORMAT = new int[] { |
| 398 | Process.PROC_TAB_TERM|Process.PROC_OUT_STRING, // 0: name |
| 399 | Process.PROC_TAB_TERM|Process.PROC_COMBINE| |
| 400 | Process.PROC_OUT_LONG, // 1: count |
| 401 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 402 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 403 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 404 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 405 | Process.PROC_TAB_TERM|Process.PROC_COMBINE |
| 406 | |Process.PROC_OUT_LONG, // 6: totalTime |
| 407 | }; |
| 408 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 409 | private final String[] mProcWakelocksName = new String[3]; |
| 410 | private final long[] mProcWakelocksData = new long[3]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 411 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 412 | /* |
| 413 | * Used as a buffer for reading in data from /proc/wakelocks before it is processed and added |
| 414 | * to mKernelWakelockStats. |
| 415 | */ |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 416 | private final Map<String, KernelWakelockStats> mProcWakelockFileStats = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 417 | new HashMap<String, KernelWakelockStats>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 419 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 420 | private NetworkStats mCurMobileSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
| 421 | private NetworkStats mLastMobileSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
| 422 | private NetworkStats mCurWifiSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
| 423 | private NetworkStats mLastWifiSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 424 | private NetworkStats mTmpNetworkStats; |
| 425 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 426 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 427 | @GuardedBy("this") |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 428 | private String[] mMobileIfaces = new String[0]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 429 | @GuardedBy("this") |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 430 | private String[] mWifiIfaces = new String[0]; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | // For debugging |
| 433 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 434 | mFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 435 | mHandler = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 438 | public static interface TimeBaseObs { |
| 439 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 440 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 441 | } |
| 442 | |
| 443 | static class TimeBase { |
| 444 | private final ArrayList<TimeBaseObs> mObservers = new ArrayList<TimeBaseObs>(); |
| 445 | |
| 446 | private long mUptime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 447 | private long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 448 | |
| 449 | private boolean mRunning; |
| 450 | |
| 451 | private long mPastUptime; |
| 452 | private long mUptimeStart; |
| 453 | private long mPastRealtime; |
| 454 | private long mRealtimeStart; |
| 455 | private long mUnpluggedUptime; |
| 456 | private long mUnpluggedRealtime; |
| 457 | |
| 458 | public void dump(PrintWriter pw, String prefix) { |
| 459 | StringBuilder sb = new StringBuilder(128); |
| 460 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 461 | sb.setLength(0); |
| 462 | sb.append(prefix); |
| 463 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 464 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 465 | pw.println(sb.toString()); |
| 466 | sb.setLength(0); |
| 467 | sb.append(prefix); |
| 468 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 469 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 470 | pw.println(sb.toString()); |
| 471 | sb.setLength(0); |
| 472 | sb.append(prefix); |
| 473 | sb.append("mPastUptime="); |
| 474 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 475 | formatTimeMs(sb, mUptimeStart / 1000); |
| 476 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 477 | pw.println(sb.toString()); |
| 478 | sb.setLength(0); |
| 479 | sb.append(prefix); |
| 480 | sb.append("mPastRealtime="); |
| 481 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 482 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 483 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 484 | pw.println(sb.toString()); |
| 485 | } |
| 486 | |
| 487 | public void add(TimeBaseObs observer) { |
| 488 | mObservers.add(observer); |
| 489 | } |
| 490 | |
| 491 | public void remove(TimeBaseObs observer) { |
| 492 | if (!mObservers.remove(observer)) { |
| 493 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | public void init(long uptime, long realtime) { |
| 498 | mRealtime = 0; |
| 499 | mUptime = 0; |
| 500 | mPastUptime = 0; |
| 501 | mPastRealtime = 0; |
| 502 | mUptimeStart = uptime; |
| 503 | mRealtimeStart = realtime; |
| 504 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 505 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 506 | } |
| 507 | |
| 508 | public void reset(long uptime, long realtime) { |
| 509 | if (!mRunning) { |
| 510 | mPastUptime = 0; |
| 511 | mPastRealtime = 0; |
| 512 | } else { |
| 513 | mUptimeStart = uptime; |
| 514 | mRealtimeStart = realtime; |
| 515 | mUnpluggedUptime = getUptime(uptime); |
| 516 | mUnpluggedRealtime = getRealtime(realtime); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | public long computeUptime(long curTime, int which) { |
| 521 | switch (which) { |
| 522 | case STATS_SINCE_CHARGED: |
| 523 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 524 | case STATS_CURRENT: |
| 525 | return getUptime(curTime); |
| 526 | case STATS_SINCE_UNPLUGGED: |
| 527 | return getUptime(curTime) - mUnpluggedUptime; |
| 528 | } |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | public long computeRealtime(long curTime, int which) { |
| 533 | switch (which) { |
| 534 | case STATS_SINCE_CHARGED: |
| 535 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 536 | case STATS_CURRENT: |
| 537 | return getRealtime(curTime); |
| 538 | case STATS_SINCE_UNPLUGGED: |
| 539 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 540 | } |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | public long getUptime(long curTime) { |
| 545 | long time = mPastUptime; |
| 546 | if (mRunning) { |
| 547 | time += curTime - mUptimeStart; |
| 548 | } |
| 549 | return time; |
| 550 | } |
| 551 | |
| 552 | public long getRealtime(long curTime) { |
| 553 | long time = mPastRealtime; |
| 554 | if (mRunning) { |
| 555 | time += curTime - mRealtimeStart; |
| 556 | } |
| 557 | return time; |
| 558 | } |
| 559 | |
| 560 | public long getUptimeStart() { |
| 561 | return mUptimeStart; |
| 562 | } |
| 563 | |
| 564 | public long getRealtimeStart() { |
| 565 | return mRealtimeStart; |
| 566 | } |
| 567 | |
| 568 | public boolean isRunning() { |
| 569 | return mRunning; |
| 570 | } |
| 571 | |
| 572 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 573 | if (mRunning != running) { |
| 574 | mRunning = running; |
| 575 | if (running) { |
| 576 | mUptimeStart = uptime; |
| 577 | mRealtimeStart = realtime; |
| 578 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 579 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 580 | |
| 581 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 582 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 583 | } |
| 584 | } else { |
| 585 | mPastUptime += uptime - mUptimeStart; |
| 586 | mPastRealtime += realtime - mRealtimeStart; |
| 587 | |
| 588 | long batteryUptime = getUptime(uptime); |
| 589 | long batteryRealtime = getRealtime(realtime); |
| 590 | |
| 591 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 592 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 593 | } |
| 594 | } |
| 595 | return true; |
| 596 | } |
| 597 | return false; |
| 598 | } |
| 599 | |
| 600 | public void readSummaryFromParcel(Parcel in) { |
| 601 | mUptime = in.readLong(); |
| 602 | mRealtime = in.readLong(); |
| 603 | } |
| 604 | |
| 605 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 606 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 607 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 608 | } |
| 609 | |
| 610 | public void readFromParcel(Parcel in) { |
| 611 | mRunning = false; |
| 612 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 613 | mPastUptime = in.readLong(); |
| 614 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 615 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 616 | mPastRealtime = in.readLong(); |
| 617 | mRealtimeStart = in.readLong(); |
| 618 | mUnpluggedUptime = in.readLong(); |
| 619 | mUnpluggedRealtime = in.readLong(); |
| 620 | } |
| 621 | |
| 622 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 623 | final long runningUptime = getUptime(uptime); |
| 624 | final long runningRealtime = getRealtime(realtime); |
| 625 | out.writeLong(mUptime); |
| 626 | out.writeLong(runningUptime); |
| 627 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 628 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 629 | out.writeLong(runningRealtime); |
| 630 | out.writeLong(mRealtimeStart); |
| 631 | out.writeLong(mUnpluggedUptime); |
| 632 | out.writeLong(mUnpluggedRealtime); |
| 633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 637 | * State for keeping track of counting information. |
| 638 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 639 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 640 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 641 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 642 | int mLoadedCount; |
| 643 | int mLastCount; |
| 644 | int mUnpluggedCount; |
| 645 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 646 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 647 | Counter(TimeBase timeBase, Parcel in) { |
| 648 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 649 | mPluggedCount = in.readInt(); |
| 650 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 651 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 652 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 653 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 654 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 657 | Counter(TimeBase timeBase) { |
| 658 | mTimeBase = timeBase; |
| 659 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 660 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 661 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 662 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 663 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 664 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 665 | out.writeInt(mUnpluggedCount); |
| 666 | } |
| 667 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 668 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 669 | mUnpluggedCount = mPluggedCount; |
| 670 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 673 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 674 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 675 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 676 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 677 | /** |
| 678 | * Writes a possibly null Counter to a Parcel. |
| 679 | * |
| 680 | * @param out the Parcel to be written to. |
| 681 | * @param counter a Counter, or null. |
| 682 | */ |
| 683 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 684 | if (counter == null) { |
| 685 | out.writeInt(0); // indicates null |
| 686 | return; |
| 687 | } |
| 688 | out.writeInt(1); // indicates non-null |
| 689 | |
| 690 | counter.writeToParcel(out); |
| 691 | } |
| 692 | |
| 693 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 694 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 695 | int val = mCount.get(); |
| 696 | if (which == STATS_SINCE_UNPLUGGED) { |
| 697 | val -= mUnpluggedCount; |
| 698 | } else if (which != STATS_SINCE_CHARGED) { |
| 699 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | return val; |
| 703 | } |
| 704 | |
| 705 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 706 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 707 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 708 | + " mUnpluggedCount=" + mUnpluggedCount |
| 709 | + " mPluggedCount=" + mPluggedCount); |
| 710 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 711 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 712 | void stepAtomic() { |
| 713 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 716 | /** |
| 717 | * Clear state of this counter. |
| 718 | */ |
| 719 | void reset(boolean detachIfReset) { |
| 720 | mCount.set(0); |
| 721 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 722 | if (detachIfReset) { |
| 723 | detach(); |
| 724 | } |
| 725 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 726 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 727 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 728 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 729 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 730 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 731 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 732 | int count = mCount.get(); |
| 733 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 737 | mLoadedCount = in.readInt(); |
| 738 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 739 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 740 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 741 | } |
| 742 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 743 | |
| 744 | public static class SamplingCounter extends Counter { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 745 | SamplingCounter(TimeBase timeBase, Parcel in) { |
| 746 | super(timeBase, in); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 749 | SamplingCounter(TimeBase timeBase) { |
| 750 | super(timeBase); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 753 | public void addCountAtomic(long count) { |
| 754 | mCount.addAndGet((int)count); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 758 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 759 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 760 | long mCount; |
| 761 | long mLoadedCount; |
| 762 | long mLastCount; |
| 763 | long mUnpluggedCount; |
| 764 | long mPluggedCount; |
| 765 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 766 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 767 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 768 | mPluggedCount = in.readLong(); |
| 769 | mCount = mPluggedCount; |
| 770 | mLoadedCount = in.readLong(); |
| 771 | mLastCount = 0; |
| 772 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 773 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 776 | LongSamplingCounter(TimeBase timeBase) { |
| 777 | mTimeBase = timeBase; |
| 778 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | public void writeToParcel(Parcel out) { |
| 782 | out.writeLong(mCount); |
| 783 | out.writeLong(mLoadedCount); |
| 784 | out.writeLong(mUnpluggedCount); |
| 785 | } |
| 786 | |
| 787 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 788 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 789 | mUnpluggedCount = mPluggedCount; |
| 790 | mCount = mPluggedCount; |
| 791 | } |
| 792 | |
| 793 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 794 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 795 | mPluggedCount = mCount; |
| 796 | } |
| 797 | |
| 798 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 799 | long val = mCount; |
| 800 | if (which == STATS_SINCE_UNPLUGGED) { |
| 801 | val -= mUnpluggedCount; |
| 802 | } else if (which != STATS_SINCE_CHARGED) { |
| 803 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | return val; |
| 807 | } |
| 808 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 809 | @Override |
| 810 | public void logState(Printer pw, String prefix) { |
| 811 | pw.println(prefix + "mCount=" + mCount |
| 812 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 813 | + " mUnpluggedCount=" + mUnpluggedCount |
| 814 | + " mPluggedCount=" + mPluggedCount); |
| 815 | } |
| 816 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 817 | void addCountLocked(long count) { |
| 818 | mCount += count; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * Clear state of this counter. |
| 823 | */ |
| 824 | void reset(boolean detachIfReset) { |
| 825 | mCount = 0; |
| 826 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 827 | if (detachIfReset) { |
| 828 | detach(); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 833 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | void writeSummaryFromParcelLocked(Parcel out) { |
| 837 | out.writeLong(mCount); |
| 838 | } |
| 839 | |
| 840 | void readSummaryFromParcelLocked(Parcel in) { |
| 841 | mLoadedCount = in.readLong(); |
| 842 | mCount = mLoadedCount; |
| 843 | mLastCount = 0; |
| 844 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 845 | } |
| 846 | } |
| 847 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 848 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | * State for keeping track of timing information. |
| 850 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 851 | 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] | 852 | final int mType; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 853 | final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | int mCount; |
| 856 | int mLoadedCount; |
| 857 | int mLastCount; |
| 858 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | // Times are in microseconds for better accuracy when dividing by the |
| 861 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | /** |
| 864 | * The total time we have accumulated since the start of the original |
| 865 | * boot, to the last time something interesting happened in the |
| 866 | * current run. |
| 867 | */ |
| 868 | long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | /** |
| 871 | * The total time we loaded for the previous runs. Subtract this from |
| 872 | * mTotalTime to find the time for the current run of the system. |
| 873 | */ |
| 874 | long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | /** |
| 877 | * The run time of the last run of the system, as loaded from the |
| 878 | * saved data. |
| 879 | */ |
| 880 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | /** |
| 883 | * The value of mTotalTime when unplug() was last called. Subtract |
| 884 | * this from mTotalTime to find the time since the last unplug from |
| 885 | * power. |
| 886 | */ |
| 887 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 888 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 889 | /** |
| 890 | * Constructs from a parcel. |
| 891 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 892 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 893 | * @param in |
| 894 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 895 | Timer(int type, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 897 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | mCount = in.readInt(); |
| 900 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 901 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | mUnpluggedCount = in.readInt(); |
| 903 | mTotalTime = in.readLong(); |
| 904 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 905 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | mUnpluggedTime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 907 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 908 | 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] | 909 | } |
| 910 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 911 | Timer(int type, TimeBase timeBase) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 913 | mTimeBase = timeBase; |
| 914 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 916 | |
| 917 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 918 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 919 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 920 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 921 | /** |
| 922 | * Clear state of this timer. Returns true if the timer is inactive |
| 923 | * so can be completely dropped. |
| 924 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 925 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 926 | mTotalTime = mLoadedTime = mLastTime = 0; |
| 927 | mCount = mLoadedCount = mLastCount = 0; |
| 928 | if (detachIfReset) { |
| 929 | detach(); |
| 930 | } |
| 931 | return true; |
| 932 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 933 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 934 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 935 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 936 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 937 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 938 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 939 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 940 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | out.writeInt(mCount); |
| 942 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 944 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | out.writeLong(mUnpluggedTime); |
| 947 | } |
| 948 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 949 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 951 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 953 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 954 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 955 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | mUnpluggedCount = mCount; |
| 957 | if (DEBUG && mType < 0) { |
| 958 | Log.v(TAG, "unplug #" + mType |
| 959 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 960 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 961 | } |
| 962 | } |
| 963 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 964 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 965 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 966 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 967 | + " old mTotalTime=" + mTotalTime); |
| 968 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 969 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 970 | mCount = computeCurrentCountLocked(); |
| 971 | if (DEBUG && mType < 0) { |
| 972 | Log.v(TAG, "plug #" + mType |
| 973 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | } |
| 975 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | /** |
| 978 | * Writes a possibly null Timer to a Parcel. |
| 979 | * |
| 980 | * @param out the Parcel to be written to. |
| 981 | * @param timer a Timer, or null. |
| 982 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 983 | 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] | 984 | if (timer == null) { |
| 985 | out.writeInt(0); // indicates null |
| 986 | return; |
| 987 | } |
| 988 | out.writeInt(1); // indicates non-null |
| 989 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 990 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 994 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 995 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 996 | if (which == STATS_SINCE_UNPLUGGED) { |
| 997 | val -= mUnpluggedTime; |
| 998 | } else if (which != STATS_SINCE_CHARGED) { |
| 999 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | return val; |
| 1003 | } |
| 1004 | |
| 1005 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1006 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1007 | int val = computeCurrentCountLocked(); |
| 1008 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1009 | val -= mUnpluggedCount; |
| 1010 | } else if (which != STATS_SINCE_CHARGED) { |
| 1011 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | return val; |
| 1015 | } |
| 1016 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1017 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1018 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1020 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1021 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1023 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1025 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1026 | |
| 1027 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1028 | void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1029 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1030 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1031 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | void readSummaryFromParcelLocked(Parcel in) { |
| 1035 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1036 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1037 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1038 | mUnpluggedTime = mTotalTime; |
| 1039 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1040 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1041 | mUnpluggedCount = mCount; |
| 1042 | } |
| 1043 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1044 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1045 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1046 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1047 | /** |
| 1048 | * The most recent reported count from /proc/wakelocks. |
| 1049 | */ |
| 1050 | int mCurrentReportedCount; |
| 1051 | |
| 1052 | /** |
| 1053 | * The reported count from /proc/wakelocks when unplug() was last |
| 1054 | * called. |
| 1055 | */ |
| 1056 | int mUnpluggedReportedCount; |
| 1057 | |
| 1058 | /** |
| 1059 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1060 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1061 | long mCurrentReportedTotalTime; |
| 1062 | |
| 1063 | |
| 1064 | /** |
| 1065 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1066 | * called. |
| 1067 | */ |
| 1068 | long mUnpluggedReportedTotalTime; |
| 1069 | |
| 1070 | /** |
| 1071 | * Whether we are currently in a discharge cycle. |
| 1072 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1073 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1074 | |
| 1075 | /** |
| 1076 | * Whether we are currently recording reported values. |
| 1077 | */ |
| 1078 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1079 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1080 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1081 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1082 | */ |
| 1083 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1084 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1085 | SamplingTimer(TimeBase timeBase, Parcel in) { |
| 1086 | super(0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1087 | mCurrentReportedCount = in.readInt(); |
| 1088 | mUnpluggedReportedCount = in.readInt(); |
| 1089 | mCurrentReportedTotalTime = in.readLong(); |
| 1090 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1091 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1092 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1093 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1094 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1095 | SamplingTimer(TimeBase timeBase, boolean trackReportedValues) { |
| 1096 | super(0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1097 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1098 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1099 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1100 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1101 | public void setStale() { |
| 1102 | mTrackingReportedValues = false; |
| 1103 | mUnpluggedReportedTotalTime = 0; |
| 1104 | mUnpluggedReportedCount = 0; |
| 1105 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1106 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1107 | public void setUpdateVersion(int version) { |
| 1108 | mUpdateVersion = version; |
| 1109 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1110 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1111 | public int getUpdateVersion() { |
| 1112 | return mUpdateVersion; |
| 1113 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1114 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1115 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1116 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1117 | // Updating the reported value for the first time. |
| 1118 | mUnpluggedReportedCount = count; |
| 1119 | // If we are receiving an update update mTrackingReportedValues; |
| 1120 | mTrackingReportedValues = true; |
| 1121 | } |
| 1122 | mCurrentReportedCount = count; |
| 1123 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1124 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1125 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1126 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1127 | // Updating the reported value for the first time. |
| 1128 | mUnpluggedReportedTotalTime = totalTime; |
| 1129 | // If we are receiving an update update mTrackingReportedValues; |
| 1130 | mTrackingReportedValues = true; |
| 1131 | } |
| 1132 | mCurrentReportedTotalTime = totalTime; |
| 1133 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1134 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1135 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1136 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1137 | if (mTrackingReportedValues) { |
| 1138 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1139 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1140 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1141 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1144 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1145 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1146 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1147 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1148 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1149 | public void logState(Printer pw, String prefix) { |
| 1150 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1151 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1152 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1153 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1154 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1155 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1156 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1157 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1158 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1159 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1160 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1161 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1162 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1163 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1164 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1165 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1166 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1167 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1168 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1169 | out.writeInt(mCurrentReportedCount); |
| 1170 | out.writeInt(mUnpluggedReportedCount); |
| 1171 | out.writeLong(mCurrentReportedTotalTime); |
| 1172 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1173 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1174 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1175 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1176 | boolean reset(boolean detachIfReset) { |
| 1177 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1178 | setStale(); |
| 1179 | return true; |
| 1180 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1181 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1182 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 1183 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1184 | out.writeLong(mCurrentReportedTotalTime); |
| 1185 | out.writeInt(mCurrentReportedCount); |
| 1186 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1187 | } |
| 1188 | |
| 1189 | void readSummaryFromParcelLocked(Parcel in) { |
| 1190 | super.readSummaryFromParcelLocked(in); |
| 1191 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1192 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1193 | mTrackingReportedValues = in.readInt() == 1; |
| 1194 | } |
| 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 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1198 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1199 | * for a pre-determined amount. |
| 1200 | */ |
| 1201 | public static final class BatchTimer extends Timer { |
| 1202 | final Uid mUid; |
| 1203 | |
| 1204 | /** |
| 1205 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1206 | */ |
| 1207 | long mLastAddedTime; |
| 1208 | |
| 1209 | /** |
| 1210 | * The last duration that we added to the timer. This is in microseconds. |
| 1211 | */ |
| 1212 | long mLastAddedDuration; |
| 1213 | |
| 1214 | /** |
| 1215 | * Whether we are currently in a discharge cycle. |
| 1216 | */ |
| 1217 | boolean mInDischarge; |
| 1218 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1219 | BatchTimer(Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1220 | super(type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1221 | mUid = uid; |
| 1222 | mLastAddedTime = in.readLong(); |
| 1223 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1224 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1227 | BatchTimer(Uid uid, int type, TimeBase timeBase) { |
| 1228 | super(type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1229 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1230 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1234 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1235 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1236 | out.writeLong(mLastAddedTime); |
| 1237 | out.writeLong(mLastAddedDuration); |
| 1238 | } |
| 1239 | |
| 1240 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1241 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1242 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 1243 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1244 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1248 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1249 | recomputeLastDuration(elapsedRealtime, false); |
| 1250 | mInDischarge = true; |
| 1251 | // If we are still within the last added duration, then re-added whatever remains. |
| 1252 | if (mLastAddedTime == elapsedRealtime) { |
| 1253 | mTotalTime += mLastAddedDuration; |
| 1254 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1255 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | @Override |
| 1259 | public void logState(Printer pw, String prefix) { |
| 1260 | super.logState(pw, prefix); |
| 1261 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1262 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1263 | } |
| 1264 | |
| 1265 | private long computeOverage(long curTime) { |
| 1266 | if (mLastAddedTime > 0) { |
| 1267 | return mLastTime + mLastAddedDuration - curTime; |
| 1268 | } |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1273 | final long overage = computeOverage(curTime); |
| 1274 | if (overage > 0) { |
| 1275 | // Aborting before the duration ran out -- roll back the remaining |
| 1276 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1277 | // actually add the time. |
| 1278 | if (mInDischarge) { |
| 1279 | mTotalTime -= overage; |
| 1280 | } |
| 1281 | if (abort) { |
| 1282 | mLastAddedTime = 0; |
| 1283 | } else { |
| 1284 | mLastAddedTime = curTime; |
| 1285 | mLastAddedDuration -= overage; |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1291 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1292 | recomputeLastDuration(now, true); |
| 1293 | mLastAddedTime = now; |
| 1294 | mLastAddedDuration = durationMillis * 1000; |
| 1295 | if (mInDischarge) { |
| 1296 | mTotalTime += mLastAddedDuration; |
| 1297 | mCount++; |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1302 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1303 | recomputeLastDuration(now, true); |
| 1304 | } |
| 1305 | |
| 1306 | @Override |
| 1307 | protected int computeCurrentCountLocked() { |
| 1308 | return mCount; |
| 1309 | } |
| 1310 | |
| 1311 | @Override |
| 1312 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1313 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1314 | if (overage > 0) { |
| 1315 | return mTotalTime = overage; |
| 1316 | } |
| 1317 | return mTotalTime; |
| 1318 | } |
| 1319 | |
| 1320 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1321 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1322 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1323 | recomputeLastDuration(now, true); |
| 1324 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1325 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1326 | return !stillActive; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1331 | * State for keeping track of timing information. |
| 1332 | */ |
| 1333 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1334 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1335 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1336 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1337 | int mNesting; |
| 1338 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1339 | /** |
| 1340 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1341 | * subtract this from the current battery time to find the amount of |
| 1342 | * time we have been running since we last computed an update. |
| 1343 | */ |
| 1344 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1345 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1346 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1347 | * 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] | 1348 | * was actually held for an interesting duration. |
| 1349 | */ |
| 1350 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1351 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1352 | long mTimeout; |
| 1353 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1354 | /** |
| 1355 | * For partial wake locks, keep track of whether we are in the list |
| 1356 | * to consume CPU cycles. |
| 1357 | */ |
| 1358 | boolean mInList; |
| 1359 | |
| 1360 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1361 | TimeBase timeBase, Parcel in) { |
| 1362 | super(type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1363 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1364 | mTimerPool = timerPool; |
| 1365 | mUpdateTime = in.readLong(); |
| 1366 | } |
| 1367 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1368 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1369 | TimeBase timeBase) { |
| 1370 | super(type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1371 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1372 | mTimerPool = timerPool; |
| 1373 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1374 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1375 | void setTimeout(long timeout) { |
| 1376 | mTimeout = timeout; |
| 1377 | } |
| 1378 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1379 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1380 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1381 | out.writeLong(mUpdateTime); |
| 1382 | } |
| 1383 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1384 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1385 | if (mNesting > 0) { |
| 1386 | if (DEBUG && mType < 0) { |
| 1387 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1388 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1389 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1390 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1391 | if (DEBUG && mType < 0) { |
| 1392 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | public void logState(Printer pw, String prefix) { |
| 1398 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1399 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | + " mAcquireTime=" + mAcquireTime); |
| 1401 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1402 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1403 | void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1405 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1406 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | if (mTimerPool != null) { |
| 1408 | // Accumulate time to all currently active timers before adding |
| 1409 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1410 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | // Add this timer to the active pool |
| 1412 | mTimerPool.add(this); |
| 1413 | } |
| 1414 | // Increment the count |
| 1415 | mCount++; |
| 1416 | mAcquireTime = mTotalTime; |
| 1417 | if (DEBUG && mType < 0) { |
| 1418 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1419 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1420 | + " mAcquireTime=" + mAcquireTime); |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1425 | boolean isRunningLocked() { |
| 1426 | return mNesting > 0; |
| 1427 | } |
| 1428 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1429 | long checkpointRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1430 | if (mNesting > 0) { |
| 1431 | // We are running... |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1432 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1433 | if (mTimerPool != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1434 | return refreshTimersLocked(batteryRealtime, mTimerPool, this); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1435 | } |
| 1436 | final long heldTime = batteryRealtime - mUpdateTime; |
| 1437 | mUpdateTime = batteryRealtime; |
| 1438 | mTotalTime += heldTime; |
| 1439 | return heldTime; |
| 1440 | } |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1444 | void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | // Ignore attempt to stop a timer that isn't running |
| 1446 | if (mNesting == 0) { |
| 1447 | return; |
| 1448 | } |
| 1449 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1450 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | if (mTimerPool != null) { |
| 1452 | // Accumulate time to all active counters, scaled by the total |
| 1453 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1454 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | // Remove this timer from the active pool |
| 1456 | mTimerPool.remove(this); |
| 1457 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | mNesting = 1; |
| 1459 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1460 | mNesting = 0; |
| 1461 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | if (DEBUG && mType < 0) { |
| 1464 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1465 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1466 | + " mAcquireTime=" + mAcquireTime); |
| 1467 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | if (mTotalTime == mAcquireTime) { |
| 1470 | // If there was no change in the time, then discard this |
| 1471 | // count. A somewhat cheezy strategy, but hey. |
| 1472 | mCount--; |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 1477 | void stopAllRunningLocked(long elapsedRealtimeMs) { |
| 1478 | if (mNesting > 0) { |
| 1479 | mNesting = 1; |
| 1480 | stopRunningLocked(elapsedRealtimeMs); |
| 1481 | } |
| 1482 | } |
| 1483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | // Update the total time for all other running Timers with the same type as this Timer |
| 1485 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1486 | private static long refreshTimersLocked(long batteryRealtime, |
| 1487 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1488 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | final int N = pool.size(); |
| 1490 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1491 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1493 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1494 | final long myTime = heldTime / N; |
| 1495 | if (t == self) { |
| 1496 | selfTime = myTime; |
| 1497 | } |
| 1498 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | } |
| 1500 | t.mUpdateTime = batteryRealtime; |
| 1501 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1502 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1505 | @Override |
| 1506 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1507 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1508 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | return mTotalTime + (mNesting > 0 |
| 1511 | ? (curBatteryRealtime - mUpdateTime) |
| 1512 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1513 | : 0); |
| 1514 | } |
| 1515 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1516 | @Override |
| 1517 | protected int computeCurrentCountLocked() { |
| 1518 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1521 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1522 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1523 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1524 | if (mNesting > 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1525 | mUpdateTime = mTimeBase.getRealtime(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1526 | } |
| 1527 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1528 | return canDetach; |
| 1529 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1530 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1531 | void detach() { |
| 1532 | super.detach(); |
| 1533 | if (mTimerPool != null) { |
| 1534 | mTimerPool.remove(this); |
| 1535 | } |
| 1536 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1539 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | mNesting = 0; |
| 1541 | } |
| 1542 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1543 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1544 | /* |
| 1545 | * Get the wakeup reason counter, and create a new one if one |
| 1546 | * doesn't already exist. |
| 1547 | */ |
| 1548 | public LongSamplingCounter getWakeupReasonCounterLocked(String name) { |
| 1549 | LongSamplingCounter counter = mWakeupReasonStats.get(name); |
| 1550 | if (counter == null) { |
| 1551 | counter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
| 1552 | mWakeupReasonStats.put(name, counter); |
| 1553 | } |
| 1554 | return counter; |
| 1555 | } |
| 1556 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1557 | private final Map<String, KernelWakelockStats> readKernelWakelockStats() { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1558 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1559 | FileInputStream is; |
Johannes Carlsson | 3372f2e | 2010-06-30 08:45:55 +0200 | [diff] [blame] | 1560 | byte[] buffer = new byte[8192]; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1561 | int len; |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1562 | boolean wakeup_sources = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1563 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1564 | try { |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1565 | try { |
| 1566 | is = new FileInputStream("/proc/wakelocks"); |
| 1567 | } catch (java.io.FileNotFoundException e) { |
| 1568 | try { |
| 1569 | is = new FileInputStream("/d/wakeup_sources"); |
| 1570 | wakeup_sources = true; |
| 1571 | } catch (java.io.FileNotFoundException e2) { |
| 1572 | return null; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1575 | |
| 1576 | len = is.read(buffer); |
| 1577 | is.close(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1578 | } catch (java.io.IOException e) { |
| 1579 | return null; |
| 1580 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1581 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1582 | if (len > 0) { |
| 1583 | int i; |
| 1584 | for (i=0; i<len; i++) { |
| 1585 | if (buffer[i] == '\0') { |
| 1586 | len = i; |
| 1587 | break; |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | return parseProcWakelocks(buffer, len, wakeup_sources); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1593 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1594 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1595 | private final Map<String, KernelWakelockStats> parseProcWakelocks( |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1596 | byte[] wlBuffer, int len, boolean wakeup_sources) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1597 | String name; |
| 1598 | int count; |
| 1599 | long totalTime; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 1600 | int startIndex; |
| 1601 | int endIndex; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1602 | int numUpdatedWlNames = 0; |
| 1603 | |
| 1604 | // Advance past the first line. |
| 1605 | int i; |
| 1606 | for (i = 0; i < len && wlBuffer[i] != '\n' && wlBuffer[i] != '\0'; i++); |
| 1607 | startIndex = endIndex = i + 1; |
| 1608 | |
| 1609 | synchronized(this) { |
| 1610 | Map<String, KernelWakelockStats> m = mProcWakelockFileStats; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1611 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1612 | sKernelWakelockUpdateVersion++; |
| 1613 | while (endIndex < len) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1614 | for (endIndex=startIndex; |
| 1615 | endIndex < len && wlBuffer[endIndex] != '\n' && wlBuffer[endIndex] != '\0'; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1616 | endIndex++); |
Johannes Carlsson | 3372f2e | 2010-06-30 08:45:55 +0200 | [diff] [blame] | 1617 | endIndex++; // endIndex is an exclusive upper bound. |
| 1618 | // Don't go over the end of the buffer, Process.parseProcLine might |
| 1619 | // write to wlBuffer[endIndex] |
| 1620 | if (endIndex >= (len - 1) ) { |
| 1621 | return m; |
Amith Yamasani | e579561 | 2010-04-05 12:43:44 -0700 | [diff] [blame] | 1622 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1623 | |
| 1624 | String[] nameStringArray = mProcWakelocksName; |
| 1625 | long[] wlData = mProcWakelocksData; |
Amith Yamasani | 2098ead | 2010-04-02 13:46:49 -0700 | [diff] [blame] | 1626 | // Stomp out any bad characters since this is from a circular buffer |
| 1627 | // A corruption is seen sometimes that results in the vm crashing |
| 1628 | // This should prevent crashes and the line will probably fail to parse |
| 1629 | for (int j = startIndex; j < endIndex; j++) { |
| 1630 | if ((wlBuffer[j] & 0x80) != 0) wlBuffer[j] = (byte) '?'; |
| 1631 | } |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1632 | boolean parsed = Process.parseProcLine(wlBuffer, startIndex, endIndex, |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1633 | wakeup_sources ? WAKEUP_SOURCES_FORMAT : |
| 1634 | PROC_WAKELOCKS_FORMAT, |
| 1635 | nameStringArray, wlData, null); |
Amith Yamasani | 2098ead | 2010-04-02 13:46:49 -0700 | [diff] [blame] | 1636 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1637 | name = nameStringArray[0]; |
| 1638 | count = (int) wlData[1]; |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1639 | |
| 1640 | if (wakeup_sources) { |
| 1641 | // convert milliseconds to microseconds |
| 1642 | totalTime = wlData[2] * 1000; |
| 1643 | } else { |
| 1644 | // convert nanoseconds to microseconds with rounding. |
| 1645 | totalTime = (wlData[2] + 500) / 1000; |
| 1646 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1647 | |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1648 | if (parsed && name.length() > 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1649 | if (!m.containsKey(name)) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1650 | m.put(name, new KernelWakelockStats(count, totalTime, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1651 | sKernelWakelockUpdateVersion)); |
| 1652 | numUpdatedWlNames++; |
| 1653 | } else { |
| 1654 | KernelWakelockStats kwlStats = m.get(name); |
| 1655 | if (kwlStats.mVersion == sKernelWakelockUpdateVersion) { |
| 1656 | kwlStats.mCount += count; |
| 1657 | kwlStats.mTotalTime += totalTime; |
| 1658 | } else { |
| 1659 | kwlStats.mCount = count; |
| 1660 | kwlStats.mTotalTime = totalTime; |
| 1661 | kwlStats.mVersion = sKernelWakelockUpdateVersion; |
| 1662 | numUpdatedWlNames++; |
| 1663 | } |
| 1664 | } |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1665 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1666 | startIndex = endIndex; |
| 1667 | } |
| 1668 | |
| 1669 | if (m.size() != numUpdatedWlNames) { |
| 1670 | // Don't report old data. |
| 1671 | Iterator<KernelWakelockStats> itr = m.values().iterator(); |
| 1672 | while (itr.hasNext()) { |
| 1673 | if (itr.next().mVersion != sKernelWakelockUpdateVersion) { |
| 1674 | itr.remove(); |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | return m; |
| 1679 | } |
| 1680 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1681 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1682 | private class KernelWakelockStats { |
| 1683 | public int mCount; |
| 1684 | public long mTotalTime; |
| 1685 | public int mVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1686 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1687 | KernelWakelockStats(int count, long totalTime, int version) { |
| 1688 | mCount = count; |
| 1689 | mTotalTime = totalTime; |
| 1690 | mVersion = version; |
| 1691 | } |
| 1692 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1693 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1694 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1695 | * 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] | 1696 | * doesn't already exist. |
| 1697 | */ |
| 1698 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1699 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1700 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1701 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1702 | mKernelWakelockStats.put(name, kwlt); |
| 1703 | } |
| 1704 | return kwlt; |
| 1705 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1706 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1707 | private int getCurrentBluetoothPingCount() { |
| 1708 | if (mBtHeadset != null) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1709 | List<BluetoothDevice> deviceList = mBtHeadset.getConnectedDevices(); |
| 1710 | if (deviceList.size() > 0) { |
| 1711 | return mBtHeadset.getBatteryUsageHint(deviceList.get(0)); |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 1712 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1713 | } |
| 1714 | return -1; |
| 1715 | } |
| 1716 | |
| 1717 | public int getBluetoothPingCount() { |
| 1718 | if (mBluetoothPingStart == -1) { |
| 1719 | return mBluetoothPingCount; |
| 1720 | } else if (mBtHeadset != null) { |
| 1721 | return getCurrentBluetoothPingCount() - mBluetoothPingStart; |
| 1722 | } |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1723 | return 0; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | public void setBtHeadset(BluetoothHeadset headset) { |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1727 | if (headset != null && mBtHeadset == null && isOnBattery() && mBluetoothPingStart == -1) { |
| 1728 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 1729 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1730 | mBtHeadset = headset; |
| 1731 | } |
| 1732 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1733 | private int writeHistoryTag(HistoryTag tag) { |
| 1734 | Integer idxObj = mHistoryTagPool.get(tag); |
| 1735 | int idx; |
| 1736 | if (idxObj != null) { |
| 1737 | idx = idxObj; |
| 1738 | } else { |
| 1739 | idx = mNextHistoryTagIdx; |
| 1740 | HistoryTag key = new HistoryTag(); |
| 1741 | key.setTo(tag); |
| 1742 | tag.poolIdx = idx; |
| 1743 | mHistoryTagPool.put(key, idx); |
| 1744 | mNextHistoryTagIdx++; |
| 1745 | mNumHistoryTagChars += key.string.length() + 1; |
| 1746 | } |
| 1747 | return idx; |
| 1748 | } |
| 1749 | |
| 1750 | private void readHistoryTag(int index, HistoryTag tag) { |
| 1751 | tag.string = mReadHistoryStrings[index]; |
| 1752 | tag.uid = mReadHistoryUids[index]; |
| 1753 | tag.poolIdx = index; |
| 1754 | } |
| 1755 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1756 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1757 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 1758 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 1759 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 1760 | 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] | 1761 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1762 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1763 | // 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] | 1764 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 1765 | // Flag in delta int: a new full state2 int follows. |
| 1766 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1767 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1768 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1769 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1770 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1771 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1772 | static final int DELTA_STATE_MASK = 0xff000000; |
| 1773 | |
| 1774 | // These are the pieces of battery state that are packed in to the upper bits of |
| 1775 | // the state int that have been packed in to the first delta int. They must fit |
| 1776 | // in DELTA_STATE_MASK. |
| 1777 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 1778 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 1779 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 1780 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 1781 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 1782 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1783 | |
| 1784 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1785 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1786 | dest.writeInt(DELTA_TIME_ABS); |
| 1787 | cur.writeToParcel(dest, 0); |
| 1788 | return; |
| 1789 | } |
| 1790 | |
| 1791 | final long deltaTime = cur.time - last.time; |
| 1792 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 1793 | final int lastStateInt = buildStateInt(last); |
| 1794 | |
| 1795 | int deltaTimeToken; |
| 1796 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 1797 | deltaTimeToken = DELTA_TIME_LONG; |
| 1798 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 1799 | deltaTimeToken = DELTA_TIME_INT; |
| 1800 | } else { |
| 1801 | deltaTimeToken = (int)deltaTime; |
| 1802 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1803 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1804 | final int batteryLevelInt = buildBatteryLevelInt(cur); |
| 1805 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 1806 | if (batteryLevelIntChanged) { |
| 1807 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 1808 | } |
| 1809 | final int stateInt = buildStateInt(cur); |
| 1810 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 1811 | if (stateIntChanged) { |
| 1812 | firstToken |= DELTA_STATE_FLAG; |
| 1813 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1814 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 1815 | if (state2IntChanged) { |
| 1816 | firstToken |= DELTA_STATE2_FLAG; |
| 1817 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1818 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1819 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 1820 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1821 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 1822 | firstToken |= DELTA_EVENT_FLAG; |
| 1823 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1824 | dest.writeInt(firstToken); |
| 1825 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1826 | + " deltaTime=" + deltaTime); |
| 1827 | |
| 1828 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 1829 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 1830 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 1831 | dest.writeInt((int)deltaTime); |
| 1832 | } else { |
| 1833 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 1834 | dest.writeLong(deltaTime); |
| 1835 | } |
| 1836 | } |
| 1837 | if (batteryLevelIntChanged) { |
| 1838 | dest.writeInt(batteryLevelInt); |
| 1839 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 1840 | + Integer.toHexString(batteryLevelInt) |
| 1841 | + " batteryLevel=" + cur.batteryLevel |
| 1842 | + " batteryTemp=" + cur.batteryTemperature |
| 1843 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1844 | } |
| 1845 | if (stateIntChanged) { |
| 1846 | dest.writeInt(stateInt); |
| 1847 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 1848 | + Integer.toHexString(stateInt) |
| 1849 | + " batteryStatus=" + cur.batteryStatus |
| 1850 | + " batteryHealth=" + cur.batteryHealth |
| 1851 | + " batteryPlugType=" + cur.batteryPlugType |
| 1852 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1853 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1854 | if (state2IntChanged) { |
| 1855 | dest.writeInt(cur.states2); |
| 1856 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 1857 | + Integer.toHexString(cur.states2)); |
| 1858 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1859 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 1860 | int wakeLockIndex; |
| 1861 | int wakeReasonIndex; |
| 1862 | if (cur.wakelockTag != null) { |
| 1863 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 1864 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1865 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1866 | } else { |
| 1867 | wakeLockIndex = 0xffff; |
| 1868 | } |
| 1869 | if (cur.wakeReasonTag != null) { |
| 1870 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 1871 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1872 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1873 | } else { |
| 1874 | wakeReasonIndex = 0xffff; |
| 1875 | } |
| 1876 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1877 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1878 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1879 | int index = writeHistoryTag(cur.eventTag); |
| 1880 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1881 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1882 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 1883 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 1884 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | private int buildBatteryLevelInt(HistoryItem h) { |
| 1889 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
| 1890 | | ((((int)h.batteryTemperature)<<14)&0x01ffc000) |
| 1891 | | (((int)h.batteryVoltage)&0x00003fff); |
| 1892 | } |
| 1893 | |
| 1894 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1895 | int plugType = 0; |
| 1896 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 1897 | plugType = 1; |
| 1898 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 1899 | plugType = 2; |
| 1900 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 1901 | plugType = 3; |
| 1902 | } |
| 1903 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 1904 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 1905 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1906 | | (h.states&(~DELTA_STATE_MASK)); |
| 1907 | } |
| 1908 | |
| 1909 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 1910 | int firstToken = src.readInt(); |
| 1911 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1912 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1913 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1914 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1915 | + " deltaTimeToken=" + deltaTimeToken); |
| 1916 | |
| 1917 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 1918 | cur.time += deltaTimeToken; |
| 1919 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 1920 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1921 | cur.numReadInts += 2; |
| 1922 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1923 | cur.readFromParcel(src); |
| 1924 | return; |
| 1925 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 1926 | int delta = src.readInt(); |
| 1927 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1928 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1929 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 1930 | } else { |
| 1931 | long delta = src.readLong(); |
| 1932 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 1933 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1934 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
| 1938 | int batteryLevelInt = src.readInt(); |
| 1939 | cur.batteryLevel = (byte)((batteryLevelInt>>25)&0x7f); |
| 1940 | cur.batteryTemperature = (short)((batteryLevelInt<<7)>>21); |
| 1941 | cur.batteryVoltage = (char)(batteryLevelInt&0x3fff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1942 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1943 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 1944 | + Integer.toHexString(batteryLevelInt) |
| 1945 | + " batteryLevel=" + cur.batteryLevel |
| 1946 | + " batteryTemp=" + cur.batteryTemperature |
| 1947 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1948 | } |
| 1949 | |
| 1950 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 1951 | int stateInt = src.readInt(); |
| 1952 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1953 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 1954 | & STATE_BATTERY_STATUS_MASK); |
| 1955 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 1956 | & STATE_BATTERY_HEALTH_MASK); |
| 1957 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 1958 | & STATE_BATTERY_PLUG_MASK); |
| 1959 | switch (cur.batteryPlugType) { |
| 1960 | case 1: |
| 1961 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 1962 | break; |
| 1963 | case 2: |
| 1964 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 1965 | break; |
| 1966 | case 3: |
| 1967 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 1968 | break; |
| 1969 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1970 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1971 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 1972 | + Integer.toHexString(stateInt) |
| 1973 | + " batteryStatus=" + cur.batteryStatus |
| 1974 | + " batteryHealth=" + cur.batteryHealth |
| 1975 | + " batteryPlugType=" + cur.batteryPlugType |
| 1976 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1977 | } else { |
| 1978 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 1979 | } |
| 1980 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1981 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 1982 | cur.states2 = src.readInt(); |
| 1983 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 1984 | + Integer.toHexString(cur.states2)); |
| 1985 | } |
| 1986 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1987 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1988 | int indexes = src.readInt(); |
| 1989 | int wakeLockIndex = indexes&0xffff; |
| 1990 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 1991 | if (wakeLockIndex != 0xffff) { |
| 1992 | cur.wakelockTag = cur.localWakelockTag; |
| 1993 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 1994 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1995 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1996 | } else { |
| 1997 | cur.wakelockTag = null; |
| 1998 | } |
| 1999 | if (wakeReasonIndex != 0xffff) { |
| 2000 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2001 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2002 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2003 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2004 | } else { |
| 2005 | cur.wakeReasonTag = null; |
| 2006 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2007 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2008 | } else { |
| 2009 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2010 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2011 | } |
| 2012 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2013 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2014 | cur.eventTag = cur.localEventTag; |
| 2015 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2016 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2017 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2018 | readHistoryTag(index, cur.eventTag); |
| 2019 | cur.numReadInts += 1; |
| 2020 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2021 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2022 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2023 | } else { |
| 2024 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2025 | } |
| 2026 | } |
| 2027 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2028 | @Override |
| 2029 | public void commitCurrentHistoryBatchLocked() { |
| 2030 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2031 | } |
| 2032 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2033 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2034 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2035 | return; |
| 2036 | } |
| 2037 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2038 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2039 | final int diffStates = mHistoryLastWritten.states^cur.states; |
| 2040 | final int diffStates2 = mHistoryLastWritten.states2^cur.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2041 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2042 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2043 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2044 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2045 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2046 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2047 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2048 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2049 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2050 | && (diffStates2&lastDiffStates2) == 0 |
| 2051 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2052 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2053 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2054 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2055 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2056 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2057 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2058 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2059 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2060 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2061 | // 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] | 2062 | // 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] | 2063 | // as long as no bit has changed both between now and the last entry, as |
| 2064 | // well as the last entry and the one before it (so we capture any toggles). |
| 2065 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2066 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2067 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2068 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2069 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2070 | // If the last written history had a wakelock tag, we need to retain it. |
| 2071 | // Note that the condition above made sure that we aren't in a case where |
| 2072 | // both it and the current history item have a wakelock tag. |
| 2073 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2074 | cur.wakelockTag = cur.localWakelockTag; |
| 2075 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2076 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2077 | // If the last written history had a wake reason tag, we need to retain it. |
| 2078 | // Note that the condition above made sure that we aren't in a case where |
| 2079 | // both it and the current history item have a wakelock tag. |
| 2080 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2081 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2082 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2083 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2084 | // If the last written history had an event, we need to retain it. |
| 2085 | // Note that the condition above made sure that we aren't in a case where |
| 2086 | // both it and the current history item have an event. |
| 2087 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2088 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2089 | cur.eventTag = cur.localEventTag; |
| 2090 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2091 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2092 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2096 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2097 | if (!mHistoryOverflow) { |
| 2098 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2099 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2100 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2101 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | // Once we've reached the maximum number of items, we only |
| 2105 | // record changes to the battery level and the most interesting states. |
| 2106 | // Once we've reached the maximum maximum number of items, we only |
| 2107 | // record changes to the battery level. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2108 | if (mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2109 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2110 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2111 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2112 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2113 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2114 | return; |
| 2115 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2116 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2117 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2118 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2121 | if (dataSize == 0) { |
| 2122 | // The history is currently empty; we need it to start with a time stamp. |
| 2123 | cur.currentTime = System.currentTimeMillis(); |
| 2124 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2125 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2126 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2129 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2130 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2131 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2132 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2133 | } |
| 2134 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2135 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2136 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2137 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2138 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2139 | cur.wakelockTag = null; |
| 2140 | cur.wakeReasonTag = null; |
| 2141 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2142 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2143 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2144 | + " now " + mHistoryBuffer.dataPosition() |
| 2145 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2148 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2149 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2150 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2151 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2152 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2153 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2154 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2155 | if (diffUptime < (diffElapsed-20)) { |
| 2156 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2157 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2158 | mHistoryAddTmp.wakelockTag = null; |
| 2159 | mHistoryAddTmp.wakeReasonTag = null; |
| 2160 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2161 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2162 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2163 | } |
| 2164 | } |
| 2165 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2166 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2167 | mTrackRunningHistoryUptime = uptimeMs; |
| 2168 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2169 | } |
| 2170 | |
| 2171 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2172 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2173 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2174 | if (!USE_OLD_HISTORY) { |
| 2175 | return; |
| 2176 | } |
| 2177 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2178 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2179 | return; |
| 2180 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2181 | |
| 2182 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2183 | // and no states have since the last recorded entry changed and |
| 2184 | // are now resetting back to their original value, then just collapse |
| 2185 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2186 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2187 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2188 | && ((mHistoryEnd.states^cur.states)&mChangedStates) == 0 |
| 2189 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2190 | // If the current is the same as the one before, then we no |
| 2191 | // longer need the entry. |
| 2192 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2193 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2194 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2195 | mHistoryLastEnd.next = null; |
| 2196 | mHistoryEnd.next = mHistoryCache; |
| 2197 | mHistoryCache = mHistoryEnd; |
| 2198 | mHistoryEnd = mHistoryLastEnd; |
| 2199 | mHistoryLastEnd = null; |
| 2200 | } else { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2201 | mChangedStates |= mHistoryEnd.states^cur.states; |
| 2202 | mChangedStates2 |= mHistoryEnd.states^cur.states2; |
| 2203 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2204 | } |
| 2205 | return; |
| 2206 | } |
| 2207 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2208 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2209 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2210 | |
| 2211 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2212 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2213 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2216 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2217 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2218 | // record changes to the battery level and the most interesting states. |
| 2219 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2220 | // record changes to the battery level. |
| 2221 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2222 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2223 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2224 | || ((mHistoryEnd.states^cur.states) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2225 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2226 | return; |
| 2227 | } |
| 2228 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2229 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2230 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2231 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2232 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2233 | void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
| 2234 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2235 | mHistoryCur.eventCode = code; |
| 2236 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2237 | mHistoryCur.eventTag.string = name; |
| 2238 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2239 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2240 | } |
| 2241 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2242 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2243 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2244 | if (rec != null) { |
| 2245 | mHistoryCache = rec.next; |
| 2246 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2247 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2248 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2249 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2250 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2251 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2252 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2253 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2254 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2255 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2256 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2257 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2258 | if (mHistoryEnd != null) { |
| 2259 | mHistoryEnd.next = rec; |
| 2260 | mHistoryEnd = rec; |
| 2261 | } else { |
| 2262 | mHistory = mHistoryEnd = rec; |
| 2263 | } |
| 2264 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2265 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2266 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2267 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2268 | if (USE_OLD_HISTORY) { |
| 2269 | if (mHistory != null) { |
| 2270 | mHistoryEnd.next = mHistoryCache; |
| 2271 | mHistoryCache = mHistory; |
| 2272 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2273 | } |
| 2274 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2275 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2276 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2277 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2278 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2279 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2280 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2281 | |
| 2282 | mHistoryBuffer.setDataSize(0); |
| 2283 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2284 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2285 | mHistoryLastLastWritten.clear(); |
| 2286 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2287 | mHistoryTagPool.clear(); |
| 2288 | mNextHistoryTagIdx = 0; |
| 2289 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2290 | mHistoryBufferLastPos = -1; |
| 2291 | mHistoryOverflow = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2292 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2293 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2294 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2295 | long realtime) { |
| 2296 | if (mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime)) { |
| 2297 | if (unplugged) { |
| 2298 | // Track bt headset ping count |
| 2299 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 2300 | mBluetoothPingCount = 0; |
| 2301 | } else { |
| 2302 | // Track bt headset ping count |
| 2303 | mBluetoothPingCount = getBluetoothPingCount(); |
| 2304 | mBluetoothPingStart = -1; |
| 2305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2306 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2307 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2308 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2309 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2310 | updateKernelWakelocksLocked(); |
| 2311 | requestWakelockCpuUpdate(); |
| 2312 | if (!unpluggedScreenOff) { |
| 2313 | // We are switching to no longer tracking wake locks, but we want |
| 2314 | // the next CPU update we receive to take them in to account. |
| 2315 | mDistributeWakelockCpu = true; |
| 2316 | } |
| 2317 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | } |
| 2319 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2320 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2321 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2322 | mIsolatedUids.put(isolatedUid, appUid); |
| 2323 | } |
| 2324 | |
| 2325 | public void removeIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2326 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2327 | if (curUid == appUid) { |
| 2328 | mIsolatedUids.delete(isolatedUid); |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | public int mapUid(int uid) { |
| 2333 | int isolated = mIsolatedUids.get(uid, -1); |
| 2334 | return isolated > 0 ? isolated : uid; |
| 2335 | } |
| 2336 | |
| 2337 | public void noteEventLocked(int code, String name, int uid) { |
| 2338 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2339 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2340 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2341 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2342 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2343 | final long uptime = SystemClock.uptimeMillis(); |
| 2344 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2345 | } |
| 2346 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2347 | public void noteProcessStartLocked(String name, int uid) { |
| 2348 | uid = mapUid(uid); |
| 2349 | if (isOnBattery()) { |
| 2350 | Uid u = getUidStatsLocked(uid); |
| 2351 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2352 | } |
| 2353 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2354 | return; |
| 2355 | } |
| 2356 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2357 | final long uptime = SystemClock.uptimeMillis(); |
| 2358 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2359 | } |
| 2360 | |
| 2361 | public void noteProcessStateLocked(String name, int uid, int state) { |
| 2362 | uid = mapUid(uid); |
| 2363 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2364 | getUidStatsLocked(uid).updateProcessStateLocked(name, state, elapsedRealtime); |
| 2365 | } |
| 2366 | |
| 2367 | public void noteProcessFinishLocked(String name, int uid) { |
| 2368 | uid = mapUid(uid); |
| 2369 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2370 | return; |
| 2371 | } |
| 2372 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2373 | final long uptime = SystemClock.uptimeMillis(); |
| 2374 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
| 2375 | getUidStatsLocked(uid).updateProcessStateLocked(name, Uid.PROCESS_STATE_NONE, |
| 2376 | elapsedRealtime); |
| 2377 | } |
| 2378 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2379 | public void noteSyncStartLocked(String name, int uid) { |
| 2380 | uid = mapUid(uid); |
| 2381 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2382 | final long uptime = SystemClock.uptimeMillis(); |
| 2383 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2384 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2385 | return; |
| 2386 | } |
| 2387 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2388 | } |
| 2389 | |
| 2390 | public void noteSyncFinishLocked(String name, int uid) { |
| 2391 | uid = mapUid(uid); |
| 2392 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2393 | final long uptime = SystemClock.uptimeMillis(); |
| 2394 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2395 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2396 | return; |
| 2397 | } |
| 2398 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2399 | } |
| 2400 | |
| 2401 | public void noteJobStartLocked(String name, int uid) { |
| 2402 | uid = mapUid(uid); |
| 2403 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2404 | final long uptime = SystemClock.uptimeMillis(); |
| 2405 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2406 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2407 | return; |
| 2408 | } |
| 2409 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2410 | } |
| 2411 | |
| 2412 | public void noteJobFinishLocked(String name, int uid) { |
| 2413 | uid = mapUid(uid); |
| 2414 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2415 | final long uptime = SystemClock.uptimeMillis(); |
| 2416 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2417 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2418 | return; |
| 2419 | } |
| 2420 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2421 | } |
| 2422 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2423 | private void requestWakelockCpuUpdate() { |
| 2424 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2425 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2426 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2427 | } |
| 2428 | } |
| 2429 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2430 | public void setRecordAllWakeLocksLocked(boolean enabled) { |
| 2431 | mRecordAllWakeLocks = enabled; |
| 2432 | if (!enabled) { |
| 2433 | // Clear out any existing state. |
| 2434 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
| 2435 | } |
| 2436 | } |
| 2437 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2438 | public void setNoAutoReset(boolean enabled) { |
| 2439 | mNoAutoReset = enabled; |
| 2440 | } |
| 2441 | |
| 2442 | private String mInitialAcquireWakeName; |
| 2443 | private int mInitialAcquireWakeUid = -1; |
| 2444 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2445 | 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] | 2446 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2447 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2448 | if (type == WAKE_TYPE_PARTIAL) { |
| 2449 | // Only care about partial wake locks, since full wake locks |
| 2450 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2451 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2452 | if (historyName == null) { |
| 2453 | historyName = name; |
| 2454 | } |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2455 | if (mRecordAllWakeLocks) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2456 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 2457 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2458 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2459 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2460 | } |
| 2461 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2462 | if (mWakeLockNesting == 0) { |
| 2463 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2464 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 2465 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2466 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2467 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2468 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2469 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2470 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2471 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 2472 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2473 | if (mHistoryLastWritten.wakelockTag != null) { |
| 2474 | // We'll try to update the last tag. |
| 2475 | mHistoryLastWritten.wakelockTag = null; |
| 2476 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2477 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2478 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2479 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2480 | } |
| 2481 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2482 | } |
| 2483 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2484 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2485 | if (uid >= 0) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2486 | //if (uid == 0) { |
| 2487 | // Slog.wtf(TAG, "Acquiring wake lock from root: " + name); |
| 2488 | //} |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2489 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2490 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2491 | } |
| 2492 | } |
| 2493 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2494 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 2495 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2496 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2497 | if (type == WAKE_TYPE_PARTIAL) { |
| 2498 | mWakeLockNesting--; |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2499 | if (mRecordAllWakeLocks) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2500 | if (historyName == null) { |
| 2501 | historyName = name; |
| 2502 | } |
| 2503 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 2504 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2505 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2506 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2507 | } |
| 2508 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2509 | if (mWakeLockNesting == 0) { |
| 2510 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2511 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 2512 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2513 | mInitialAcquireWakeName = null; |
| 2514 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2515 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2516 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2517 | } |
| 2518 | if (uid >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2519 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2520 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2524 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2525 | String historyName, int type, boolean unimportantForLogging) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2526 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2527 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2528 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2529 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2530 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2531 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2535 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 2536 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2537 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
| 2538 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2539 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2540 | // For correct semantics, we start the need worksources first, so that we won't |
| 2541 | // make inappropriate history items as if all wake locks went away and new ones |
| 2542 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2543 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2544 | for (int i=0; i<NN; i++) { |
| 2545 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2546 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2547 | } |
| 2548 | final int NO = ws.size(); |
| 2549 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2550 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2554 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2555 | String historyName, int type) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2556 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2557 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2558 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2559 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2560 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2564 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 2565 | if (mLastWakeupReason != null) { |
| 2566 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
| 2567 | LongSamplingCounter timer = getWakeupReasonCounterLocked(mLastWakeupReason); |
| 2568 | timer.addCountLocked(deltaUptime); |
| 2569 | mLastWakeupReason = null; |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | public void noteWakeupReasonLocked(String reason) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2574 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2575 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2576 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2577 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2578 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2579 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 2580 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2581 | mHistoryCur.wakeReasonTag.uid = 0; |
| 2582 | mLastWakeupReason = reason; |
| 2583 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2584 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2585 | } |
| 2586 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2587 | public int startAddingCpuLocked() { |
| 2588 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2589 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2590 | final int N = mPartialTimers.size(); |
| 2591 | if (N == 0) { |
| 2592 | mLastPartialTimers.clear(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2593 | mDistributeWakelockCpu = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2594 | return 0; |
| 2595 | } |
| 2596 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2597 | if (!mOnBatteryScreenOffTimeBase.isRunning() && !mDistributeWakelockCpu) { |
| 2598 | return 0; |
| 2599 | } |
| 2600 | |
| 2601 | mDistributeWakelockCpu = false; |
| 2602 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2603 | // How many timers should consume CPU? Only want to include ones |
| 2604 | // that have already been in the list. |
| 2605 | for (int i=0; i<N; i++) { |
| 2606 | StopwatchTimer st = mPartialTimers.get(i); |
| 2607 | if (st.mInList) { |
| 2608 | Uid uid = st.mUid; |
| 2609 | // We don't include the system UID, because it so often |
| 2610 | // holds wake locks at one request or another of an app. |
| 2611 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2612 | return 50; |
| 2613 | } |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | return 0; |
| 2618 | } |
| 2619 | |
| 2620 | public void finishAddingCpuLocked(int perc, int utime, int stime, long[] cpuSpeedTimes) { |
| 2621 | final int N = mPartialTimers.size(); |
| 2622 | if (perc != 0) { |
| 2623 | int num = 0; |
| 2624 | for (int i=0; i<N; i++) { |
| 2625 | StopwatchTimer st = mPartialTimers.get(i); |
| 2626 | if (st.mInList) { |
| 2627 | Uid uid = st.mUid; |
| 2628 | // We don't include the system UID, because it so often |
| 2629 | // holds wake locks at one request or another of an app. |
| 2630 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2631 | num++; |
| 2632 | } |
| 2633 | } |
| 2634 | } |
| 2635 | if (num != 0) { |
| 2636 | for (int i=0; i<N; i++) { |
| 2637 | StopwatchTimer st = mPartialTimers.get(i); |
| 2638 | if (st.mInList) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2639 | Uid uid = st.mUid; |
| 2640 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
Dianne Hackborn | 618b8c1 | 2010-09-09 23:10:38 -0700 | [diff] [blame] | 2641 | int myUTime = utime/num; |
| 2642 | int mySTime = stime/num; |
| 2643 | utime -= myUTime; |
| 2644 | stime -= mySTime; |
| 2645 | num--; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2646 | Uid.Proc proc = uid.getProcessStatsLocked("*wakelock*"); |
| 2647 | proc.addCpuTimeLocked(myUTime, mySTime); |
| 2648 | proc.addSpeedStepTimes(cpuSpeedTimes); |
| 2649 | } |
| 2650 | } |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | // Just in case, collect any lost CPU time. |
| 2655 | if (utime != 0 || stime != 0) { |
| 2656 | Uid uid = getUidStatsLocked(Process.SYSTEM_UID); |
| 2657 | if (uid != null) { |
| 2658 | Uid.Proc proc = uid.getProcessStatsLocked("*lost*"); |
| 2659 | proc.addCpuTimeLocked(utime, stime); |
| 2660 | proc.addSpeedStepTimes(cpuSpeedTimes); |
| 2661 | } |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | final int NL = mLastPartialTimers.size(); |
| 2666 | boolean diff = N != NL; |
| 2667 | for (int i=0; i<NL && !diff; i++) { |
| 2668 | diff |= mPartialTimers.get(i) != mLastPartialTimers.get(i); |
| 2669 | } |
| 2670 | if (!diff) { |
| 2671 | for (int i=0; i<NL; i++) { |
| 2672 | mPartialTimers.get(i).mInList = true; |
| 2673 | } |
| 2674 | return; |
| 2675 | } |
| 2676 | |
| 2677 | for (int i=0; i<NL; i++) { |
| 2678 | mLastPartialTimers.get(i).mInList = false; |
| 2679 | } |
| 2680 | mLastPartialTimers.clear(); |
| 2681 | for (int i=0; i<N; i++) { |
| 2682 | StopwatchTimer st = mPartialTimers.get(i); |
| 2683 | st.mInList = true; |
| 2684 | mLastPartialTimers.add(st); |
| 2685 | } |
| 2686 | } |
| 2687 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2688 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2689 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2690 | Uid u = mUidStats.get(uid); |
| 2691 | if (u != null) { |
| 2692 | u.mPids.remove(pid); |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2697 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2698 | Uid u = mUidStats.get(uid); |
| 2699 | if (u != null) { |
| 2700 | Uid.Pid p = u.mPids.get(pid); |
| 2701 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2702 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | return 0; |
| 2706 | } |
| 2707 | |
| 2708 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2709 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2710 | Uid u = mUidStats.get(uid); |
| 2711 | if (u != null) { |
| 2712 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 2713 | } |
| 2714 | } |
| 2715 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2716 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2717 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2718 | Uid u = mUidStats.get(uid); |
| 2719 | if (u != null) { |
| 2720 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 2721 | } |
| 2722 | } |
| 2723 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2724 | int mSensorNesting; |
| 2725 | |
| 2726 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2727 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2728 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2729 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2730 | if (mSensorNesting == 0) { |
| 2731 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2732 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 2733 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2734 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2735 | } |
| 2736 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2737 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2741 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2742 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2743 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2744 | mSensorNesting--; |
| 2745 | if (mSensorNesting == 0) { |
| 2746 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2747 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 2748 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2749 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2750 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2751 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2754 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2755 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2756 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2757 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2758 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2759 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2760 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2761 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2762 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 2763 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2764 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2765 | } |
| 2766 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2767 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2769 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2770 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2771 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2772 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2773 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2774 | mGpsNesting--; |
| 2775 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2776 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2777 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 2778 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2779 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2780 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2781 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2783 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2784 | public void noteScreenStateLocked(int state) { |
| 2785 | if (mScreenState != state) { |
| 2786 | final int oldState = mScreenState; |
| 2787 | mScreenState = state; |
| 2788 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 2789 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2790 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2791 | if (state == Display.STATE_ON) { |
| 2792 | // Screen turning on. |
| 2793 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2794 | final long uptime = SystemClock.uptimeMillis(); |
| 2795 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 2796 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 2797 | + Integer.toHexString(mHistoryCur.states)); |
| 2798 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2799 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 2800 | if (mScreenBrightnessBin >= 0) { |
| 2801 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 2802 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2803 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2804 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
| 2805 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2806 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2807 | // Fake a wake lock, so we consider the device waked as long |
| 2808 | // as the screen is on. |
| 2809 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 2810 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2811 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2812 | // Update discharge amounts. |
| 2813 | if (mOnBatteryInternal) { |
| 2814 | updateDischargeScreenLevelsLocked(false, true); |
| 2815 | } |
| 2816 | } else if (oldState == Display.STATE_ON) { |
| 2817 | // Screen turning off or dozing. |
| 2818 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2819 | final long uptime = SystemClock.uptimeMillis(); |
| 2820 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 2821 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 2822 | + Integer.toHexString(mHistoryCur.states)); |
| 2823 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2824 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 2825 | if (mScreenBrightnessBin >= 0) { |
| 2826 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 2827 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2828 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2829 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2830 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2831 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2832 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
| 2833 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2834 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2835 | // Update discharge amounts. |
| 2836 | if (mOnBatteryInternal) { |
| 2837 | updateDischargeScreenLevelsLocked(true, false); |
| 2838 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2839 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2840 | } |
| 2841 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2842 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2843 | public void noteScreenBrightnessLocked(int brightness) { |
| 2844 | // Bin the brightness. |
| 2845 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 2846 | if (bin < 0) bin = 0; |
| 2847 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 2848 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2849 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2850 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2851 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 2852 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2853 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 2854 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2855 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2856 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2857 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2858 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2859 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2860 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2861 | } |
| 2862 | mScreenBrightnessBin = bin; |
| 2863 | } |
| 2864 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2865 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2866 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2867 | if (mOnBatteryInternal) { |
| 2868 | uid = mapUid(uid); |
| 2869 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 2870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2872 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2873 | public void noteInteractiveLocked(boolean interactive) { |
| 2874 | if (mInteractive != interactive) { |
| 2875 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2876 | mInteractive = interactive; |
| 2877 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 2878 | if (interactive) { |
| 2879 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 2880 | } else { |
| 2881 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 2882 | } |
| 2883 | } |
| 2884 | } |
| 2885 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2886 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
| 2887 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2888 | final long uptime = SystemClock.uptimeMillis(); |
| 2889 | if (mMobileRadioPowerState != powerState) { |
| 2890 | long realElapsedRealtimeMs; |
| 2891 | final boolean active = |
| 2892 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 2893 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 2894 | if (active) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 2895 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2896 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 2897 | } else { |
| 2898 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 2899 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2900 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 2901 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 2902 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2903 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2904 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 2905 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 2906 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2907 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2908 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 2909 | } |
| 2910 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 2911 | + Integer.toHexString(mHistoryCur.states)); |
| 2912 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2913 | mMobileRadioPowerState = powerState; |
| 2914 | if (active) { |
| 2915 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 2916 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 2917 | } else { |
| 2918 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
| 2919 | updateNetworkActivityLocked(NET_UPDATE_MOBILE, realElapsedRealtimeMs); |
| 2920 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2921 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2922 | } |
| 2923 | } |
| 2924 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2925 | public void noteLowPowerMode(boolean enabled) { |
| 2926 | if (mLowPowerModeEnabled != enabled) { |
| 2927 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2928 | final long uptime = SystemClock.uptimeMillis(); |
| 2929 | mLowPowerModeEnabled = enabled; |
| 2930 | if (enabled) { |
| 2931 | mHistoryCur.states2 |= HistoryItem.STATE2_LOW_POWER_FLAG; |
| 2932 | if (DEBUG_HISTORY) Slog.v(TAG, "Low power mode enabled to: " |
| 2933 | + Integer.toHexString(mHistoryCur.states2)); |
| 2934 | mLowPowerModeEnabledTimer.startRunningLocked(elapsedRealtime); |
| 2935 | } else { |
| 2936 | mHistoryCur.states2 &= ~HistoryItem.STATE2_LOW_POWER_FLAG; |
| 2937 | if (DEBUG_HISTORY) Slog.v(TAG, "Low power mode disabled to: " |
| 2938 | + Integer.toHexString(mHistoryCur.states2)); |
| 2939 | mLowPowerModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
| 2940 | } |
| 2941 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2942 | } |
| 2943 | } |
| 2944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | public void notePhoneOnLocked() { |
| 2946 | if (!mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2947 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2948 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2949 | mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2950 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 2951 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2952 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2954 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | } |
| 2956 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | public void notePhoneOffLocked() { |
| 2959 | if (mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2960 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2961 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2962 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2963 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 2964 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2965 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2967 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | } |
| 2969 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2970 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2971 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2972 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2973 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2974 | if (i == except) { |
| 2975 | continue; |
| 2976 | } |
| 2977 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2978 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2979 | } |
| 2980 | } |
| 2981 | } |
| 2982 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2983 | private int fixPhoneServiceState(int state, int signalBin) { |
| 2984 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 2985 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 2986 | // to infer that we are scanning from other data. |
| 2987 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2988 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2989 | state = ServiceState.STATE_IN_SERVICE; |
| 2990 | } |
| 2991 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2992 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2993 | return state; |
| 2994 | } |
| 2995 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2996 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2997 | boolean scanning = false; |
| 2998 | boolean newHistory = false; |
| 2999 | |
| 3000 | mPhoneServiceStateRaw = state; |
| 3001 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3002 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3003 | |
| 3004 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3005 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3006 | |
| 3007 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3008 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3009 | // to infer that we are scanning from other data. |
| 3010 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3011 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3012 | state = ServiceState.STATE_IN_SERVICE; |
| 3013 | } |
| 3014 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3015 | |
| 3016 | // If the phone is powered off, stop all timers. |
| 3017 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3018 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3019 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3020 | // If we are in service, make sure the correct signal string timer is running. |
| 3021 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3022 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3023 | |
| 3024 | // If we're out of service, we are in the lowest signal strength |
| 3025 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3026 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3027 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3028 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3029 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3030 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3031 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3032 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3033 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3034 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3035 | } |
| 3036 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3037 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3038 | if (!scanning) { |
| 3039 | // If we are no longer scanning, then stop the scanning timer. |
| 3040 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3041 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3042 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3043 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3044 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3045 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3049 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3050 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3051 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3052 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3053 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3054 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3055 | mPhoneServiceState = state; |
| 3056 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3057 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3058 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3059 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3060 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3061 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3062 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3063 | if (strengthBin >= 0) { |
| 3064 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3065 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3066 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3067 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3068 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3069 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3070 | + Integer.toHexString(mHistoryCur.states)); |
| 3071 | newHistory = true; |
| 3072 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3073 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3074 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3075 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3079 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | /** |
| 3084 | * Telephony stack updates the phone state. |
| 3085 | * @param state phone state from ServiceState.getState() |
| 3086 | */ |
| 3087 | public void notePhoneStateLocked(int state, int simState) { |
| 3088 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3091 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3092 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3093 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3094 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3095 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3096 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3097 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3098 | int bin = DATA_CONNECTION_NONE; |
| 3099 | if (hasData) { |
| 3100 | switch (dataType) { |
| 3101 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3102 | bin = DATA_CONNECTION_EDGE; |
| 3103 | break; |
| 3104 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3105 | bin = DATA_CONNECTION_GPRS; |
| 3106 | break; |
| 3107 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3108 | bin = DATA_CONNECTION_UMTS; |
| 3109 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3110 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3111 | bin = DATA_CONNECTION_CDMA; |
| 3112 | break; |
| 3113 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3114 | bin = DATA_CONNECTION_EVDO_0; |
| 3115 | break; |
| 3116 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3117 | bin = DATA_CONNECTION_EVDO_A; |
| 3118 | break; |
| 3119 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3120 | bin = DATA_CONNECTION_1xRTT; |
| 3121 | break; |
| 3122 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3123 | bin = DATA_CONNECTION_HSDPA; |
| 3124 | break; |
| 3125 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3126 | bin = DATA_CONNECTION_HSUPA; |
| 3127 | break; |
| 3128 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3129 | bin = DATA_CONNECTION_HSPA; |
| 3130 | break; |
| 3131 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3132 | bin = DATA_CONNECTION_IDEN; |
| 3133 | break; |
| 3134 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3135 | bin = DATA_CONNECTION_EVDO_B; |
| 3136 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3137 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3138 | bin = DATA_CONNECTION_LTE; |
| 3139 | break; |
| 3140 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3141 | bin = DATA_CONNECTION_EHRPD; |
| 3142 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3143 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3144 | bin = DATA_CONNECTION_HSPAP; |
| 3145 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3146 | default: |
| 3147 | bin = DATA_CONNECTION_OTHER; |
| 3148 | break; |
| 3149 | } |
| 3150 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3151 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3152 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3153 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3154 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3155 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3156 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3157 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3158 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3159 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3160 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3161 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3162 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3163 | } |
| 3164 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3165 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3166 | } |
| 3167 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3168 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3169 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3170 | if (!mWifiOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3171 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3172 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3173 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3174 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3175 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3176 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3177 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3178 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3179 | } |
| 3180 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3181 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3182 | public void noteWifiOffLocked() { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3183 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3184 | final long uptime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3185 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3186 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3187 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3188 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3189 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3190 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3191 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3192 | } |
| 3193 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3194 | |
| 3195 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3196 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3197 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3198 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3199 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3200 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3201 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3202 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3203 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3204 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3205 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3206 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3207 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3208 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3209 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3210 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3211 | if (mAudioOnNesting == 0) { |
| 3212 | return; |
| 3213 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3214 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3215 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3216 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3217 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3218 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3219 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3220 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3221 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3222 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3223 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3224 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3228 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3229 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3230 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3231 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3232 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3233 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3234 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3235 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3236 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3237 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3238 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3239 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3240 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3241 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3242 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3243 | if (mVideoOnNesting == 0) { |
| 3244 | return; |
| 3245 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3246 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3247 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3248 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3249 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3250 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3251 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3252 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3253 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3254 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3255 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3256 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 3259 | public void noteResetAudioLocked() { |
| 3260 | if (mAudioOnNesting > 0) { |
| 3261 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3262 | final long uptime = SystemClock.uptimeMillis(); |
| 3263 | mAudioOnNesting = 0; |
| 3264 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3265 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3266 | + Integer.toHexString(mHistoryCur.states)); |
| 3267 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3268 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3269 | for (int i=0; i<mUidStats.size(); i++) { |
| 3270 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3271 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3272 | } |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | public void noteResetVideoLocked() { |
| 3277 | if (mVideoOnNesting > 0) { |
| 3278 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3279 | final long uptime = SystemClock.uptimeMillis(); |
| 3280 | mAudioOnNesting = 0; |
| 3281 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3282 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3283 | + Integer.toHexString(mHistoryCur.states)); |
| 3284 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3285 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3286 | for (int i=0; i<mUidStats.size(); i++) { |
| 3287 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3288 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3293 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3294 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3295 | getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3299 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3300 | getUidStatsLocked(uid).noteActivityPausedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3303 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3304 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3305 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3306 | } |
| 3307 | |
| 3308 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3309 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3310 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3311 | } |
| 3312 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3313 | public void noteFlashlightOnLocked() { |
| 3314 | if (!mFlashlightOn) { |
| 3315 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3316 | final long uptime = SystemClock.uptimeMillis(); |
| 3317 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3318 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
| 3319 | + Integer.toHexString(mHistoryCur.states)); |
| 3320 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3321 | mFlashlightOn = true; |
| 3322 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | public void noteFlashlightOffLocked() { |
| 3327 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3328 | final long uptime = SystemClock.uptimeMillis(); |
| 3329 | if (mFlashlightOn) { |
| 3330 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3331 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3332 | + Integer.toHexString(mHistoryCur.states)); |
| 3333 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3334 | mFlashlightOn = false; |
| 3335 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3336 | } |
| 3337 | } |
| 3338 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3339 | public void noteWifiRunningLocked(WorkSource ws) { |
| 3340 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3341 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3342 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3343 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3344 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 3345 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3346 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3347 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3348 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3349 | int N = ws.size(); |
| 3350 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3351 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3352 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } else { |
| 3355 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3356 | } |
| 3357 | } |
| 3358 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3359 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 3360 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3361 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3362 | int N = oldWs.size(); |
| 3363 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3364 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3365 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3366 | } |
| 3367 | N = newWs.size(); |
| 3368 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3369 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3370 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3371 | } |
| 3372 | } else { |
| 3373 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 3378 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3379 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3380 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3381 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3382 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 3383 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3384 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3385 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3386 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3387 | int N = ws.size(); |
| 3388 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3389 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3390 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3391 | } |
| 3392 | } else { |
| 3393 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3394 | } |
| 3395 | } |
| 3396 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3397 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 3398 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 3399 | if (mWifiState != wifiState) { |
| 3400 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3401 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3402 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3403 | } |
| 3404 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3405 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3409 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 3410 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 3411 | if (mWifiSupplState != supplState) { |
| 3412 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3413 | final long uptime = SystemClock.uptimeMillis(); |
| 3414 | if (mWifiSupplState >= 0) { |
| 3415 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 3416 | } |
| 3417 | mWifiSupplState = supplState; |
| 3418 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 3419 | mHistoryCur.states2 = |
| 3420 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 3421 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 3422 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 3423 | + Integer.toHexString(mHistoryCur.states2)); |
| 3424 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
| 3429 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3430 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3431 | if (i == except) { |
| 3432 | continue; |
| 3433 | } |
| 3434 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 3435 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 3441 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 3442 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 3443 | if (mWifiSignalStrengthBin != strengthBin) { |
| 3444 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3445 | final long uptime = SystemClock.uptimeMillis(); |
| 3446 | if (mWifiSignalStrengthBin >= 0) { |
| 3447 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 3448 | elapsedRealtime); |
| 3449 | } |
| 3450 | if (strengthBin >= 0) { |
| 3451 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 3452 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 3453 | } |
| 3454 | mHistoryCur.states2 = |
| 3455 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 3456 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 3457 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 3458 | + Integer.toHexString(mHistoryCur.states2)); |
| 3459 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3460 | } else { |
| 3461 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 3462 | } |
| 3463 | mWifiSignalStrengthBin = strengthBin; |
| 3464 | } |
| 3465 | } |
| 3466 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3467 | public void noteBluetoothOnLocked() { |
| 3468 | if (!mBluetoothOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3469 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3470 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3471 | mHistoryCur.states |= HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3472 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth on to: " |
| 3473 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3474 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3475 | mBluetoothOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3476 | mBluetoothOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3477 | } |
| 3478 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3479 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3480 | public void noteBluetoothOffLocked() { |
| 3481 | if (mBluetoothOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3482 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3483 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3484 | mHistoryCur.states &= ~HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3485 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth off to: " |
| 3486 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3487 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3488 | mBluetoothOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3489 | mBluetoothOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3490 | } |
| 3491 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3492 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3493 | public void noteBluetoothStateLocked(int bluetoothState) { |
| 3494 | if (DEBUG) Log.i(TAG, "Bluetooth state -> " + bluetoothState); |
| 3495 | if (mBluetoothState != bluetoothState) { |
| 3496 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3497 | if (mBluetoothState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3498 | mBluetoothStateTimer[mBluetoothState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3499 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3500 | mBluetoothState = bluetoothState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3501 | mBluetoothStateTimer[bluetoothState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3505 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3506 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3507 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3508 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3509 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3510 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3511 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3512 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3513 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 3514 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3515 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3516 | } |
| 3517 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3518 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3522 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3523 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3524 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3525 | mWifiFullLockNesting--; |
| 3526 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3527 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3528 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 3529 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3530 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3531 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3532 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3535 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3536 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3537 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3538 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3539 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3540 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3541 | if (mWifiScanNesting == 0) { |
| 3542 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3543 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3544 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3545 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3546 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3547 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3548 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3551 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3552 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3553 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3554 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3555 | mWifiScanNesting--; |
| 3556 | if (mWifiScanNesting == 0) { |
| 3557 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3558 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3559 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3560 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3561 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3562 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3563 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3564 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3565 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3566 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3567 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3568 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3572 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3573 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3574 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3577 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3578 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3579 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3580 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3581 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3582 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3583 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3584 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3585 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 3586 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3587 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3588 | } |
| 3589 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3590 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3594 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3595 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3596 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3597 | mWifiMulticastNesting--; |
| 3598 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3599 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3600 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 3601 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3602 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3603 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3604 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3607 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 3608 | int N = ws.size(); |
| 3609 | for (int i=0; i<N; i++) { |
| 3610 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 3615 | int N = ws.size(); |
| 3616 | for (int i=0; i<N; i++) { |
| 3617 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 3618 | } |
| 3619 | } |
| 3620 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3621 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3622 | int N = ws.size(); |
| 3623 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3624 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3625 | } |
| 3626 | } |
| 3627 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3628 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3629 | int N = ws.size(); |
| 3630 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3631 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3635 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 3636 | int N = ws.size(); |
| 3637 | for (int i=0; i<N; i++) { |
| 3638 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 3643 | int N = ws.size(); |
| 3644 | for (int i=0; i<N; i++) { |
| 3645 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 3646 | } |
| 3647 | } |
| 3648 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3649 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 3650 | int N = ws.size(); |
| 3651 | for (int i=0; i<N; i++) { |
| 3652 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 3653 | } |
| 3654 | } |
| 3655 | |
| 3656 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 3657 | int N = ws.size(); |
| 3658 | for (int i=0; i<N; i++) { |
| 3659 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 3660 | } |
| 3661 | } |
| 3662 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3663 | private static String[] includeInStringArray(String[] array, String str) { |
| 3664 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 3665 | return array; |
| 3666 | } |
| 3667 | String[] newArray = new String[array.length+1]; |
| 3668 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 3669 | newArray[array.length] = str; |
| 3670 | return newArray; |
| 3671 | } |
| 3672 | |
| 3673 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 3674 | int index = ArrayUtils.indexOf(array, str); |
| 3675 | if (index >= 0) { |
| 3676 | String[] newArray = new String[array.length-1]; |
| 3677 | if (index > 0) { |
| 3678 | System.arraycopy(array, 0, newArray, 0, index); |
| 3679 | } |
| 3680 | if (index < array.length-1) { |
| 3681 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 3682 | } |
| 3683 | return newArray; |
| 3684 | } |
| 3685 | return array; |
| 3686 | } |
| 3687 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3688 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
| 3689 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3690 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 3691 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3692 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3693 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 3694 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3695 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3696 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3697 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 3698 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3699 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3700 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 3701 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | public void noteNetworkStatsEnabledLocked() { |
| 3706 | // During device boot, qtaguid isn't enabled until after the inital |
| 3707 | // loading of battery stats. Now that they're enabled, take our initial |
| 3708 | // snapshot for future delta calculation. |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3709 | updateNetworkActivityLocked(NET_UPDATE_ALL, SystemClock.elapsedRealtime()); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3712 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 3713 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3715 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3716 | @Override public int getScreenOnCount(int which) { |
| 3717 | return mScreenOnTimer.getCountLocked(which); |
| 3718 | } |
| 3719 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3720 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3721 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3722 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3723 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3724 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3725 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3726 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 3727 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3728 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3729 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3730 | @Override public long getLowPowerModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 3731 | return mLowPowerModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 3732 | } |
| 3733 | |
| 3734 | @Override public int getLowPowerModeEnabledCount(int which) { |
| 3735 | return mLowPowerModeEnabledTimer.getCountLocked(which); |
| 3736 | } |
| 3737 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3738 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 3739 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3741 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3742 | @Override public int getPhoneOnCount(int which) { |
| 3743 | return mPhoneOnTimer.getCountLocked(which); |
| 3744 | } |
| 3745 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3746 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3747 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3748 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3749 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3750 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3751 | |
| 3752 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3753 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3754 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3755 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 3758 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 3759 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3760 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3761 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3762 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3763 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3764 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3765 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3766 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3767 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3768 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3769 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3770 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3771 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3772 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 3773 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3774 | } |
| 3775 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3776 | @Override public int getMobileRadioActiveCount(int which) { |
| 3777 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 3778 | } |
| 3779 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3780 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 3781 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 3782 | } |
| 3783 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3784 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 3785 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 3786 | } |
| 3787 | |
| 3788 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 3789 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 3790 | } |
| 3791 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3792 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 3793 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3794 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3795 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3796 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 3797 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3800 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3801 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3802 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3803 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 3807 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 3808 | } |
| 3809 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3810 | @Override public long getWifiSupplStateTime(int state, |
| 3811 | long elapsedRealtimeUs, int which) { |
| 3812 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 3813 | elapsedRealtimeUs, which); |
| 3814 | } |
| 3815 | |
| 3816 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 3817 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 3818 | } |
| 3819 | |
| 3820 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 3821 | long elapsedRealtimeUs, int which) { |
| 3822 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 3823 | elapsedRealtimeUs, which); |
| 3824 | } |
| 3825 | |
| 3826 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 3827 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 3828 | } |
| 3829 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3830 | @Override public long getBluetoothOnTime(long elapsedRealtimeUs, int which) { |
| 3831 | return mBluetoothOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3832 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3833 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3834 | @Override public long getBluetoothStateTime(int bluetoothState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3835 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3836 | return mBluetoothStateTimer[bluetoothState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3837 | elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3840 | @Override public int getBluetoothStateCount(int bluetoothState, int which) { |
| 3841 | return mBluetoothStateTimer[bluetoothState].getCountLocked(which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3842 | } |
| 3843 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3844 | @Override public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
| 3845 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 3846 | } |
| 3847 | |
| 3848 | @Override public long getFlashlightOnCount(int which) { |
| 3849 | return mFlashlightOnTimer.getCountLocked(which); |
| 3850 | } |
| 3851 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3852 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3853 | public long getNetworkActivityBytes(int type, int which) { |
| 3854 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 3855 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 3856 | } else { |
| 3857 | return 0; |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | @Override |
| 3862 | public long getNetworkActivityPackets(int type, int which) { |
| 3863 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 3864 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3865 | } else { |
| 3866 | return 0; |
| 3867 | } |
| 3868 | } |
| 3869 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3870 | @Override public long getStartClockTime() { |
| 3871 | return mStartClockTime; |
| 3872 | } |
| 3873 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | @Override public boolean getIsOnBattery() { |
| 3875 | return mOnBattery; |
| 3876 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 3879 | return mUidStats; |
| 3880 | } |
| 3881 | |
| 3882 | /** |
| 3883 | * The statistics associated with a particular uid. |
| 3884 | */ |
| 3885 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3888 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3889 | boolean mWifiRunning; |
| 3890 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3891 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3892 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3893 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3894 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3895 | boolean mWifiScanStarted; |
| 3896 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3897 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3898 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3899 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 3900 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 3901 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3902 | boolean mWifiMulticastEnabled; |
| 3903 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3904 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3905 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3906 | StopwatchTimer mVideoTurnedOnTimer; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3907 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3908 | StopwatchTimer mForegroundActivityTimer; |
| 3909 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3910 | static final int PROCESS_STATE_NONE = NUM_PROCESS_STATE; |
| 3911 | int mProcessState = PROCESS_STATE_NONE; |
| 3912 | StopwatchTimer[] mProcessStateTimer; |
| 3913 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3914 | BatchTimer mVibratorOnTimer; |
| 3915 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3916 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3917 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3918 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 3919 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3920 | LongSamplingCounter mMobileRadioActiveTime; |
| 3921 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | /** |
| 3924 | * The statistics we have collected for this uid's wake locks. |
| 3925 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3926 | final ArrayMap<String, Wakelock> mWakelockStats = new ArrayMap<String, Wakelock>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | |
| 3928 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3929 | * The statistics we have collected for this uid's syncs. |
| 3930 | */ |
| 3931 | final ArrayMap<String, StopwatchTimer> mSyncStats = new ArrayMap<String, StopwatchTimer>(); |
| 3932 | |
| 3933 | /** |
| 3934 | * The statistics we have collected for this uid's jobs. |
| 3935 | */ |
| 3936 | final ArrayMap<String, StopwatchTimer> mJobStats = new ArrayMap<String, StopwatchTimer>(); |
| 3937 | |
| 3938 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | * The statistics we have collected for this uid's sensor activations. |
| 3940 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3941 | final SparseArray<Sensor> mSensorStats = new SparseArray<Sensor>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3942 | |
| 3943 | /** |
| 3944 | * The statistics we have collected for this uid's processes. |
| 3945 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3946 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<String, Proc>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3947 | |
| 3948 | /** |
| 3949 | * The statistics we have collected for this uid's processes. |
| 3950 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3951 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<String, Pkg>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3952 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3953 | /** |
| 3954 | * The transient wake stats we have collected for this uid's pids. |
| 3955 | */ |
| 3956 | final SparseArray<Pid> mPids = new SparseArray<Pid>(); |
| 3957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3958 | public Uid(int uid) { |
| 3959 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3960 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3961 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3962 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3963 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3964 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3965 | mWifiScanTimers, mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3966 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3967 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3968 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3969 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | @Override |
| 3973 | public Map<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
| 3974 | return mWakelockStats; |
| 3975 | } |
| 3976 | |
| 3977 | @Override |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3978 | public Map<String, ? extends BatteryStats.Timer> getSyncStats() { |
| 3979 | return mSyncStats; |
| 3980 | } |
| 3981 | |
| 3982 | @Override |
| 3983 | public Map<String, ? extends BatteryStats.Timer> getJobStats() { |
| 3984 | return mJobStats; |
| 3985 | } |
| 3986 | |
| 3987 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3988 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | return mSensorStats; |
| 3990 | } |
| 3991 | |
| 3992 | @Override |
| 3993 | public Map<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
| 3994 | return mProcessStats; |
| 3995 | } |
| 3996 | |
| 3997 | @Override |
| 3998 | public Map<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
| 3999 | return mPackageStats; |
| 4000 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4001 | |
| 4002 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | public int getUid() { |
| 4004 | return mUid; |
| 4005 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4006 | |
| 4007 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4008 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4009 | if (!mWifiRunning) { |
| 4010 | mWifiRunning = true; |
| 4011 | if (mWifiRunningTimer == null) { |
| 4012 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4013 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4014 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4015 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4016 | } |
| 4017 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4018 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4019 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4020 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4021 | if (mWifiRunning) { |
| 4022 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4023 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4024 | } |
| 4025 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4026 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4027 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4028 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4029 | if (!mFullWifiLockOut) { |
| 4030 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4031 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4032 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4033 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4034 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4035 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4036 | } |
| 4037 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4038 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4039 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4040 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4041 | if (mFullWifiLockOut) { |
| 4042 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4043 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4044 | } |
| 4045 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4046 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4047 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4048 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4049 | if (!mWifiScanStarted) { |
| 4050 | mWifiScanStarted = true; |
| 4051 | if (mWifiScanTimer == null) { |
| 4052 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4053 | mWifiScanTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4054 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4055 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4056 | } |
| 4057 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4058 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4059 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4060 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4061 | if (mWifiScanStarted) { |
| 4062 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4063 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4064 | } |
| 4065 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4066 | |
| 4067 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4068 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4069 | int bin = 0; |
| 4070 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS) { |
| 4071 | csph = csph >> 3; |
| 4072 | bin++; |
| 4073 | } |
| 4074 | |
| 4075 | if (mWifiBatchedScanBinStarted == bin) return; |
| 4076 | |
| 4077 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4078 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4079 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4080 | } |
| 4081 | mWifiBatchedScanBinStarted = bin; |
| 4082 | if (mWifiBatchedScanTimer[bin] == null) { |
| 4083 | makeWifiBatchedScanBin(bin, null); |
| 4084 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4085 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4089 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4090 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4091 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4092 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4093 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4098 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4099 | if (!mWifiMulticastEnabled) { |
| 4100 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4101 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4102 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4103 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4104 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4105 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4110 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4111 | if (mWifiMulticastEnabled) { |
| 4112 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4113 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4117 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 4118 | if (mAudioTurnedOnTimer == null) { |
| 4119 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4120 | mAudioTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4121 | } |
| 4122 | return mAudioTurnedOnTimer; |
| 4123 | } |
| 4124 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4125 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4126 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4127 | } |
| 4128 | |
| 4129 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 4130 | if (mAudioTurnedOnTimer != null) { |
| 4131 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4132 | } |
| 4133 | } |
| 4134 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4135 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 4136 | if (mAudioTurnedOnTimer != null) { |
| 4137 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4141 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 4142 | if (mVideoTurnedOnTimer == null) { |
| 4143 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4144 | mVideoTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4145 | } |
| 4146 | return mVideoTurnedOnTimer; |
| 4147 | } |
| 4148 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4149 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4150 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4151 | } |
| 4152 | |
| 4153 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 4154 | if (mVideoTurnedOnTimer != null) { |
| 4155 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4156 | } |
| 4157 | } |
| 4158 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4159 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 4160 | if (mVideoTurnedOnTimer != null) { |
| 4161 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4165 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 4166 | if (mForegroundActivityTimer == null) { |
| 4167 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4168 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4169 | } |
| 4170 | return mForegroundActivityTimer; |
| 4171 | } |
| 4172 | |
| 4173 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4174 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4175 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4176 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4180 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4181 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4182 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4183 | } |
| 4184 | } |
| 4185 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4186 | void updateUidProcessStateLocked(int state, long elapsedRealtimeMs) { |
| 4187 | if (mProcessState == state) return; |
| 4188 | |
| 4189 | if (mProcessState != PROCESS_STATE_NONE) { |
| 4190 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
| 4191 | } |
| 4192 | mProcessState = state; |
| 4193 | if (state != PROCESS_STATE_NONE) { |
| 4194 | if (mProcessStateTimer[state] == null) { |
| 4195 | makeProcessState(state, null); |
| 4196 | } |
| 4197 | mProcessStateTimer[state].startRunningLocked(elapsedRealtimeMs); |
| 4198 | } |
| 4199 | } |
| 4200 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4201 | public BatchTimer createVibratorOnTimerLocked() { |
| 4202 | if (mVibratorOnTimer == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4203 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4204 | } |
| 4205 | return mVibratorOnTimer; |
| 4206 | } |
| 4207 | |
| 4208 | public void noteVibratorOnLocked(long durationMillis) { |
| 4209 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 4210 | } |
| 4211 | |
| 4212 | public void noteVibratorOffLocked() { |
| 4213 | if (mVibratorOnTimer != null) { |
| 4214 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4215 | } |
| 4216 | } |
| 4217 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4218 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4219 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4220 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4221 | return 0; |
| 4222 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4223 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4224 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4225 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4226 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4227 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4228 | if (mFullWifiLockTimer == null) { |
| 4229 | return 0; |
| 4230 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4231 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4232 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4233 | |
| 4234 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4235 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4236 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4237 | return 0; |
| 4238 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4239 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4240 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4241 | |
| 4242 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4243 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4244 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4245 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4246 | return 0; |
| 4247 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4248 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4252 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4253 | if (mWifiMulticastTimer == null) { |
| 4254 | return 0; |
| 4255 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4256 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4259 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4260 | public long getAudioTurnedOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4261 | if (mAudioTurnedOnTimer == null) { |
| 4262 | return 0; |
| 4263 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4264 | return mAudioTurnedOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4267 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4268 | public long getVideoTurnedOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4269 | if (mVideoTurnedOnTimer == null) { |
| 4270 | return 0; |
| 4271 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4272 | return mVideoTurnedOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4273 | } |
| 4274 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4275 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4276 | public Timer getForegroundActivityTimer() { |
| 4277 | return mForegroundActivityTimer; |
| 4278 | } |
| 4279 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4280 | void makeProcessState(int i, Parcel in) { |
| 4281 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 4282 | |
| 4283 | if (in == null) { |
| 4284 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4285 | mOnBatteryTimeBase); |
| 4286 | } else { |
| 4287 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4288 | mOnBatteryTimeBase, in); |
| 4289 | } |
| 4290 | } |
| 4291 | |
| 4292 | @Override |
| 4293 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 4294 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 4295 | if (mProcessStateTimer[state] == null) { |
| 4296 | return 0; |
| 4297 | } |
| 4298 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4299 | } |
| 4300 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4301 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4302 | public Timer getVibratorOnTimer() { |
| 4303 | return mVibratorOnTimer; |
| 4304 | } |
| 4305 | |
| 4306 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4307 | public void noteUserActivityLocked(int type) { |
| 4308 | if (mUserActivityCounters == null) { |
| 4309 | initUserActivityLocked(); |
| 4310 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 4311 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 4312 | mUserActivityCounters[type].stepAtomic(); |
| 4313 | } else { |
| 4314 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 4315 | new Throwable()); |
| 4316 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4317 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4318 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4319 | @Override |
| 4320 | public boolean hasUserActivity() { |
| 4321 | return mUserActivityCounters != null; |
| 4322 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4323 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4324 | @Override |
| 4325 | public int getUserActivityCount(int type, int which) { |
| 4326 | if (mUserActivityCounters == null) { |
| 4327 | return 0; |
| 4328 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4329 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4330 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4331 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4332 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 4333 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 4334 | |
| 4335 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 4336 | if (collected == null) { |
| 4337 | collected = new ArrayList<StopwatchTimer>(); |
| 4338 | mWifiBatchedScanTimers.put(i, collected); |
| 4339 | } |
| 4340 | if (in == null) { |
| 4341 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4342 | mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4343 | } else { |
| 4344 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4345 | mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4350 | void initUserActivityLocked() { |
| 4351 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4352 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4353 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4354 | } |
| 4355 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4356 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4357 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 4358 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4359 | initNetworkActivityLocked(); |
| 4360 | } |
| 4361 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4362 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 4363 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4364 | } else { |
| 4365 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 4366 | new Throwable()); |
| 4367 | } |
| 4368 | } |
| 4369 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4370 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 4371 | if (mNetworkByteActivityCounters == null) { |
| 4372 | initNetworkActivityLocked(); |
| 4373 | } |
| 4374 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 4375 | mMobileRadioActiveCount.addCountLocked(1); |
| 4376 | } |
| 4377 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4378 | @Override |
| 4379 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4380 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4384 | public long getNetworkActivityBytes(int type, int which) { |
| 4385 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 4386 | && type < mNetworkByteActivityCounters.length) { |
| 4387 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4388 | } else { |
| 4389 | return 0; |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | @Override |
| 4394 | public long getNetworkActivityPackets(int type, int which) { |
| 4395 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 4396 | && type < mNetworkPacketActivityCounters.length) { |
| 4397 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4398 | } else { |
| 4399 | return 0; |
| 4400 | } |
| 4401 | } |
| 4402 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4403 | @Override |
| 4404 | public long getMobileRadioActiveTime(int which) { |
| 4405 | return mMobileRadioActiveTime != null |
| 4406 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 4407 | } |
| 4408 | |
| 4409 | @Override |
| 4410 | public int getMobileRadioActiveCount(int which) { |
| 4411 | return mMobileRadioActiveCount != null |
| 4412 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 4413 | } |
| 4414 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4415 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4416 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 4417 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4418 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4419 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4420 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4421 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4422 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4423 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4425 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4426 | /** |
| 4427 | * Clear all stats for this uid. Returns true if the uid is completely |
| 4428 | * inactive so can be dropped. |
| 4429 | */ |
| 4430 | boolean reset() { |
| 4431 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4432 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4433 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4434 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4435 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4436 | } |
| 4437 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4438 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4439 | active |= mFullWifiLockOut; |
| 4440 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4441 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4442 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4443 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4444 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4445 | if (mWifiBatchedScanTimer != null) { |
| 4446 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4447 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4448 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 4452 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4453 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4454 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4455 | active |= mWifiMulticastEnabled; |
| 4456 | } |
| 4457 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4458 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4459 | } |
| 4460 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4461 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4462 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4463 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4464 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4465 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4466 | if (mProcessStateTimer != null) { |
| 4467 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 4468 | if (mProcessStateTimer[i] != null) { |
| 4469 | active |= !mProcessStateTimer[i].reset(false); |
| 4470 | } |
| 4471 | } |
| 4472 | active |= (mProcessState != PROCESS_STATE_NONE); |
| 4473 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4474 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4475 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4476 | mVibratorOnTimer.detach(); |
| 4477 | mVibratorOnTimer = null; |
| 4478 | } else { |
| 4479 | active = true; |
| 4480 | } |
| 4481 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4482 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4483 | if (mUserActivityCounters != null) { |
| 4484 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 4485 | mUserActivityCounters[i].reset(false); |
| 4486 | } |
| 4487 | } |
| 4488 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4489 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4490 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4491 | mNetworkByteActivityCounters[i].reset(false); |
| 4492 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4493 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4494 | mMobileRadioActiveTime.reset(false); |
| 4495 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4498 | for (int iw=mWakelockStats.size()-1; iw>=0; iw--) { |
| 4499 | Wakelock wl = mWakelockStats.valueAt(iw); |
| 4500 | if (wl.reset()) { |
| 4501 | mWakelockStats.removeAt(iw); |
| 4502 | } else { |
| 4503 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4504 | } |
| 4505 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4506 | for (int is=mSyncStats.size()-1; is>=0; is--) { |
| 4507 | StopwatchTimer timer = mSyncStats.valueAt(is); |
| 4508 | if (timer.reset(false)) { |
| 4509 | mSyncStats.removeAt(is); |
| 4510 | timer.detach(); |
| 4511 | } else { |
| 4512 | active = true; |
| 4513 | } |
| 4514 | } |
| 4515 | for (int ij=mJobStats.size()-1; ij>=0; ij--) { |
| 4516 | StopwatchTimer timer = mJobStats.valueAt(ij); |
| 4517 | if (timer.reset(false)) { |
| 4518 | mJobStats.removeAt(ij); |
| 4519 | timer.detach(); |
| 4520 | } else { |
| 4521 | active = true; |
| 4522 | } |
| 4523 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4524 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 4525 | Sensor s = mSensorStats.valueAt(ise); |
| 4526 | if (s.reset()) { |
| 4527 | mSensorStats.removeAt(ise); |
| 4528 | } else { |
| 4529 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4530 | } |
| 4531 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4532 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 4533 | Proc proc = mProcessStats.valueAt(ip); |
| 4534 | if (proc.mProcessState == PROCESS_STATE_NONE) { |
| 4535 | proc.detach(); |
| 4536 | mProcessStats.removeAt(ip); |
| 4537 | } else { |
| 4538 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4539 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4540 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4541 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4542 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4543 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4544 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4545 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4546 | } else { |
| 4547 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4548 | } |
| 4549 | } |
| 4550 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4551 | if (mPackageStats.size() > 0) { |
| 4552 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 4553 | while (it.hasNext()) { |
| 4554 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 4555 | Pkg p = pkgEntry.getValue(); |
| 4556 | p.detach(); |
| 4557 | if (p.mServiceStats.size() > 0) { |
| 4558 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 4559 | = p.mServiceStats.entrySet().iterator(); |
| 4560 | while (it2.hasNext()) { |
| 4561 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 4562 | servEntry.getValue().detach(); |
| 4563 | } |
| 4564 | } |
| 4565 | } |
| 4566 | mPackageStats.clear(); |
| 4567 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4568 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4569 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4570 | if (mWifiRunningTimer != null) { |
| 4571 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4572 | } |
| 4573 | if (mFullWifiLockTimer != null) { |
| 4574 | mFullWifiLockTimer.detach(); |
| 4575 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4576 | if (mWifiScanTimer != null) { |
| 4577 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4578 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4579 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4580 | if (mWifiBatchedScanTimer[i] != null) { |
| 4581 | mWifiBatchedScanTimer[i].detach(); |
| 4582 | } |
| 4583 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4584 | if (mWifiMulticastTimer != null) { |
| 4585 | mWifiMulticastTimer.detach(); |
| 4586 | } |
| 4587 | if (mAudioTurnedOnTimer != null) { |
| 4588 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4589 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4590 | } |
| 4591 | if (mVideoTurnedOnTimer != null) { |
| 4592 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4593 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4594 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4595 | if (mForegroundActivityTimer != null) { |
| 4596 | mForegroundActivityTimer.detach(); |
| 4597 | mForegroundActivityTimer = null; |
| 4598 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4599 | if (mUserActivityCounters != null) { |
| 4600 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 4601 | mUserActivityCounters[i].detach(); |
| 4602 | } |
| 4603 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4604 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4605 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4606 | mNetworkByteActivityCounters[i].detach(); |
| 4607 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4608 | } |
| 4609 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4610 | mPids.clear(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4611 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4612 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4613 | return !active; |
| 4614 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4615 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4616 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4617 | int NW = mWakelockStats.size(); |
| 4618 | out.writeInt(NW); |
| 4619 | for (int iw=0; iw<NW; iw++) { |
| 4620 | out.writeString(mWakelockStats.keyAt(iw)); |
| 4621 | Uid.Wakelock wakelock = mWakelockStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4622 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4625 | int NS = mSyncStats.size(); |
| 4626 | out.writeInt(NS); |
| 4627 | for (int is=0; is<NS; is++) { |
| 4628 | out.writeString(mSyncStats.keyAt(is)); |
| 4629 | StopwatchTimer timer = mSyncStats.valueAt(is); |
| 4630 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 4631 | } |
| 4632 | |
| 4633 | int NJ = mJobStats.size(); |
| 4634 | out.writeInt(NJ); |
| 4635 | for (int ij=0; ij<NJ; ij++) { |
| 4636 | out.writeString(mJobStats.keyAt(ij)); |
| 4637 | StopwatchTimer timer = mJobStats.valueAt(ij); |
| 4638 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 4639 | } |
| 4640 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4641 | int NSE = mSensorStats.size(); |
| 4642 | out.writeInt(NSE); |
| 4643 | for (int ise=0; ise<NSE; ise++) { |
| 4644 | out.writeInt(mSensorStats.keyAt(ise)); |
| 4645 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4646 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | } |
| 4648 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4649 | int NP = mProcessStats.size(); |
| 4650 | out.writeInt(NP); |
| 4651 | for (int ip=0; ip<NP; ip++) { |
| 4652 | out.writeString(mProcessStats.keyAt(ip)); |
| 4653 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | proc.writeToParcelLocked(out); |
| 4655 | } |
| 4656 | |
| 4657 | out.writeInt(mPackageStats.size()); |
| 4658 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 4659 | out.writeString(pkgEntry.getKey()); |
| 4660 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 4661 | pkg.writeToParcelLocked(out); |
| 4662 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4663 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4664 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4665 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4666 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4667 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4668 | out.writeInt(0); |
| 4669 | } |
| 4670 | if (mFullWifiLockTimer != null) { |
| 4671 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4672 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4673 | } else { |
| 4674 | out.writeInt(0); |
| 4675 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4676 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4677 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4678 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4679 | } else { |
| 4680 | out.writeInt(0); |
| 4681 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4682 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4683 | if (mWifiBatchedScanTimer[i] != null) { |
| 4684 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4685 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4686 | } else { |
| 4687 | out.writeInt(0); |
| 4688 | } |
| 4689 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4690 | if (mWifiMulticastTimer != null) { |
| 4691 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4692 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4693 | } else { |
| 4694 | out.writeInt(0); |
| 4695 | } |
| 4696 | if (mAudioTurnedOnTimer != null) { |
| 4697 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4698 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4699 | } else { |
| 4700 | out.writeInt(0); |
| 4701 | } |
| 4702 | if (mVideoTurnedOnTimer != null) { |
| 4703 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4704 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4705 | } else { |
| 4706 | out.writeInt(0); |
| 4707 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4708 | if (mForegroundActivityTimer != null) { |
| 4709 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4710 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4711 | } else { |
| 4712 | out.writeInt(0); |
| 4713 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4714 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 4715 | if (mProcessStateTimer[i] != null) { |
| 4716 | out.writeInt(1); |
| 4717 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 4718 | } else { |
| 4719 | out.writeInt(0); |
| 4720 | } |
| 4721 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4722 | if (mVibratorOnTimer != null) { |
| 4723 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4724 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4725 | } else { |
| 4726 | out.writeInt(0); |
| 4727 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4728 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4729 | out.writeInt(1); |
| 4730 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 4731 | mUserActivityCounters[i].writeToParcel(out); |
| 4732 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4733 | } else { |
| 4734 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4735 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4736 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4737 | out.writeInt(1); |
| 4738 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4739 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 4740 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4741 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4742 | mMobileRadioActiveTime.writeToParcel(out); |
| 4743 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4744 | } else { |
| 4745 | out.writeInt(0); |
| 4746 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4747 | } |
| 4748 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4749 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | int numWakelocks = in.readInt(); |
| 4751 | mWakelockStats.clear(); |
| 4752 | for (int j = 0; j < numWakelocks; j++) { |
| 4753 | String wakelockName = in.readString(); |
| 4754 | Uid.Wakelock wakelock = new Wakelock(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4755 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 4756 | // We will just drop some random set of wakelocks if |
| 4757 | // the previous run of the system was an older version |
| 4758 | // that didn't impose a limit. |
| 4759 | mWakelockStats.put(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4760 | } |
| 4761 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4762 | int numSyncs = in.readInt(); |
| 4763 | mSyncStats.clear(); |
| 4764 | for (int j = 0; j < numSyncs; j++) { |
| 4765 | String syncName = in.readString(); |
| 4766 | if (in.readInt() != 0) { |
| 4767 | mSyncStats.put(syncName, |
| 4768 | new StopwatchTimer(Uid.this, SYNC, null, timeBase, in)); |
| 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | int numJobs = in.readInt(); |
| 4773 | mJobStats.clear(); |
| 4774 | for (int j = 0; j < numJobs; j++) { |
| 4775 | String jobName = in.readString(); |
| 4776 | if (in.readInt() != 0) { |
| 4777 | mJobStats.put(jobName, new StopwatchTimer(Uid.this, JOB, null, timeBase, in)); |
| 4778 | } |
| 4779 | } |
| 4780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4781 | int numSensors = in.readInt(); |
| 4782 | mSensorStats.clear(); |
| 4783 | for (int k = 0; k < numSensors; k++) { |
| 4784 | int sensorNumber = in.readInt(); |
| 4785 | Uid.Sensor sensor = new Sensor(sensorNumber); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4786 | sensor.readFromParcelLocked(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | mSensorStats.put(sensorNumber, sensor); |
| 4788 | } |
| 4789 | |
| 4790 | int numProcs = in.readInt(); |
| 4791 | mProcessStats.clear(); |
| 4792 | for (int k = 0; k < numProcs; k++) { |
| 4793 | String processName = in.readString(); |
| 4794 | Uid.Proc proc = new Proc(); |
| 4795 | proc.readFromParcelLocked(in); |
| 4796 | mProcessStats.put(processName, proc); |
| 4797 | } |
| 4798 | |
| 4799 | int numPkgs = in.readInt(); |
| 4800 | mPackageStats.clear(); |
| 4801 | for (int l = 0; l < numPkgs; l++) { |
| 4802 | String packageName = in.readString(); |
| 4803 | Uid.Pkg pkg = new Pkg(); |
| 4804 | pkg.readFromParcelLocked(in); |
| 4805 | mPackageStats.put(packageName, pkg); |
| 4806 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4807 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4808 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4809 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4810 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4811 | mWifiRunningTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4812 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4813 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4814 | } |
| 4815 | mFullWifiLockOut = false; |
| 4816 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4817 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4818 | mFullWifiLockTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4819 | } else { |
| 4820 | mFullWifiLockTimer = null; |
| 4821 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4822 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4823 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4824 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4825 | mWifiScanTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4826 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4827 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4828 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4829 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4830 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4831 | if (in.readInt() != 0) { |
| 4832 | makeWifiBatchedScanBin(i, in); |
| 4833 | } else { |
| 4834 | mWifiBatchedScanTimer[i] = null; |
| 4835 | } |
| 4836 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4837 | mWifiMulticastEnabled = false; |
| 4838 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4839 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4840 | mWifiMulticastTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4841 | } else { |
| 4842 | mWifiMulticastTimer = null; |
| 4843 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4844 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4845 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4846 | mAudioTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4847 | } else { |
| 4848 | mAudioTurnedOnTimer = null; |
| 4849 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4850 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4851 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 4852 | mVideoTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4853 | } else { |
| 4854 | mVideoTurnedOnTimer = null; |
| 4855 | } |
| 4856 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4857 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4858 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4859 | } else { |
| 4860 | mForegroundActivityTimer = null; |
| 4861 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4862 | mProcessState = PROCESS_STATE_NONE; |
| 4863 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 4864 | if (in.readInt() != 0) { |
| 4865 | makeProcessState(i, in); |
| 4866 | } else { |
| 4867 | mProcessStateTimer[i] = null; |
| 4868 | } |
| 4869 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4870 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4871 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4872 | } else { |
| 4873 | mVibratorOnTimer = null; |
| 4874 | } |
| 4875 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4876 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4877 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4878 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4879 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4880 | } else { |
| 4881 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4882 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4883 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4884 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 4885 | mNetworkPacketActivityCounters |
| 4886 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4887 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4888 | mNetworkByteActivityCounters[i] |
| 4889 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 4890 | mNetworkPacketActivityCounters[i] |
| 4891 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4892 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4893 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 4894 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4895 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4896 | mNetworkByteActivityCounters = null; |
| 4897 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | /** |
| 4902 | * The statistics associated with a particular wake lock. |
| 4903 | */ |
| 4904 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 4905 | /** |
| 4906 | * How long (in ms) this uid has been keeping the device partially awake. |
| 4907 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4908 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4909 | |
| 4910 | /** |
| 4911 | * How long (in ms) this uid has been keeping the device fully awake. |
| 4912 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4913 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | |
| 4915 | /** |
| 4916 | * How long (in ms) this uid has had a window keeping the device awake. |
| 4917 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4918 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | |
| 4920 | /** |
| 4921 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 4922 | * proper timer pool from the given BatteryStatsImpl object. |
| 4923 | * |
| 4924 | * @param in the Parcel to be read from. |
| 4925 | * return a new Timer, or null. |
| 4926 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4927 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4928 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | if (in.readInt() == 0) { |
| 4930 | return null; |
| 4931 | } |
| 4932 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4933 | return new StopwatchTimer(Uid.this, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4934 | } |
| 4935 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4936 | boolean reset() { |
| 4937 | boolean wlactive = false; |
| 4938 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4939 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4940 | } |
| 4941 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4942 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4943 | } |
| 4944 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4945 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4946 | } |
| 4947 | if (!wlactive) { |
| 4948 | if (mTimerFull != null) { |
| 4949 | mTimerFull.detach(); |
| 4950 | mTimerFull = null; |
| 4951 | } |
| 4952 | if (mTimerPartial != null) { |
| 4953 | mTimerPartial.detach(); |
| 4954 | mTimerPartial = null; |
| 4955 | } |
| 4956 | if (mTimerWindow != null) { |
| 4957 | mTimerWindow.detach(); |
| 4958 | mTimerWindow = null; |
| 4959 | } |
| 4960 | } |
| 4961 | return !wlactive; |
| 4962 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4963 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4964 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4966 | mPartialTimers, screenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4967 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4968 | mFullTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4970 | mWindowTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | } |
| 4972 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4973 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 4974 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 4975 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 4976 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | @Override |
| 4980 | public Timer getWakeTime(int type) { |
| 4981 | switch (type) { |
| 4982 | case WAKE_TYPE_FULL: return mTimerFull; |
| 4983 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 4984 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
| 4985 | default: throw new IllegalArgumentException("type = " + type); |
| 4986 | } |
| 4987 | } |
| 4988 | } |
| 4989 | |
| 4990 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 4991 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4992 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | public Sensor(int handle) { |
| 4995 | mHandle = handle; |
| 4996 | } |
| 4997 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4998 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4999 | if (in.readInt() == 0) { |
| 5000 | return null; |
| 5001 | } |
| 5002 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5003 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5004 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5005 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | mSensorTimers.put(mHandle, pool); |
| 5007 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5008 | return new StopwatchTimer(Uid.this, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5009 | } |
| 5010 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5011 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5012 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5013 | mTimer = null; |
| 5014 | return true; |
| 5015 | } |
| 5016 | return false; |
| 5017 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5018 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5019 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 5020 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5021 | } |
| 5022 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5023 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5024 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | @Override |
| 5028 | public Timer getSensorTime() { |
| 5029 | return mTimer; |
| 5030 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5031 | |
| 5032 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | public int getHandle() { |
| 5034 | return mHandle; |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | /** |
| 5039 | * The statistics associated with a particular process. |
| 5040 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5041 | 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] | 5042 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5043 | * Remains true until removed from the stats. |
| 5044 | */ |
| 5045 | boolean mActive = true; |
| 5046 | |
| 5047 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5048 | * Total time (in 1/100 sec) spent executing in user code. |
| 5049 | */ |
| 5050 | long mUserTime; |
| 5051 | |
| 5052 | /** |
| 5053 | * Total time (in 1/100 sec) spent executing in kernel code. |
| 5054 | */ |
| 5055 | long mSystemTime; |
| 5056 | |
| 5057 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5058 | * Amount of time the process was running in the foreground. |
| 5059 | */ |
| 5060 | long mForegroundTime; |
| 5061 | |
| 5062 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5063 | * Number of times the process has been started. |
| 5064 | */ |
| 5065 | int mStarts; |
| 5066 | |
| 5067 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5068 | * The amount of user time loaded from a previous save. |
| 5069 | */ |
| 5070 | long mLoadedUserTime; |
| 5071 | |
| 5072 | /** |
| 5073 | * The amount of system time loaded from a previous save. |
| 5074 | */ |
| 5075 | long mLoadedSystemTime; |
| 5076 | |
| 5077 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5078 | * The amount of foreground time loaded from a previous save. |
| 5079 | */ |
| 5080 | long mLoadedForegroundTime; |
| 5081 | |
| 5082 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5083 | * The number of times the process has started from a previous save. |
| 5084 | */ |
| 5085 | int mLoadedStarts; |
| 5086 | |
| 5087 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5088 | * The amount of user time loaded from the previous run. |
| 5089 | */ |
| 5090 | long mLastUserTime; |
| 5091 | |
| 5092 | /** |
| 5093 | * The amount of system time loaded from the previous run. |
| 5094 | */ |
| 5095 | long mLastSystemTime; |
| 5096 | |
| 5097 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5098 | * The amount of foreground time loaded from the previous run |
| 5099 | */ |
| 5100 | long mLastForegroundTime; |
| 5101 | |
| 5102 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5103 | * The number of times the process has started from the previous run. |
| 5104 | */ |
| 5105 | int mLastStarts; |
| 5106 | |
| 5107 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5108 | * The amount of user time when last unplugged. |
| 5109 | */ |
| 5110 | long mUnpluggedUserTime; |
| 5111 | |
| 5112 | /** |
| 5113 | * The amount of system time when last unplugged. |
| 5114 | */ |
| 5115 | long mUnpluggedSystemTime; |
| 5116 | |
| 5117 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5118 | * The amount of foreground time since unplugged. |
| 5119 | */ |
| 5120 | long mUnpluggedForegroundTime; |
| 5121 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5122 | /** |
| 5123 | * The number of times the process has started before unplugged. |
| 5124 | */ |
| 5125 | int mUnpluggedStarts; |
| 5126 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5127 | /** |
| 5128 | * Current process state. |
| 5129 | */ |
| 5130 | int mProcessState = PROCESS_STATE_NONE; |
| 5131 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5132 | SamplingCounter[] mSpeedBins; |
| 5133 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5134 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5136 | Proc() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5137 | mOnBatteryTimeBase.add(this); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5138 | mSpeedBins = new SamplingCounter[getCpuSpeedSteps()]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5139 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5140 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5141 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5142 | mUnpluggedUserTime = mUserTime; |
| 5143 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5144 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5145 | mUnpluggedStarts = mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | } |
| 5147 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5148 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5150 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5151 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5152 | mActive = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5153 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5154 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5155 | SamplingCounter c = mSpeedBins[i]; |
| 5156 | if (c != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5157 | mOnBatteryTimeBase.remove(c); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5158 | mSpeedBins[i] = null; |
| 5159 | } |
| 5160 | } |
| 5161 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5162 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5163 | public int countExcessivePowers() { |
| 5164 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5167 | public ExcessivePower getExcessivePower(int i) { |
| 5168 | if (mExcessivePower != null) { |
| 5169 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5170 | } |
| 5171 | return null; |
| 5172 | } |
| 5173 | |
| 5174 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5175 | if (mExcessivePower == null) { |
| 5176 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5177 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5178 | ExcessivePower ew = new ExcessivePower(); |
| 5179 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5180 | ew.overTime = overTime; |
| 5181 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5182 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5185 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 5186 | if (mExcessivePower == null) { |
| 5187 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 5188 | } |
| 5189 | ExcessivePower ew = new ExcessivePower(); |
| 5190 | ew.type = ExcessivePower.TYPE_CPU; |
| 5191 | ew.overTime = overTime; |
| 5192 | ew.usedTime = usedTime; |
| 5193 | mExcessivePower.add(ew); |
| 5194 | } |
| 5195 | |
| 5196 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 5197 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5198 | out.writeInt(0); |
| 5199 | return; |
| 5200 | } |
| 5201 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5202 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5203 | out.writeInt(N); |
| 5204 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5205 | ExcessivePower ew = mExcessivePower.get(i); |
| 5206 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5207 | out.writeLong(ew.overTime); |
| 5208 | out.writeLong(ew.usedTime); |
| 5209 | } |
| 5210 | } |
| 5211 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5212 | boolean readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5213 | final int N = in.readInt(); |
| 5214 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5215 | mExcessivePower = null; |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5216 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5217 | } |
| 5218 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5219 | if (N > 10000) { |
| 5220 | Slog.w(TAG, "File corrupt: too many excessive power entries " + N); |
| 5221 | return false; |
| 5222 | } |
| 5223 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5224 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5225 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5226 | ExcessivePower ew = new ExcessivePower(); |
| 5227 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5228 | ew.overTime = in.readLong(); |
| 5229 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5230 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5231 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5232 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5233 | } |
| 5234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5235 | void writeToParcelLocked(Parcel out) { |
| 5236 | out.writeLong(mUserTime); |
| 5237 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5238 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | out.writeInt(mStarts); |
| 5240 | out.writeLong(mLoadedUserTime); |
| 5241 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5242 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | out.writeInt(mLoadedStarts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5244 | out.writeLong(mUnpluggedUserTime); |
| 5245 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5246 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | out.writeInt(mUnpluggedStarts); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5248 | |
| 5249 | out.writeInt(mSpeedBins.length); |
| 5250 | for (int i = 0; i < mSpeedBins.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5251 | SamplingCounter c = mSpeedBins[i]; |
| 5252 | if (c != null) { |
| 5253 | out.writeInt(1); |
| 5254 | c.writeToParcel(out); |
| 5255 | } else { |
| 5256 | out.writeInt(0); |
| 5257 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5258 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5259 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5260 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | void readFromParcelLocked(Parcel in) { |
| 5264 | mUserTime = in.readLong(); |
| 5265 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5266 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5267 | mStarts = in.readInt(); |
| 5268 | mLoadedUserTime = in.readLong(); |
| 5269 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5270 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5272 | mLastUserTime = 0; |
| 5273 | mLastSystemTime = 0; |
| 5274 | mLastForegroundTime = 0; |
| 5275 | mLastStarts = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5276 | mUnpluggedUserTime = in.readLong(); |
| 5277 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5278 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | mUnpluggedStarts = in.readInt(); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5280 | |
| 5281 | int bins = in.readInt(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5282 | int steps = getCpuSpeedSteps(); |
| 5283 | mSpeedBins = new SamplingCounter[bins >= steps ? bins : steps]; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5284 | for (int i = 0; i < bins; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5285 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5286 | mSpeedBins[i] = new SamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5287 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5288 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5289 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5290 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | public BatteryStatsImpl getBatteryStats() { |
| 5294 | return BatteryStatsImpl.this; |
| 5295 | } |
| 5296 | |
| 5297 | public void addCpuTimeLocked(int utime, int stime) { |
| 5298 | mUserTime += utime; |
| 5299 | mSystemTime += stime; |
| 5300 | } |
| 5301 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5302 | public void addForegroundTimeLocked(long ttime) { |
| 5303 | mForegroundTime += ttime; |
| 5304 | } |
| 5305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | public void incStartsLocked() { |
| 5307 | mStarts++; |
| 5308 | } |
| 5309 | |
| 5310 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5311 | public boolean isActive() { |
| 5312 | return mActive; |
| 5313 | } |
| 5314 | |
| 5315 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5316 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5317 | long val = mUserTime; |
| 5318 | if (which == STATS_CURRENT) { |
| 5319 | val -= mLoadedUserTime; |
| 5320 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5321 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5322 | } |
| 5323 | return val; |
| 5324 | } |
| 5325 | |
| 5326 | @Override |
| 5327 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5328 | long val = mSystemTime; |
| 5329 | if (which == STATS_CURRENT) { |
| 5330 | val -= mLoadedSystemTime; |
| 5331 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5332 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | } |
| 5334 | return val; |
| 5335 | } |
| 5336 | |
| 5337 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5338 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5339 | long val = mForegroundTime; |
| 5340 | if (which == STATS_CURRENT) { |
| 5341 | val -= mLoadedForegroundTime; |
| 5342 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5343 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5344 | } |
| 5345 | return val; |
| 5346 | } |
| 5347 | |
| 5348 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5349 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5350 | int val = mStarts; |
| 5351 | if (which == STATS_CURRENT) { |
| 5352 | val -= mLoadedStarts; |
| 5353 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5354 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | } |
| 5356 | return val; |
| 5357 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5358 | |
| 5359 | /* Called by ActivityManagerService when CPU times are updated. */ |
| 5360 | public void addSpeedStepTimes(long[] values) { |
| 5361 | for (int i = 0; i < mSpeedBins.length && i < values.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5362 | long amt = values[i]; |
| 5363 | if (amt != 0) { |
| 5364 | SamplingCounter c = mSpeedBins[i]; |
| 5365 | if (c == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5366 | mSpeedBins[i] = c = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5367 | } |
| 5368 | c.addCountAtomic(values[i]); |
| 5369 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5370 | } |
| 5371 | } |
| 5372 | |
| 5373 | @Override |
| 5374 | public long getTimeAtCpuSpeedStep(int speedStep, int which) { |
| 5375 | if (speedStep < mSpeedBins.length) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5376 | SamplingCounter c = mSpeedBins[speedStep]; |
| 5377 | return c != null ? c.getCountLocked(which) : 0; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5378 | } else { |
| 5379 | return 0; |
| 5380 | } |
| 5381 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | /** |
| 5385 | * The statistics associated with a particular package. |
| 5386 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5387 | 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] | 5388 | /** |
| 5389 | * Number of times this package has done something that could wake up the |
| 5390 | * device from sleep. |
| 5391 | */ |
| 5392 | int mWakeups; |
| 5393 | |
| 5394 | /** |
| 5395 | * Number of things that could wake up the device loaded from a |
| 5396 | * previous save. |
| 5397 | */ |
| 5398 | int mLoadedWakeups; |
| 5399 | |
| 5400 | /** |
| 5401 | * Number of things that could wake up the device as of the |
| 5402 | * last run. |
| 5403 | */ |
| 5404 | int mLastWakeups; |
| 5405 | |
| 5406 | /** |
| 5407 | * Number of things that could wake up the device as of the |
| 5408 | * last run. |
| 5409 | */ |
| 5410 | int mUnpluggedWakeups; |
| 5411 | |
| 5412 | /** |
| 5413 | * The statics we have collected for this package's services. |
| 5414 | */ |
| 5415 | final HashMap<String, Serv> mServiceStats = new HashMap<String, Serv>(); |
| 5416 | |
| 5417 | Pkg() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5418 | mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5420 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5421 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5422 | mUnpluggedWakeups = mWakeups; |
| 5423 | } |
| 5424 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5425 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5426 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5427 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5428 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5429 | mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5430 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | void readFromParcelLocked(Parcel in) { |
| 5433 | mWakeups = in.readInt(); |
| 5434 | mLoadedWakeups = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5435 | mLastWakeups = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5436 | mUnpluggedWakeups = in.readInt(); |
| 5437 | |
| 5438 | int numServs = in.readInt(); |
| 5439 | mServiceStats.clear(); |
| 5440 | for (int m = 0; m < numServs; m++) { |
| 5441 | String serviceName = in.readString(); |
| 5442 | Uid.Pkg.Serv serv = new Serv(); |
| 5443 | mServiceStats.put(serviceName, serv); |
| 5444 | |
| 5445 | serv.readFromParcelLocked(in); |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | void writeToParcelLocked(Parcel out) { |
| 5450 | out.writeInt(mWakeups); |
| 5451 | out.writeInt(mLoadedWakeups); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5452 | out.writeInt(mUnpluggedWakeups); |
| 5453 | |
| 5454 | out.writeInt(mServiceStats.size()); |
| 5455 | for (Map.Entry<String, Uid.Pkg.Serv> servEntry : mServiceStats.entrySet()) { |
| 5456 | out.writeString(servEntry.getKey()); |
| 5457 | Uid.Pkg.Serv serv = servEntry.getValue(); |
| 5458 | |
| 5459 | serv.writeToParcelLocked(out); |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | @Override |
| 5464 | public Map<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 5465 | return mServiceStats; |
| 5466 | } |
| 5467 | |
| 5468 | @Override |
| 5469 | public int getWakeups(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5470 | int val = mWakeups; |
| 5471 | if (which == STATS_CURRENT) { |
| 5472 | val -= mLoadedWakeups; |
| 5473 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5474 | val -= mUnpluggedWakeups; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | return val; |
| 5478 | } |
| 5479 | |
| 5480 | /** |
| 5481 | * The statistics associated with a particular service. |
| 5482 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5483 | 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] | 5484 | /** |
| 5485 | * Total time (ms in battery uptime) the service has been left started. |
| 5486 | */ |
| 5487 | long mStartTime; |
| 5488 | |
| 5489 | /** |
| 5490 | * If service has been started and not yet stopped, this is |
| 5491 | * when it was started. |
| 5492 | */ |
| 5493 | long mRunningSince; |
| 5494 | |
| 5495 | /** |
| 5496 | * True if we are currently running. |
| 5497 | */ |
| 5498 | boolean mRunning; |
| 5499 | |
| 5500 | /** |
| 5501 | * Total number of times startService() has been called. |
| 5502 | */ |
| 5503 | int mStarts; |
| 5504 | |
| 5505 | /** |
| 5506 | * Total time (ms in battery uptime) the service has been left launched. |
| 5507 | */ |
| 5508 | long mLaunchedTime; |
| 5509 | |
| 5510 | /** |
| 5511 | * If service has been launched and not yet exited, this is |
| 5512 | * when it was launched (ms in battery uptime). |
| 5513 | */ |
| 5514 | long mLaunchedSince; |
| 5515 | |
| 5516 | /** |
| 5517 | * True if we are currently launched. |
| 5518 | */ |
| 5519 | boolean mLaunched; |
| 5520 | |
| 5521 | /** |
| 5522 | * Total number times the service has been launched. |
| 5523 | */ |
| 5524 | int mLaunches; |
| 5525 | |
| 5526 | /** |
| 5527 | * The amount of time spent started loaded from a previous save |
| 5528 | * (ms in battery uptime). |
| 5529 | */ |
| 5530 | long mLoadedStartTime; |
| 5531 | |
| 5532 | /** |
| 5533 | * The number of starts loaded from a previous save. |
| 5534 | */ |
| 5535 | int mLoadedStarts; |
| 5536 | |
| 5537 | /** |
| 5538 | * The number of launches loaded from a previous save. |
| 5539 | */ |
| 5540 | int mLoadedLaunches; |
| 5541 | |
| 5542 | /** |
| 5543 | * The amount of time spent started as of the last run (ms |
| 5544 | * in battery uptime). |
| 5545 | */ |
| 5546 | long mLastStartTime; |
| 5547 | |
| 5548 | /** |
| 5549 | * The number of starts as of the last run. |
| 5550 | */ |
| 5551 | int mLastStarts; |
| 5552 | |
| 5553 | /** |
| 5554 | * The number of launches as of the last run. |
| 5555 | */ |
| 5556 | int mLastLaunches; |
| 5557 | |
| 5558 | /** |
| 5559 | * The amount of time spent started when last unplugged (ms |
| 5560 | * in battery uptime). |
| 5561 | */ |
| 5562 | long mUnpluggedStartTime; |
| 5563 | |
| 5564 | /** |
| 5565 | * The number of starts when last unplugged. |
| 5566 | */ |
| 5567 | int mUnpluggedStarts; |
| 5568 | |
| 5569 | /** |
| 5570 | * The number of launches when last unplugged. |
| 5571 | */ |
| 5572 | int mUnpluggedLaunches; |
| 5573 | |
| 5574 | Serv() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5575 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5576 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5577 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5578 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 5579 | long baseRealtime) { |
| 5580 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5581 | mUnpluggedStarts = mStarts; |
| 5582 | mUnpluggedLaunches = mLaunches; |
| 5583 | } |
| 5584 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5585 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 5586 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5588 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5589 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5590 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5591 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5593 | void readFromParcelLocked(Parcel in) { |
| 5594 | mStartTime = in.readLong(); |
| 5595 | mRunningSince = in.readLong(); |
| 5596 | mRunning = in.readInt() != 0; |
| 5597 | mStarts = in.readInt(); |
| 5598 | mLaunchedTime = in.readLong(); |
| 5599 | mLaunchedSince = in.readLong(); |
| 5600 | mLaunched = in.readInt() != 0; |
| 5601 | mLaunches = in.readInt(); |
| 5602 | mLoadedStartTime = in.readLong(); |
| 5603 | mLoadedStarts = in.readInt(); |
| 5604 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5605 | mLastStartTime = 0; |
| 5606 | mLastStarts = 0; |
| 5607 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | mUnpluggedStartTime = in.readLong(); |
| 5609 | mUnpluggedStarts = in.readInt(); |
| 5610 | mUnpluggedLaunches = in.readInt(); |
| 5611 | } |
| 5612 | |
| 5613 | void writeToParcelLocked(Parcel out) { |
| 5614 | out.writeLong(mStartTime); |
| 5615 | out.writeLong(mRunningSince); |
| 5616 | out.writeInt(mRunning ? 1 : 0); |
| 5617 | out.writeInt(mStarts); |
| 5618 | out.writeLong(mLaunchedTime); |
| 5619 | out.writeLong(mLaunchedSince); |
| 5620 | out.writeInt(mLaunched ? 1 : 0); |
| 5621 | out.writeInt(mLaunches); |
| 5622 | out.writeLong(mLoadedStartTime); |
| 5623 | out.writeInt(mLoadedStarts); |
| 5624 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | out.writeLong(mUnpluggedStartTime); |
| 5626 | out.writeInt(mUnpluggedStarts); |
| 5627 | out.writeInt(mUnpluggedLaunches); |
| 5628 | } |
| 5629 | |
| 5630 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 5631 | if (!mLaunched) return mLaunchedTime; |
| 5632 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 5633 | } |
| 5634 | |
| 5635 | long getStartTimeToNowLocked(long batteryUptime) { |
| 5636 | if (!mRunning) return mStartTime; |
| 5637 | return mStartTime + batteryUptime - mRunningSince; |
| 5638 | } |
| 5639 | |
| 5640 | public void startLaunchedLocked() { |
| 5641 | if (!mLaunched) { |
| 5642 | mLaunches++; |
| 5643 | mLaunchedSince = getBatteryUptimeLocked(); |
| 5644 | mLaunched = true; |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | public void stopLaunchedLocked() { |
| 5649 | if (mLaunched) { |
| 5650 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 5651 | if (time > 0) { |
| 5652 | mLaunchedTime += time; |
| 5653 | } else { |
| 5654 | mLaunches--; |
| 5655 | } |
| 5656 | mLaunched = false; |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | public void startRunningLocked() { |
| 5661 | if (!mRunning) { |
| 5662 | mStarts++; |
| 5663 | mRunningSince = getBatteryUptimeLocked(); |
| 5664 | mRunning = true; |
| 5665 | } |
| 5666 | } |
| 5667 | |
| 5668 | public void stopRunningLocked() { |
| 5669 | if (mRunning) { |
| 5670 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 5671 | if (time > 0) { |
| 5672 | mStartTime += time; |
| 5673 | } else { |
| 5674 | mStarts--; |
| 5675 | } |
| 5676 | mRunning = false; |
| 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | public BatteryStatsImpl getBatteryStats() { |
| 5681 | return BatteryStatsImpl.this; |
| 5682 | } |
| 5683 | |
| 5684 | @Override |
| 5685 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5686 | int val = mLaunches; |
| 5687 | if (which == STATS_CURRENT) { |
| 5688 | val -= mLoadedLaunches; |
| 5689 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5690 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5691 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5692 | return val; |
| 5693 | } |
| 5694 | |
| 5695 | @Override |
| 5696 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5697 | long val = getStartTimeToNowLocked(now); |
| 5698 | if (which == STATS_CURRENT) { |
| 5699 | val -= mLoadedStartTime; |
| 5700 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5701 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5703 | return val; |
| 5704 | } |
| 5705 | |
| 5706 | @Override |
| 5707 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5708 | int val = mStarts; |
| 5709 | if (which == STATS_CURRENT) { |
| 5710 | val -= mLoadedStarts; |
| 5711 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5712 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | return val; |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | public BatteryStatsImpl getBatteryStats() { |
| 5720 | return BatteryStatsImpl.this; |
| 5721 | } |
| 5722 | |
| 5723 | public void incWakeupsLocked() { |
| 5724 | mWakeups++; |
| 5725 | } |
| 5726 | |
| 5727 | final Serv newServiceStatsLocked() { |
| 5728 | return new Serv(); |
| 5729 | } |
| 5730 | } |
| 5731 | |
| 5732 | /** |
| 5733 | * Retrieve the statistics object for a particular process, creating |
| 5734 | * if needed. |
| 5735 | */ |
| 5736 | public Proc getProcessStatsLocked(String name) { |
| 5737 | Proc ps = mProcessStats.get(name); |
| 5738 | if (ps == null) { |
| 5739 | ps = new Proc(); |
| 5740 | mProcessStats.put(name, ps); |
| 5741 | } |
| 5742 | |
| 5743 | return ps; |
| 5744 | } |
| 5745 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5746 | public void updateProcessStateLocked(String procName, int state, long elapsedRealtimeMs) { |
| 5747 | int procState; |
| 5748 | if (state <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 5749 | procState = PROCESS_STATE_FOREGROUND; |
| 5750 | } else if (state <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 5751 | procState = PROCESS_STATE_ACTIVE; |
| 5752 | } else { |
| 5753 | procState = PROCESS_STATE_RUNNING; |
| 5754 | } |
| 5755 | updateRealProcessStateLocked(procName, procState, elapsedRealtimeMs); |
| 5756 | } |
| 5757 | |
| 5758 | public void updateRealProcessStateLocked(String procName, int procState, |
| 5759 | long elapsedRealtimeMs) { |
| 5760 | Proc proc = getProcessStatsLocked(procName); |
| 5761 | if (proc.mProcessState != procState) { |
| 5762 | boolean changed; |
| 5763 | if (procState < proc.mProcessState) { |
| 5764 | // Has this process become more important? If so, |
| 5765 | // we may need to change the uid if the currrent uid proc state |
| 5766 | // is not as important as what we are now setting. |
| 5767 | changed = mProcessState > procState; |
| 5768 | } else { |
| 5769 | // Has this process become less important? If so, |
| 5770 | // we may need to change the uid if the current uid proc state |
| 5771 | // is the same importance as the old setting. |
| 5772 | changed = mProcessState == proc.mProcessState; |
| 5773 | } |
| 5774 | proc.mProcessState = procState; |
| 5775 | if (changed) { |
| 5776 | // uid's state may have changed; compute what the new state should be. |
| 5777 | int uidProcState = PROCESS_STATE_NONE; |
| 5778 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5779 | proc = mProcessStats.valueAt(ip); |
| 5780 | if (proc.mProcessState < uidProcState) { |
| 5781 | uidProcState = proc.mProcessState; |
| 5782 | } |
| 5783 | } |
| 5784 | updateUidProcessStateLocked(uidProcState, elapsedRealtimeMs); |
| 5785 | } |
| 5786 | } |
| 5787 | } |
| 5788 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5789 | public SparseArray<? extends Pid> getPidStats() { |
| 5790 | return mPids; |
| 5791 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5792 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5793 | public Pid getPidStatsLocked(int pid) { |
| 5794 | Pid p = mPids.get(pid); |
| 5795 | if (p == null) { |
| 5796 | p = new Pid(); |
| 5797 | mPids.put(pid, p); |
| 5798 | } |
| 5799 | return p; |
| 5800 | } |
| 5801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5802 | /** |
| 5803 | * Retrieve the statistics object for a particular service, creating |
| 5804 | * if needed. |
| 5805 | */ |
| 5806 | public Pkg getPackageStatsLocked(String name) { |
| 5807 | Pkg ps = mPackageStats.get(name); |
| 5808 | if (ps == null) { |
| 5809 | ps = new Pkg(); |
| 5810 | mPackageStats.put(name, ps); |
| 5811 | } |
| 5812 | |
| 5813 | return ps; |
| 5814 | } |
| 5815 | |
| 5816 | /** |
| 5817 | * Retrieve the statistics object for a particular service, creating |
| 5818 | * if needed. |
| 5819 | */ |
| 5820 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 5821 | Pkg ps = getPackageStatsLocked(pkg); |
| 5822 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 5823 | if (ss == null) { |
| 5824 | ss = ps.newServiceStatsLocked(); |
| 5825 | ps.mServiceStats.put(serv, ss); |
| 5826 | } |
| 5827 | |
| 5828 | return ss; |
| 5829 | } |
| 5830 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5831 | public StopwatchTimer getSyncTimerLocked(String name) { |
| 5832 | StopwatchTimer t = mSyncStats.get(name); |
| 5833 | if (t == null) { |
| 5834 | final int N = mSyncStats.size(); |
| 5835 | if (N > MAX_WAKELOCKS_PER_UID) { |
| 5836 | name = BATCHED_WAKELOCK_NAME; |
| 5837 | t = mSyncStats.get(name); |
| 5838 | } |
| 5839 | if (t == null) { |
| 5840 | t = new StopwatchTimer(Uid.this, SYNC, null, mOnBatteryTimeBase); |
| 5841 | mSyncStats.put(name, t); |
| 5842 | } |
| 5843 | } |
| 5844 | return t; |
| 5845 | } |
| 5846 | |
| 5847 | public StopwatchTimer getJobTimerLocked(String name) { |
| 5848 | StopwatchTimer t = mJobStats.get(name); |
| 5849 | if (t == null) { |
| 5850 | final int N = mJobStats.size(); |
| 5851 | if (N > MAX_WAKELOCKS_PER_UID) { |
| 5852 | name = BATCHED_WAKELOCK_NAME; |
| 5853 | t = mJobStats.get(name); |
| 5854 | } |
| 5855 | if (t == null) { |
| 5856 | t = new StopwatchTimer(Uid.this, JOB, null, mOnBatteryTimeBase); |
| 5857 | mJobStats.put(name, t); |
| 5858 | } |
| 5859 | } |
| 5860 | return t; |
| 5861 | } |
| 5862 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5863 | public StopwatchTimer getWakeTimerLocked(String name, int type) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | Wakelock wl = mWakelockStats.get(name); |
| 5865 | if (wl == null) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 5866 | final int N = mWakelockStats.size(); |
Dianne Hackborn | af17baa | 2013-05-09 15:27:47 -0700 | [diff] [blame] | 5867 | if (N > MAX_WAKELOCKS_PER_UID) { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 5868 | name = BATCHED_WAKELOCK_NAME; |
| 5869 | wl = mWakelockStats.get(name); |
| 5870 | } |
| 5871 | if (wl == null) { |
| 5872 | wl = new Wakelock(); |
| 5873 | mWakelockStats.put(name, wl); |
| 5874 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5876 | StopwatchTimer t = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | switch (type) { |
| 5878 | case WAKE_TYPE_PARTIAL: |
| 5879 | t = wl.mTimerPartial; |
| 5880 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5881 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5882 | mPartialTimers, mOnBatteryScreenOffTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | wl.mTimerPartial = t; |
| 5884 | } |
| 5885 | return t; |
| 5886 | case WAKE_TYPE_FULL: |
| 5887 | t = wl.mTimerFull; |
| 5888 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5889 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5890 | mFullTimers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | wl.mTimerFull = t; |
| 5892 | } |
| 5893 | return t; |
| 5894 | case WAKE_TYPE_WINDOW: |
| 5895 | t = wl.mTimerWindow; |
| 5896 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5897 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5898 | mWindowTimers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | wl.mTimerWindow = t; |
| 5900 | } |
| 5901 | return t; |
| 5902 | default: |
| 5903 | throw new IllegalArgumentException("type=" + type); |
| 5904 | } |
| 5905 | } |
| 5906 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5907 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5908 | Sensor se = mSensorStats.get(sensor); |
| 5909 | if (se == null) { |
| 5910 | if (!create) { |
| 5911 | return null; |
| 5912 | } |
| 5913 | se = new Sensor(sensor); |
| 5914 | mSensorStats.put(sensor, se); |
| 5915 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5916 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5917 | if (t != null) { |
| 5918 | return t; |
| 5919 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5920 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5922 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5923 | mSensorTimers.put(sensor, timers); |
| 5924 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5925 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | se.mTimer = t; |
| 5927 | return t; |
| 5928 | } |
| 5929 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5930 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
| 5931 | StopwatchTimer t = getSyncTimerLocked(name); |
| 5932 | if (t != null) { |
| 5933 | t.startRunningLocked(elapsedRealtimeMs); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
| 5938 | StopwatchTimer t = getSyncTimerLocked(name); |
| 5939 | if (t != null) { |
| 5940 | t.stopRunningLocked(elapsedRealtimeMs); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
| 5945 | StopwatchTimer t = getJobTimerLocked(name); |
| 5946 | if (t != null) { |
| 5947 | t.startRunningLocked(elapsedRealtimeMs); |
| 5948 | } |
| 5949 | } |
| 5950 | |
| 5951 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
| 5952 | StopwatchTimer t = getJobTimerLocked(name); |
| 5953 | if (t != null) { |
| 5954 | t.stopRunningLocked(elapsedRealtimeMs); |
| 5955 | } |
| 5956 | } |
| 5957 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5958 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5959 | StopwatchTimer t = getWakeTimerLocked(name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5961 | t.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5962 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 5963 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5964 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5965 | if (p.mWakeNesting++ == 0) { |
| 5966 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 5967 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5968 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5969 | } |
| 5970 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5971 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5972 | StopwatchTimer t = getWakeTimerLocked(name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5973 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5974 | t.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5975 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 5976 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5977 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5978 | if (p != null && p.mWakeNesting > 0) { |
| 5979 | if (p.mWakeNesting-- == 1) { |
| 5980 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 5981 | p.mWakeStartMs = 0; |
| 5982 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5983 | } |
| 5984 | } |
| 5985 | } |
| 5986 | |
| 5987 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 5988 | Proc p = getProcessStatsLocked(proc); |
| 5989 | if (p != null) { |
| 5990 | p.addExcessiveWake(overTime, usedTime); |
| 5991 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5993 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5994 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 5995 | Proc p = getProcessStatsLocked(proc); |
| 5996 | if (p != null) { |
| 5997 | p.addExcessiveCpu(overTime, usedTime); |
| 5998 | } |
| 5999 | } |
| 6000 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6001 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6002 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6004 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6005 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | } |
| 6007 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6008 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6009 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6010 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6012 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6015 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6016 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6017 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6019 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6020 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6021 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6022 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6023 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6024 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6025 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6026 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6027 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | public BatteryStatsImpl getBatteryStats() { |
| 6031 | return BatteryStatsImpl.this; |
| 6032 | } |
| 6033 | } |
| 6034 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 6035 | public BatteryStatsImpl(String filename, Handler handler) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6036 | mFile = new JournaledFile(new File(filename), new File(filename + ".tmp")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 6037 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6038 | mStartCount++; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6039 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6040 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6041 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6042 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6043 | mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6044 | mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase); |
| 6045 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6046 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6047 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, |
| 6048 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6049 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6050 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6051 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6052 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, |
| 6053 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6054 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6055 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6056 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6057 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6058 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6059 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); |
| 6060 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6061 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6062 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6063 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6064 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase); |
| 6065 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6066 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6067 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6068 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6069 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 6070 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, null, mOnBatteryTimeBase); |
| 6071 | } |
| 6072 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 6073 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, null, |
| 6074 | mOnBatteryTimeBase); |
| 6075 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6076 | mBluetoothOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6077 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6078 | mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6079 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6080 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
| 6081 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6082 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6084 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 6085 | long realtime = SystemClock.elapsedRealtime() * 1000; |
| 6086 | initTimes(uptime, realtime); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6087 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6088 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6089 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6090 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6091 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6092 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6093 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6097 | mFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6098 | mHandler = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6099 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | readFromParcel(p); |
| 6101 | } |
| 6102 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6103 | public void setCallback(BatteryCallback cb) { |
| 6104 | mCallback = cb; |
| 6105 | } |
| 6106 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6107 | public void setNumSpeedSteps(int steps) { |
| 6108 | if (sNumSpeedSteps == 0) sNumSpeedSteps = steps; |
| 6109 | } |
| 6110 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6111 | public void setRadioScanningTimeout(long timeout) { |
| 6112 | if (mPhoneSignalScanningTimer != null) { |
| 6113 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 6114 | } |
| 6115 | } |
| 6116 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6117 | @Override |
| 6118 | public boolean startIteratingOldHistoryLocked() { |
| 6119 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 6120 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6121 | if ((mHistoryIterator = mHistory) == null) { |
| 6122 | return false; |
| 6123 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6124 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 6125 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6126 | mReadOverflow = false; |
| 6127 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6128 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6129 | } |
| 6130 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6131 | @Override |
| 6132 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 6133 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 6134 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6135 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 6136 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6137 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6138 | HistoryItem cur = mHistoryIterator; |
| 6139 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6140 | if (!mReadOverflow && !end) { |
| 6141 | Slog.w(TAG, "Old history ends before new history!"); |
| 6142 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6143 | return false; |
| 6144 | } |
| 6145 | out.setTo(cur); |
| 6146 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6147 | if (!mReadOverflow) { |
| 6148 | if (end) { |
| 6149 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 6150 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 6151 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6152 | pw.println("Histories differ!"); |
| 6153 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6154 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6155 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6156 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 6157 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 6158 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6159 | } |
| 6160 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6161 | return true; |
| 6162 | } |
| 6163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6165 | public void finishIteratingOldHistoryLocked() { |
| 6166 | mIteratingHistory = false; |
| 6167 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6168 | mHistoryIterator = null; |
| 6169 | } |
| 6170 | |
| 6171 | public int getHistoryTotalSize() { |
| 6172 | return MAX_HISTORY_BUFFER; |
| 6173 | } |
| 6174 | |
| 6175 | public int getHistoryUsedSize() { |
| 6176 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | @Override |
| 6180 | public boolean startIteratingHistoryLocked() { |
| 6181 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 6182 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6183 | if (mHistoryBuffer.dataSize() <= 0) { |
| 6184 | return false; |
| 6185 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6186 | mHistoryBuffer.setDataPosition(0); |
| 6187 | mReadOverflow = false; |
| 6188 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6189 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 6190 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 6191 | mReadHistoryChars = 0; |
| 6192 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 6193 | final HistoryTag tag = ent.getKey(); |
| 6194 | final int idx = ent.getValue(); |
| 6195 | mReadHistoryStrings[idx] = tag.string; |
| 6196 | mReadHistoryUids[idx] = tag.uid; |
| 6197 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6198 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6199 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6203 | public int getHistoryStringPoolSize() { |
| 6204 | return mReadHistoryStrings.length; |
| 6205 | } |
| 6206 | |
| 6207 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6208 | public int getHistoryStringPoolBytes() { |
| 6209 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 6210 | // Each string character is 2 bytes. |
| 6211 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 6212 | } |
| 6213 | |
| 6214 | @Override |
| 6215 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6216 | return mReadHistoryStrings[index]; |
| 6217 | } |
| 6218 | |
| 6219 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6220 | public int getHistoryTagPoolUid(int index) { |
| 6221 | return mReadHistoryUids[index]; |
| 6222 | } |
| 6223 | |
| 6224 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6225 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 6226 | final int pos = mHistoryBuffer.dataPosition(); |
| 6227 | if (pos == 0) { |
| 6228 | out.clear(); |
| 6229 | } |
| 6230 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6231 | if (end) { |
| 6232 | return false; |
| 6233 | } |
| 6234 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6235 | final long lastRealtime = out.time; |
| 6236 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6237 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6238 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 6239 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6240 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 6241 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6242 | return true; |
| 6243 | } |
| 6244 | |
| 6245 | @Override |
| 6246 | public void finishIteratingHistoryLocked() { |
| 6247 | mIteratingHistory = false; |
| 6248 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6249 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6250 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6251 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6252 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6253 | public long getHistoryBaseTime() { |
| 6254 | return mHistoryBaseTime; |
| 6255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6256 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6257 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | public int getStartCount() { |
| 6259 | return mStartCount; |
| 6260 | } |
| 6261 | |
| 6262 | public boolean isOnBattery() { |
| 6263 | return mOnBattery; |
| 6264 | } |
| 6265 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6266 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6267 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6268 | } |
| 6269 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6270 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6271 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6272 | mOnBatteryTimeBase.init(uptime, realtime); |
| 6273 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6274 | mRealtime = 0; |
| 6275 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6276 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6277 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6278 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6279 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6280 | void initDischarge() { |
| 6281 | mLowDischargeAmountSinceCharge = 0; |
| 6282 | mHighDischargeAmountSinceCharge = 0; |
| 6283 | mDischargeAmountScreenOn = 0; |
| 6284 | mDischargeAmountScreenOnSinceCharge = 0; |
| 6285 | mDischargeAmountScreenOff = 0; |
| 6286 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6287 | mLastDischargeStepTime = -1; |
| 6288 | mNumDischargeStepDurations = 0; |
| 6289 | mLastChargeStepTime = -1; |
| 6290 | mNumChargeStepDurations = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6291 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6292 | |
| 6293 | public void resetAllStatsCmdLocked() { |
| 6294 | resetAllStatsLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6295 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 6296 | long uptime = mSecUptime * 1000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6297 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 6298 | long realtime = mSecRealtime * 1000; |
| 6299 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 6300 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6301 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6302 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 6303 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6304 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 6305 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 6306 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6307 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6308 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 6309 | mDischargeScreenOffUnplugLevel = 0; |
| 6310 | } else { |
| 6311 | mDischargeScreenOnUnplugLevel = 0; |
| 6312 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 6313 | } |
| 6314 | mDischargeAmountScreenOn = 0; |
| 6315 | mDischargeAmountScreenOff = 0; |
| 6316 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6317 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6321 | mStartCount = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6322 | initTimes(SystemClock.uptimeMillis() * 1000, SystemClock.elapsedRealtime() * 1000); |
| 6323 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6324 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6325 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6326 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6327 | mInteractiveTimer.reset(false); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6328 | mLowPowerModeEnabledTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6329 | mPhoneOnTimer.reset(false); |
| 6330 | mAudioOnTimer.reset(false); |
| 6331 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6332 | mFlashlightOnTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6333 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6334 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6335 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6336 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6337 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6338 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6339 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6340 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6341 | mNetworkByteActivityCounters[i].reset(false); |
| 6342 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6343 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6344 | mMobileRadioActiveTimer.reset(false); |
| 6345 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6346 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6347 | mMobileRadioActiveUnknownTime.reset(false); |
| 6348 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6349 | mWifiOnTimer.reset(false); |
| 6350 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6351 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6352 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6353 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6354 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 6355 | mWifiSupplStateTimer[i].reset(false); |
| 6356 | } |
| 6357 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 6358 | mWifiSignalStrengthsTimer[i].reset(false); |
| 6359 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6360 | mBluetoothOnTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6361 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6362 | mBluetoothStateTimer[i].reset(false); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6363 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6364 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6365 | for (int i=0; i<mUidStats.size(); i++) { |
| 6366 | if (mUidStats.valueAt(i).reset()) { |
| 6367 | mUidStats.remove(mUidStats.keyAt(i)); |
| 6368 | i--; |
| 6369 | } |
| 6370 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6371 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6372 | if (mKernelWakelockStats.size() > 0) { |
| 6373 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6374 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6375 | } |
| 6376 | mKernelWakelockStats.clear(); |
| 6377 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6378 | |
| 6379 | if (mWakeupReasonStats.size() > 0) { |
| 6380 | for (LongSamplingCounter timer : mWakeupReasonStats.values()) { |
| 6381 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 6382 | } |
| 6383 | mWakeupReasonStats.clear(); |
| 6384 | } |
| 6385 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6386 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6387 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6388 | clearHistoryLocked(); |
| 6389 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6390 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6391 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6392 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6393 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6394 | if (active == null) { |
| 6395 | continue; |
| 6396 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6397 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 6398 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6399 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6400 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 6401 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6402 | } |
| 6403 | } |
| 6404 | } |
| 6405 | } |
| 6406 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6407 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6408 | if (oldScreenOn) { |
| 6409 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 6410 | if (diff > 0) { |
| 6411 | mDischargeAmountScreenOn += diff; |
| 6412 | mDischargeAmountScreenOnSinceCharge += diff; |
| 6413 | } |
| 6414 | } else { |
| 6415 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 6416 | if (diff > 0) { |
| 6417 | mDischargeAmountScreenOff += diff; |
| 6418 | mDischargeAmountScreenOffSinceCharge += diff; |
| 6419 | } |
| 6420 | } |
| 6421 | if (newScreenOn) { |
| 6422 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 6423 | mDischargeScreenOffUnplugLevel = 0; |
| 6424 | } else { |
| 6425 | mDischargeScreenOnUnplugLevel = 0; |
| 6426 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 6427 | } |
| 6428 | } |
| 6429 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 6430 | public void pullPendingStateUpdatesLocked() { |
| 6431 | updateKernelWakelocksLocked(); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6432 | updateNetworkActivityLocked(NET_UPDATE_ALL, SystemClock.elapsedRealtime()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6433 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6434 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 6435 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6436 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 6437 | } |
| 6438 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6439 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 6440 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6441 | boolean doWrite = false; |
| 6442 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 6443 | m.arg1 = onBattery ? 1 : 0; |
| 6444 | mHandler.sendMessage(m); |
| 6445 | mOnBattery = mOnBatteryInternal = onBattery; |
| 6446 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6447 | final long uptime = mSecUptime * 1000; |
| 6448 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6449 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6450 | if (onBattery) { |
| 6451 | // We will reset our status if we are unplugging after the |
| 6452 | // battery was last full, or the level is at 100, or |
| 6453 | // we have gone through a significant charge (from a very low |
| 6454 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6455 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 6456 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6457 | || level >= 90 |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 6458 | || (mDischargeCurrentLevel < 20 && level >= 80))) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6459 | doWrite = true; |
| 6460 | resetAllStatsLocked(); |
| 6461 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 6462 | reset = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6463 | mNumDischargeStepDurations = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6464 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6465 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6466 | mMinDischargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6467 | mLastDischargeStepTime = -1; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 6468 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6469 | mHistoryCur.batteryLevel = (byte)level; |
| 6470 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 6471 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 6472 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6473 | if (reset) { |
| 6474 | mRecordingHistory = true; |
| 6475 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 6476 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6477 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6478 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6479 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6480 | mDischargeScreenOnUnplugLevel = level; |
| 6481 | mDischargeScreenOffUnplugLevel = 0; |
| 6482 | } else { |
| 6483 | mDischargeScreenOnUnplugLevel = 0; |
| 6484 | mDischargeScreenOffUnplugLevel = level; |
| 6485 | } |
| 6486 | mDischargeAmountScreenOn = 0; |
| 6487 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6488 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6489 | } else { |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 6490 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6491 | mHistoryCur.batteryLevel = (byte)level; |
| 6492 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 6493 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 6494 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6495 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6496 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6497 | if (level < mDischargeUnplugLevel) { |
| 6498 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 6499 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 6500 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6501 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 6502 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6503 | mNumChargeStepDurations = 0; |
| 6504 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6505 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6506 | mLastChargeStepTime = -1; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6507 | } |
| 6508 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 6509 | if (mFile != null) { |
| 6510 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | } |
| 6512 | } |
| 6513 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6514 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6515 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 6516 | boolean reset) { |
| 6517 | mRecordingHistory = true; |
| 6518 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6519 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 6520 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6521 | mHistoryCur); |
| 6522 | mHistoryCur.currentTime = 0; |
| 6523 | if (reset) { |
| 6524 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 6525 | } |
| 6526 | } |
| 6527 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6528 | // This should probably be exposed in the API, though it's not critical |
| 6529 | private static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6530 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6531 | private static int addLevelSteps(long[] steps, int stepCount, long lastStepTime, |
| 6532 | int numStepLevels, long elapsedRealtime) { |
| 6533 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 6534 | long duration = elapsedRealtime - lastStepTime; |
| 6535 | for (int i=0; i<numStepLevels; i++) { |
| 6536 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 6537 | long thisDuration = duration / (numStepLevels-i); |
| 6538 | duration -= thisDuration; |
| 6539 | steps[0] = thisDuration; |
| 6540 | } |
| 6541 | stepCount += numStepLevels; |
| 6542 | if (stepCount > steps.length) { |
| 6543 | stepCount = steps.length; |
| 6544 | } |
| 6545 | } |
| 6546 | return stepCount; |
| 6547 | } |
| 6548 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6549 | public void setBatteryState(int status, int health, int plugType, int level, |
| 6550 | int temp, int volt) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6551 | synchronized(this) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6552 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 6553 | final long uptime = SystemClock.uptimeMillis(); |
| 6554 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6555 | int oldStatus = mHistoryCur.batteryStatus; |
| 6556 | if (!mHaveBatteryLevel) { |
| 6557 | mHaveBatteryLevel = true; |
| 6558 | // We start out assuming that the device is plugged in (not |
| 6559 | // on battery). If our first report is now that we are indeed |
| 6560 | // plugged in, then twiddle our state to correctly reflect that |
| 6561 | // since we won't be going through the full setOnBattery(). |
| 6562 | if (onBattery == mOnBattery) { |
| 6563 | if (onBattery) { |
| 6564 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 6565 | } else { |
| 6566 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 6567 | } |
| 6568 | } |
| 6569 | oldStatus = status; |
| 6570 | } |
| 6571 | if (onBattery) { |
| 6572 | mDischargeCurrentLevel = level; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6573 | if (!mRecordingHistory) { |
| 6574 | mRecordingHistory = true; |
| 6575 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 6576 | } |
| 6577 | } else if (level < 96) { |
| 6578 | if (!mRecordingHistory) { |
| 6579 | mRecordingHistory = true; |
| 6580 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 6581 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6582 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6583 | mCurrentBatteryLevel = level; |
| 6584 | if (mDischargePlugLevel < 0) { |
| 6585 | mDischargePlugLevel = level; |
| 6586 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6587 | if (onBattery != mOnBattery) { |
| 6588 | mHistoryCur.batteryLevel = (byte)level; |
| 6589 | mHistoryCur.batteryStatus = (byte)status; |
| 6590 | mHistoryCur.batteryHealth = (byte)health; |
| 6591 | mHistoryCur.batteryPlugType = (byte)plugType; |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 6592 | mHistoryCur.batteryTemperature = (short)temp; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6593 | mHistoryCur.batteryVoltage = (char)volt; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6594 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6595 | } else { |
| 6596 | boolean changed = false; |
| 6597 | if (mHistoryCur.batteryLevel != level) { |
| 6598 | mHistoryCur.batteryLevel = (byte)level; |
| 6599 | changed = true; |
| 6600 | } |
| 6601 | if (mHistoryCur.batteryStatus != status) { |
| 6602 | mHistoryCur.batteryStatus = (byte)status; |
| 6603 | changed = true; |
| 6604 | } |
| 6605 | if (mHistoryCur.batteryHealth != health) { |
| 6606 | mHistoryCur.batteryHealth = (byte)health; |
| 6607 | changed = true; |
| 6608 | } |
| 6609 | if (mHistoryCur.batteryPlugType != plugType) { |
| 6610 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 6611 | changed = true; |
| 6612 | } |
| 6613 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 6614 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 6615 | mHistoryCur.batteryTemperature = (short)temp; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6616 | changed = true; |
| 6617 | } |
| 6618 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 6619 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 6620 | mHistoryCur.batteryVoltage = (char)volt; |
| 6621 | changed = true; |
| 6622 | } |
| 6623 | if (changed) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6624 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6625 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6626 | if (onBattery) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6627 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6628 | mNumDischargeStepDurations = addLevelSteps(mDischargeStepDurations, |
| 6629 | mNumDischargeStepDurations, mLastDischargeStepTime, |
| 6630 | mLastDischargeStepLevel - level, elapsedRealtime); |
| 6631 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6632 | mMinDischargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6633 | mLastDischargeStepTime = elapsedRealtime; |
| 6634 | } |
| 6635 | } else { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6636 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6637 | mNumChargeStepDurations = addLevelSteps(mChargeStepDurations, |
| 6638 | mNumChargeStepDurations, mLastChargeStepTime, |
| 6639 | level - mLastChargeStepLevel, elapsedRealtime); |
| 6640 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6641 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6642 | mLastChargeStepTime = elapsedRealtime; |
| 6643 | } |
| 6644 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6645 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6646 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 6647 | // We don't record history while we are plugged in and fully charged. |
| 6648 | // The next time we are unplugged, history will be cleared. |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6649 | mRecordingHistory = DEBUG; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6650 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6651 | } |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6652 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6653 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6654 | public void updateKernelWakelocksLocked() { |
| 6655 | Map<String, KernelWakelockStats> m = readKernelWakelockStats(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6656 | |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 6657 | if (m == null) { |
| 6658 | // Not crashing might make board bringup easier. |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6659 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 6660 | return; |
| 6661 | } |
| 6662 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6663 | for (Map.Entry<String, KernelWakelockStats> ent : m.entrySet()) { |
| 6664 | String name = ent.getKey(); |
| 6665 | KernelWakelockStats kws = ent.getValue(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6666 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6667 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 6668 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6669 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, |
| 6670 | true /* track reported val */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6671 | mKernelWakelockStats.put(name, kwlt); |
| 6672 | } |
| 6673 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 6674 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 6675 | kwlt.setUpdateVersion(sKernelWakelockUpdateVersion); |
| 6676 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6677 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6678 | if (m.size() != mKernelWakelockStats.size()) { |
| 6679 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 6680 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 6681 | SamplingTimer st = ent.getValue(); |
| 6682 | if (st.getUpdateVersion() != sKernelWakelockUpdateVersion) { |
| 6683 | st.setStale(); |
| 6684 | } |
| 6685 | } |
| 6686 | } |
| 6687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6688 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6689 | static final int NET_UPDATE_MOBILE = 1<<0; |
| 6690 | static final int NET_UPDATE_WIFI = 1<<1; |
| 6691 | static final int NET_UPDATE_ALL = 0xffff; |
| 6692 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6693 | private void updateNetworkActivityLocked(int which, long elapsedRealtimeMs) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6694 | if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) return; |
| 6695 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6696 | if ((which&NET_UPDATE_MOBILE) != 0 && mMobileIfaces.length > 0) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6697 | final NetworkStats snapshot; |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6698 | final NetworkStats last = mCurMobileSnapshot; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6699 | try { |
| 6700 | snapshot = mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL, |
| 6701 | mMobileIfaces, NetworkStats.TAG_NONE, mLastMobileSnapshot); |
| 6702 | } catch (IOException e) { |
| 6703 | Log.wtf(TAG, "Failed to read mobile network stats", e); |
| 6704 | return; |
| 6705 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6706 | |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6707 | mCurMobileSnapshot = snapshot; |
| 6708 | mLastMobileSnapshot = last; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6709 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6710 | if (mOnBatteryInternal) { |
| 6711 | final NetworkStats delta = NetworkStats.subtract(snapshot, last, |
| 6712 | null, null, mTmpNetworkStats); |
| 6713 | mTmpNetworkStats = delta; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6714 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6715 | long radioTime = mMobileRadioActivePerAppTimer.checkpointRunningLocked( |
| 6716 | elapsedRealtimeMs); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6717 | long totalPackets = delta.getTotalPackets(); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6718 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6719 | final int size = delta.size(); |
| 6720 | for (int i = 0; i < size; i++) { |
| 6721 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6722 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6723 | if (entry.rxBytes == 0 || entry.txBytes == 0) continue; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6724 | |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6725 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6726 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 6727 | entry.rxPackets); |
| 6728 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 6729 | entry.txPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6730 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6731 | if (radioTime > 0) { |
| 6732 | // Distribute total radio active time in to this app. |
| 6733 | long appPackets = entry.rxPackets + entry.txPackets; |
| 6734 | long appRadioTime = (radioTime*appPackets)/totalPackets; |
| 6735 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 6736 | // Remove this app from the totals, so that we don't lose any time |
| 6737 | // due to rounding. |
| 6738 | radioTime -= appRadioTime; |
| 6739 | totalPackets -= appPackets; |
| 6740 | } |
| 6741 | |
| 6742 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 6743 | entry.rxBytes); |
| 6744 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 6745 | entry.txBytes); |
| 6746 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 6747 | entry.rxPackets); |
| 6748 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 6749 | entry.txPackets); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6750 | } |
| 6751 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6752 | if (radioTime > 0) { |
| 6753 | // Whoops, there is some radio time we can't blame on an app! |
| 6754 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 6755 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 6756 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6757 | } |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6758 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6759 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6760 | if ((which&NET_UPDATE_WIFI) != 0 && mWifiIfaces.length > 0) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6761 | final NetworkStats snapshot; |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6762 | final NetworkStats last = mCurWifiSnapshot; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6763 | try { |
| 6764 | snapshot = mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL, |
| 6765 | mWifiIfaces, NetworkStats.TAG_NONE, mLastWifiSnapshot); |
| 6766 | } catch (IOException e) { |
| 6767 | Log.wtf(TAG, "Failed to read wifi network stats", e); |
| 6768 | return; |
| 6769 | } |
| 6770 | |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6771 | mCurWifiSnapshot = snapshot; |
| 6772 | mLastWifiSnapshot = last; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6773 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6774 | if (mOnBatteryInternal) { |
| 6775 | final NetworkStats delta = NetworkStats.subtract(snapshot, last, |
| 6776 | null, null, mTmpNetworkStats); |
| 6777 | mTmpNetworkStats = delta; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6778 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6779 | final int size = delta.size(); |
| 6780 | for (int i = 0; i < size; i++) { |
| 6781 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6782 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6783 | if (DEBUG) { |
| 6784 | final NetworkStats.Entry cur = snapshot.getValues(i, null); |
| 6785 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 6786 | + " tx=" + entry.txBytes + ", cur rx=" + cur.rxBytes |
| 6787 | + " tx=" + cur.txBytes); |
| 6788 | } |
| 6789 | |
| 6790 | if (entry.rxBytes == 0 || entry.txBytes == 0) continue; |
| 6791 | |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6792 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6793 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 6794 | entry.rxPackets); |
| 6795 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 6796 | entry.txPackets); |
| 6797 | |
| 6798 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 6799 | entry.rxBytes); |
| 6800 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 6801 | entry.txBytes); |
| 6802 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 6803 | entry.rxPackets); |
| 6804 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 6805 | entry.txPackets); |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6806 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6807 | } |
| 6808 | } |
| 6809 | } |
| 6810 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | public long getAwakeTimeBattery() { |
| 6812 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 6813 | } |
| 6814 | |
| 6815 | public long getAwakeTimePlugged() { |
| 6816 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 6817 | } |
| 6818 | |
| 6819 | @Override |
| 6820 | public long computeUptime(long curTime, int which) { |
| 6821 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6822 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6824 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6825 | } |
| 6826 | return 0; |
| 6827 | } |
| 6828 | |
| 6829 | @Override |
| 6830 | public long computeRealtime(long curTime, int which) { |
| 6831 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6832 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6833 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6834 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | } |
| 6836 | return 0; |
| 6837 | } |
| 6838 | |
| 6839 | @Override |
| 6840 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6841 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | @Override |
| 6845 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6846 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6847 | } |
| 6848 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6849 | @Override |
| 6850 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 6851 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 6852 | } |
| 6853 | |
| 6854 | @Override |
| 6855 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 6856 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6857 | } |
| 6858 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6859 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 6860 | // For now we'll do a simple average across all steps. |
| 6861 | if (numSteps <= 0) { |
| 6862 | return -1; |
| 6863 | } |
| 6864 | long total = 0; |
| 6865 | for (int i=0; i<numSteps; i++) { |
| 6866 | total += steps[i]; |
| 6867 | } |
| 6868 | return total / numSteps; |
| 6869 | /* |
| 6870 | long[] buckets = new long[numSteps]; |
| 6871 | int numBuckets = 0; |
| 6872 | int numToAverage = 4; |
| 6873 | int i = 0; |
| 6874 | while (i < numSteps) { |
| 6875 | long totalTime = 0; |
| 6876 | int num = 0; |
| 6877 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 6878 | totalTime += steps[i+j]; |
| 6879 | num++; |
| 6880 | } |
| 6881 | buckets[numBuckets] = totalTime / num; |
| 6882 | numBuckets++; |
| 6883 | numToAverage *= 2; |
| 6884 | i += num; |
| 6885 | } |
| 6886 | if (numBuckets < 1) { |
| 6887 | return -1; |
| 6888 | } |
| 6889 | long averageTime = buckets[numBuckets-1]; |
| 6890 | for (i=numBuckets-2; i>=0; i--) { |
| 6891 | averageTime = (averageTime + buckets[i]) / 2; |
| 6892 | } |
| 6893 | return averageTime; |
| 6894 | */ |
| 6895 | } |
| 6896 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6897 | @Override |
| 6898 | public long computeBatteryTimeRemaining(long curTime) { |
| 6899 | if (!mOnBattery) { |
| 6900 | return -1; |
| 6901 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6902 | /* Simple implementation just looks at the average discharge per level across the |
| 6903 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6904 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 6905 | if (discharge < 2) { |
| 6906 | return -1; |
| 6907 | } |
| 6908 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 6909 | if (duration < 1000*1000) { |
| 6910 | return -1; |
| 6911 | } |
| 6912 | long usPerLevel = duration/discharge; |
| 6913 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6914 | */ |
| 6915 | if (mNumDischargeStepDurations < 1) { |
| 6916 | return -1; |
| 6917 | } |
| 6918 | long msPerLevel = computeTimePerLevel(mDischargeStepDurations, mNumDischargeStepDurations); |
| 6919 | if (msPerLevel <= 0) { |
| 6920 | return -1; |
| 6921 | } |
| 6922 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6923 | } |
| 6924 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6925 | public int getNumDischargeStepDurations() { |
| 6926 | return mNumDischargeStepDurations; |
| 6927 | } |
| 6928 | |
| 6929 | public long[] getDischargeStepDurationsArray() { |
| 6930 | return mDischargeStepDurations; |
| 6931 | } |
| 6932 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6933 | @Override |
| 6934 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6935 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6936 | // Not yet working. |
| 6937 | return -1; |
| 6938 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6939 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6940 | int curLevel = mCurrentBatteryLevel; |
| 6941 | int plugLevel = mDischargePlugLevel; |
| 6942 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 6943 | return -1; |
| 6944 | } |
| 6945 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 6946 | if (duration < 1000*1000) { |
| 6947 | return -1; |
| 6948 | } |
| 6949 | long usPerLevel = duration/(curLevel-plugLevel); |
| 6950 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6951 | */ |
| 6952 | if (mNumChargeStepDurations < 1) { |
| 6953 | return -1; |
| 6954 | } |
| 6955 | long msPerLevel = computeTimePerLevel(mChargeStepDurations, mNumChargeStepDurations); |
| 6956 | if (msPerLevel <= 0) { |
| 6957 | return -1; |
| 6958 | } |
| 6959 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6960 | } |
| 6961 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6962 | public int getNumChargeStepDurations() { |
| 6963 | return mNumChargeStepDurations; |
| 6964 | } |
| 6965 | |
| 6966 | public long[] getChargeStepDurationsArray() { |
| 6967 | return mChargeStepDurations; |
| 6968 | } |
| 6969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | long getBatteryUptimeLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6971 | return mOnBatteryTimeBase.getUptime(SystemClock.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | @Override |
| 6975 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6976 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | @Override |
| 6980 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6981 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6982 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 6983 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6984 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6985 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6986 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6987 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6988 | } |
| 6989 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6990 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6991 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6992 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6993 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6994 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6995 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6996 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6997 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6998 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6999 | } |
| 7000 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7001 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7002 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7003 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7004 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7006 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7007 | public int getLowDischargeAmountSinceCharge() { |
| 7008 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7009 | int val = mLowDischargeAmountSinceCharge; |
| 7010 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 7011 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 7012 | } |
| 7013 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7014 | } |
| 7015 | } |
| 7016 | |
| 7017 | @Override |
| 7018 | public int getHighDischargeAmountSinceCharge() { |
| 7019 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7020 | int val = mHighDischargeAmountSinceCharge; |
| 7021 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 7022 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 7023 | } |
| 7024 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7025 | } |
| 7026 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7027 | |
| 7028 | @Override |
| 7029 | public int getDischargeAmount(int which) { |
| 7030 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 7031 | ? getHighDischargeAmountSinceCharge() |
| 7032 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 7033 | if (dischargeAmount < 0) { |
| 7034 | dischargeAmount = 0; |
| 7035 | } |
| 7036 | return dischargeAmount; |
| 7037 | } |
| 7038 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7039 | public int getDischargeAmountScreenOn() { |
| 7040 | synchronized(this) { |
| 7041 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7042 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7043 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 7044 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 7045 | } |
| 7046 | return val; |
| 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | public int getDischargeAmountScreenOnSinceCharge() { |
| 7051 | synchronized(this) { |
| 7052 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7053 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7054 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 7055 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 7056 | } |
| 7057 | return val; |
| 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | public int getDischargeAmountScreenOff() { |
| 7062 | synchronized(this) { |
| 7063 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7064 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7065 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 7066 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 7067 | } |
| 7068 | return val; |
| 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | public int getDischargeAmountScreenOffSinceCharge() { |
| 7073 | synchronized(this) { |
| 7074 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7075 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7076 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 7077 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 7078 | } |
| 7079 | return val; |
| 7080 | } |
| 7081 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7082 | |
| 7083 | @Override |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7084 | public int getCpuSpeedSteps() { |
| 7085 | return sNumSpeedSteps; |
| 7086 | } |
| 7087 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7088 | /** |
| 7089 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 7090 | */ |
| 7091 | public Uid getUidStatsLocked(int uid) { |
| 7092 | Uid u = mUidStats.get(uid); |
| 7093 | if (u == null) { |
| 7094 | u = new Uid(uid); |
| 7095 | mUidStats.put(uid, u); |
| 7096 | } |
| 7097 | return u; |
| 7098 | } |
| 7099 | |
| 7100 | /** |
| 7101 | * Remove the statistics object for a particular uid. |
| 7102 | */ |
| 7103 | public void removeUidStatsLocked(int uid) { |
| 7104 | mUidStats.remove(uid); |
| 7105 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 7106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7107 | /** |
| 7108 | * Retrieve the statistics object for a particular process, creating |
| 7109 | * if needed. |
| 7110 | */ |
| 7111 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 7112 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7113 | Uid u = getUidStatsLocked(uid); |
| 7114 | return u.getProcessStatsLocked(name); |
| 7115 | } |
| 7116 | |
| 7117 | /** |
| 7118 | * Retrieve the statistics object for a particular process, creating |
| 7119 | * if needed. |
| 7120 | */ |
| 7121 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 7122 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7123 | Uid u = getUidStatsLocked(uid); |
| 7124 | return u.getPackageStatsLocked(pkg); |
| 7125 | } |
| 7126 | |
| 7127 | /** |
| 7128 | * Retrieve the statistics object for a particular service, creating |
| 7129 | * if needed. |
| 7130 | */ |
| 7131 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 7132 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7133 | Uid u = getUidStatsLocked(uid); |
| 7134 | return u.getServiceStatsLocked(pkg, name); |
| 7135 | } |
| 7136 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7137 | /** |
| 7138 | * Massage data to distribute any reasonable work down to more specific |
| 7139 | * owners. Must only be called on a dead BatteryStats object! |
| 7140 | */ |
| 7141 | public void distributeWorkLocked(int which) { |
| 7142 | // Aggregate all CPU time associated with WIFI. |
| 7143 | Uid wifiUid = mUidStats.get(Process.WIFI_UID); |
| 7144 | if (wifiUid != null) { |
| 7145 | long uSecTime = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7146 | for (int ip=wifiUid.mProcessStats.size()-1; ip>=0; ip--) { |
| 7147 | Uid.Proc proc = wifiUid.mProcessStats.valueAt(ip); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7148 | long totalRunningTime = getGlobalWifiRunningTime(uSecTime, which); |
| 7149 | for (int i=0; i<mUidStats.size(); i++) { |
| 7150 | Uid uid = mUidStats.valueAt(i); |
| 7151 | if (uid.mUid != Process.WIFI_UID) { |
| 7152 | long uidRunningTime = uid.getWifiRunningTime(uSecTime, which); |
| 7153 | if (uidRunningTime > 0) { |
| 7154 | Uid.Proc uidProc = uid.getProcessStatsLocked("*wifi*"); |
| 7155 | long time = proc.getUserTime(which); |
| 7156 | time = (time*uidRunningTime)/totalRunningTime; |
| 7157 | uidProc.mUserTime += time; |
| 7158 | proc.mUserTime -= time; |
| 7159 | time = proc.getSystemTime(which); |
| 7160 | time = (time*uidRunningTime)/totalRunningTime; |
| 7161 | uidProc.mSystemTime += time; |
| 7162 | proc.mSystemTime -= time; |
| 7163 | time = proc.getForegroundTime(which); |
| 7164 | time = (time*uidRunningTime)/totalRunningTime; |
| 7165 | uidProc.mForegroundTime += time; |
| 7166 | proc.mForegroundTime -= time; |
| 7167 | for (int sb=0; sb<proc.mSpeedBins.length; sb++) { |
| 7168 | SamplingCounter sc = proc.mSpeedBins[sb]; |
| 7169 | if (sc != null) { |
| 7170 | time = sc.getCountLocked(which); |
| 7171 | time = (time*uidRunningTime)/totalRunningTime; |
| 7172 | SamplingCounter uidSc = uidProc.mSpeedBins[sb]; |
| 7173 | if (uidSc == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7174 | uidSc = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7175 | uidProc.mSpeedBins[sb] = uidSc; |
| 7176 | } |
| 7177 | uidSc.mCount.addAndGet((int)time); |
| 7178 | sc.mCount.addAndGet((int)-time); |
| 7179 | } |
| 7180 | } |
| 7181 | totalRunningTime -= uidRunningTime; |
| 7182 | } |
| 7183 | } |
| 7184 | } |
| 7185 | } |
| 7186 | } |
| 7187 | } |
| 7188 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7189 | public void shutdownLocked() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7190 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7191 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7192 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7193 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7194 | Parcel mPendingWrite = null; |
| 7195 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 7196 | |
| 7197 | public void writeAsyncLocked() { |
| 7198 | writeLocked(false); |
| 7199 | } |
| 7200 | |
| 7201 | public void writeSyncLocked() { |
| 7202 | writeLocked(true); |
| 7203 | } |
| 7204 | |
| 7205 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7206 | if (mFile == null) { |
| 7207 | 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] | 7208 | return; |
| 7209 | } |
| 7210 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7211 | if (mShuttingDown) { |
| 7212 | return; |
| 7213 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7214 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7215 | Parcel out = Parcel.obtain(); |
| 7216 | writeSummaryToParcel(out); |
| 7217 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 7218 | |
| 7219 | if (mPendingWrite != null) { |
| 7220 | mPendingWrite.recycle(); |
| 7221 | } |
| 7222 | mPendingWrite = out; |
| 7223 | |
| 7224 | if (sync) { |
| 7225 | commitPendingDataToDisk(); |
| 7226 | } else { |
| 7227 | Thread thr = new Thread("BatteryStats-Write") { |
| 7228 | @Override |
| 7229 | public void run() { |
| 7230 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 7231 | commitPendingDataToDisk(); |
| 7232 | } |
| 7233 | }; |
| 7234 | thr.start(); |
| 7235 | } |
| 7236 | } |
| 7237 | |
| 7238 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 7239 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7240 | synchronized (this) { |
| 7241 | next = mPendingWrite; |
| 7242 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 7243 | if (next == null) { |
| 7244 | return; |
| 7245 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7246 | |
| 7247 | mWriteLock.lock(); |
| 7248 | } |
| 7249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7250 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7251 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7252 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7253 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 7254 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7255 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7256 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7257 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7258 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7259 | mFile.rollback(); |
| 7260 | } finally { |
| 7261 | next.recycle(); |
| 7262 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 7263 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | } |
| 7265 | |
| 7266 | static byte[] readFully(FileInputStream stream) throws java.io.IOException { |
| 7267 | int pos = 0; |
| 7268 | int avail = stream.available(); |
| 7269 | byte[] data = new byte[avail]; |
| 7270 | while (true) { |
| 7271 | int amt = stream.read(data, pos, data.length-pos); |
| 7272 | //Log.i("foo", "Read " + amt + " bytes at " + pos |
| 7273 | // + " of avail " + data.length); |
| 7274 | if (amt <= 0) { |
| 7275 | //Log.i("foo", "**** FINISHED READING: pos=" + pos |
| 7276 | // + " len=" + data.length); |
| 7277 | return data; |
| 7278 | } |
| 7279 | pos += amt; |
| 7280 | avail = stream.available(); |
| 7281 | if (avail > data.length-pos) { |
| 7282 | byte[] newData = new byte[pos+avail]; |
| 7283 | System.arraycopy(data, 0, newData, 0, pos); |
| 7284 | data = newData; |
| 7285 | } |
| 7286 | } |
| 7287 | } |
| 7288 | |
| 7289 | public void readLocked() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7290 | if (mFile == null) { |
| 7291 | 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] | 7292 | return; |
| 7293 | } |
| 7294 | |
| 7295 | mUidStats.clear(); |
| 7296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7297 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7298 | File file = mFile.chooseForRead(); |
| 7299 | if (!file.exists()) { |
| 7300 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7302 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | |
| 7304 | byte[] raw = readFully(stream); |
| 7305 | Parcel in = Parcel.obtain(); |
| 7306 | in.unmarshall(raw, 0, raw.length); |
| 7307 | in.setDataPosition(0); |
| 7308 | stream.close(); |
| 7309 | |
| 7310 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 7311 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7312 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7314 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7315 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7316 | mRecordingHistory = true; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7317 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 7318 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7319 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7320 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7321 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7322 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 7323 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 7324 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | } |
| 7326 | |
| 7327 | public int describeContents() { |
| 7328 | return 0; |
| 7329 | } |
| 7330 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7331 | void readHistory(Parcel in, boolean andOldHistory) { |
| 7332 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7333 | |
| 7334 | mHistoryBuffer.setDataSize(0); |
| 7335 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7336 | mHistoryTagPool.clear(); |
| 7337 | mNextHistoryTagIdx = 0; |
| 7338 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7339 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7340 | int numTags = in.readInt(); |
| 7341 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7342 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7343 | String str = in.readString(); |
| 7344 | int uid = in.readInt(); |
| 7345 | HistoryTag tag = new HistoryTag(); |
| 7346 | tag.string = str; |
| 7347 | tag.uid = uid; |
| 7348 | tag.poolIdx = idx; |
| 7349 | mHistoryTagPool.put(tag, idx); |
| 7350 | if (idx >= mNextHistoryTagIdx) { |
| 7351 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7352 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7353 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7354 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7355 | |
| 7356 | int bufSize = in.readInt(); |
| 7357 | int curPos = in.dataPosition(); |
| 7358 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
| 7359 | Slog.w(TAG, "File corrupt: history data buffer too large " + bufSize); |
| 7360 | } else if ((bufSize&~3) != bufSize) { |
| 7361 | Slog.w(TAG, "File corrupt: history data buffer not aligned " + bufSize); |
| 7362 | } else { |
| 7363 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 7364 | + " bytes at " + curPos); |
| 7365 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 7366 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7367 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7368 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7369 | if (andOldHistory) { |
| 7370 | readOldHistory(in); |
| 7371 | } |
| 7372 | |
| 7373 | if (DEBUG_HISTORY) { |
| 7374 | StringBuilder sb = new StringBuilder(128); |
| 7375 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 7376 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 7377 | Slog.i(TAG, sb.toString()); |
| 7378 | } |
| 7379 | mHistoryBaseTime = historyBaseTime; |
| 7380 | if (DEBUG_HISTORY) { |
| 7381 | StringBuilder sb = new StringBuilder(128); |
| 7382 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 7383 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 7384 | Slog.i(TAG, sb.toString()); |
| 7385 | } |
| 7386 | |
| 7387 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 7388 | // the last run until samples in this run. |
| 7389 | if (mHistoryBaseTime > 0) { |
| 7390 | long oldnow = SystemClock.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7391 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7392 | if (DEBUG_HISTORY) { |
| 7393 | StringBuilder sb = new StringBuilder(128); |
| 7394 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 7395 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 7396 | Slog.i(TAG, sb.toString()); |
| 7397 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 7398 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7399 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7400 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7401 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 7402 | if (!USE_OLD_HISTORY) { |
| 7403 | return; |
| 7404 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7405 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 7406 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 7407 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7408 | HistoryItem rec = new HistoryItem(time, in); |
| 7409 | addHistoryRecordLocked(rec); |
| 7410 | } |
| 7411 | } |
| 7412 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7413 | void writeHistory(Parcel out, boolean andOldHistory) { |
| 7414 | if (DEBUG_HISTORY) { |
| 7415 | StringBuilder sb = new StringBuilder(128); |
| 7416 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 7417 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7418 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 7419 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7420 | Slog.i(TAG, sb.toString()); |
| 7421 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7422 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7423 | out.writeInt(mHistoryTagPool.size()); |
| 7424 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7425 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7426 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7427 | out.writeString(tag.string); |
| 7428 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7429 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7430 | out.writeInt(mHistoryBuffer.dataSize()); |
| 7431 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 7432 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 7433 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7434 | |
| 7435 | if (andOldHistory) { |
| 7436 | writeOldHistory(out); |
| 7437 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 7441 | if (!USE_OLD_HISTORY) { |
| 7442 | return; |
| 7443 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7444 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7445 | while (rec != null) { |
| 7446 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 7447 | rec = rec.next; |
| 7448 | } |
| 7449 | out.writeLong(-1); |
| 7450 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | private void readSummaryFromParcel(Parcel in) { |
| 7453 | final int version = in.readInt(); |
| 7454 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7455 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | + ", expected " + VERSION + "; erasing old stats"); |
| 7457 | return; |
| 7458 | } |
| 7459 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7460 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7462 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7463 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7465 | mStartClockTime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7466 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 7467 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7468 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7469 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7470 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7471 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7472 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 7473 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7474 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 7475 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7476 | mNumDischargeStepDurations = in.readInt(); |
| 7477 | in.readLongArray(mDischargeStepDurations); |
| 7478 | mNumChargeStepDurations = in.readInt(); |
| 7479 | in.readLongArray(mChargeStepDurations); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7482 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7483 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7484 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7485 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 7486 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 7487 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7488 | mInteractive = false; |
| 7489 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7490 | mPhoneOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7491 | mLowPowerModeEnabledTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7492 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7493 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7494 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 7495 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7496 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7497 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 7498 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 7499 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7500 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7501 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 7502 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7503 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7504 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7505 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7506 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7507 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7508 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 7509 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7510 | mWifiOn = false; |
| 7511 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7512 | mGlobalWifiRunning = false; |
| 7513 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7514 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 7515 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 7516 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7517 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7518 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 7519 | } |
| 7520 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7521 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 7522 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7523 | mBluetoothOn = false; |
| 7524 | mBluetoothOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7525 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 7526 | mBluetoothStateTimer[i].readSummaryFromParcelLocked(in); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7527 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 7528 | mFlashlightOn = false; |
| 7529 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7531 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7532 | if (NKW > 10000) { |
| 7533 | Slog.w(TAG, "File corrupt: too many kernel wake locks " + NKW); |
| 7534 | return; |
| 7535 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7536 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 7537 | if (in.readInt() != 0) { |
| 7538 | String kwltName = in.readString(); |
| 7539 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 7540 | } |
| 7541 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7542 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7543 | int NWR = in.readInt(); |
| 7544 | if (NWR > 10000) { |
| 7545 | Slog.w(TAG, "File corrupt: too many wakeup reasons " + NWR); |
| 7546 | return; |
| 7547 | } |
| 7548 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 7549 | if (in.readInt() != 0) { |
| 7550 | String reasonName = in.readString(); |
| 7551 | getWakeupReasonCounterLocked(reasonName).readSummaryFromParcelLocked(in); |
| 7552 | } |
| 7553 | } |
| 7554 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7555 | sNumSpeedSteps = in.readInt(); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 7556 | if (sNumSpeedSteps < 0 || sNumSpeedSteps > 100) { |
| 7557 | throw new BadParcelableException("Bad speed steps in data: " + sNumSpeedSteps); |
| 7558 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7561 | if (NU > 10000) { |
| 7562 | Slog.w(TAG, "File corrupt: too many uids " + NU); |
| 7563 | return; |
| 7564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | for (int iu = 0; iu < NU; iu++) { |
| 7566 | int uid = in.readInt(); |
| 7567 | Uid u = new Uid(uid); |
| 7568 | mUidStats.put(uid, u); |
| 7569 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7570 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7571 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7572 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7573 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7574 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7575 | if (in.readInt() != 0) { |
| 7576 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 7577 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7578 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7579 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7580 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7581 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7582 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 7583 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7584 | if (in.readInt() != 0) { |
| 7585 | u.makeWifiBatchedScanBin(i, null); |
| 7586 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 7587 | } |
| 7588 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7589 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7590 | if (in.readInt() != 0) { |
| 7591 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 7592 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7593 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7594 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7595 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7596 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7597 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 7598 | } |
| 7599 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7600 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 7601 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7602 | u.mProcessState = Uid.PROCESS_STATE_NONE; |
| 7603 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 7604 | if (in.readInt() != 0) { |
| 7605 | u.makeProcessState(i, null); |
| 7606 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 7607 | } |
| 7608 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7609 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7610 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7611 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7612 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7613 | if (in.readInt() != 0) { |
| 7614 | if (u.mUserActivityCounters == null) { |
| 7615 | u.initUserActivityLocked(); |
| 7616 | } |
| 7617 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 7618 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 7619 | } |
| 7620 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7621 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7622 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7623 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7624 | u.initNetworkActivityLocked(); |
| 7625 | } |
| 7626 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7627 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 7628 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7629 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7630 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 7631 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7632 | } |
| 7633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7634 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7635 | if (NW > 100) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7636 | Slog.w(TAG, "File corrupt: too many wake locks " + NW); |
| 7637 | return; |
| 7638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | for (int iw = 0; iw < NW; iw++) { |
| 7640 | String wlName = in.readString(); |
| 7641 | if (in.readInt() != 0) { |
| 7642 | u.getWakeTimerLocked(wlName, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
| 7643 | } |
| 7644 | if (in.readInt() != 0) { |
| 7645 | u.getWakeTimerLocked(wlName, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7646 | } |
| 7647 | if (in.readInt() != 0) { |
| 7648 | u.getWakeTimerLocked(wlName, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
| 7649 | } |
| 7650 | } |
| 7651 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7652 | int NS = in.readInt(); |
| 7653 | if (NS > 100) { |
| 7654 | Slog.w(TAG, "File corrupt: too many syncs " + NS); |
| 7655 | return; |
| 7656 | } |
| 7657 | for (int is = 0; is < NS; is++) { |
| 7658 | String name = in.readString(); |
| 7659 | u.getSyncTimerLocked(name).readSummaryFromParcelLocked(in); |
| 7660 | } |
| 7661 | |
| 7662 | int NJ = in.readInt(); |
| 7663 | if (NJ > 100) { |
| 7664 | Slog.w(TAG, "File corrupt: too many job timers " + NJ); |
| 7665 | return; |
| 7666 | } |
| 7667 | for (int ij = 0; ij < NJ; ij++) { |
| 7668 | String name = in.readString(); |
| 7669 | u.getJobTimerLocked(name).readSummaryFromParcelLocked(in); |
| 7670 | } |
| 7671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7672 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7673 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7674 | Slog.w(TAG, "File corrupt: too many sensors " + NP); |
| 7675 | return; |
| 7676 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7677 | for (int is = 0; is < NP; is++) { |
| 7678 | int seNumber = in.readInt(); |
| 7679 | if (in.readInt() != 0) { |
| 7680 | u.getSensorTimerLocked(seNumber, true) |
| 7681 | .readSummaryFromParcelLocked(in); |
| 7682 | } |
| 7683 | } |
| 7684 | |
| 7685 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7686 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7687 | Slog.w(TAG, "File corrupt: too many processes " + NP); |
| 7688 | return; |
| 7689 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | for (int ip = 0; ip < NP; ip++) { |
| 7691 | String procName = in.readString(); |
| 7692 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 7693 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7695 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7696 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7697 | int NSB = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7698 | if (NSB > 100) { |
| 7699 | Slog.w(TAG, "File corrupt: too many speed bins " + NSB); |
| 7700 | return; |
| 7701 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7702 | p.mSpeedBins = new SamplingCounter[NSB]; |
| 7703 | for (int i=0; i<NSB; i++) { |
| 7704 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7705 | p.mSpeedBins[i] = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7706 | p.mSpeedBins[i].readSummaryFromParcelLocked(in); |
| 7707 | } |
| 7708 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7709 | if (!p.readExcessivePowerFromParcelLocked(in)) { |
| 7710 | return; |
| 7711 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | } |
| 7713 | |
| 7714 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7715 | if (NP > 10000) { |
| 7716 | Slog.w(TAG, "File corrupt: too many packages " + NP); |
| 7717 | return; |
| 7718 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | for (int ip = 0; ip < NP; ip++) { |
| 7720 | String pkgName = in.readString(); |
| 7721 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
| 7722 | p.mWakeups = p.mLoadedWakeups = in.readInt(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7723 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7724 | if (NS > 1000) { |
| 7725 | Slog.w(TAG, "File corrupt: too many services " + NS); |
| 7726 | return; |
| 7727 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | for (int is = 0; is < NS; is++) { |
| 7729 | String servName = in.readString(); |
| 7730 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 7731 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7733 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7734 | } |
| 7735 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7736 | } |
| 7737 | } |
| 7738 | |
| 7739 | /** |
| 7740 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 7741 | * disk. This format does not allow a lossless round-trip. |
| 7742 | * |
| 7743 | * @param out the Parcel to be written to. |
| 7744 | */ |
| 7745 | public void writeSummaryToParcel(Parcel out) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7746 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7748 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 7749 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | |
| 7751 | out.writeInt(VERSION); |
| 7752 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7753 | writeHistory(out, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7755 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7756 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7757 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7758 | out.writeLong(mStartClockTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7759 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 7760 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7761 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7762 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7763 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7764 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7765 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 7766 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7767 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 7768 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7769 | out.writeInt(mNumDischargeStepDurations); |
| 7770 | out.writeLongArray(mDischargeStepDurations); |
| 7771 | out.writeInt(mNumChargeStepDurations); |
| 7772 | out.writeLongArray(mChargeStepDurations); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7773 | |
| 7774 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7775 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7776 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7777 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7778 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7779 | mLowPowerModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7780 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7781 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7782 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7783 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7784 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7785 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7786 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7787 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7788 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7789 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 7790 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7791 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7792 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7793 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7794 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7795 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 7796 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7797 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7798 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7799 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7800 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7801 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7802 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7803 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7804 | } |
| 7805 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7806 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7807 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7808 | mBluetoothOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7809 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7810 | mBluetoothStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7811 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 7812 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7813 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7814 | out.writeInt(mKernelWakelockStats.size()); |
| 7815 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 7816 | Timer kwlt = ent.getValue(); |
| 7817 | if (kwlt != null) { |
| 7818 | out.writeInt(1); |
| 7819 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7820 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7821 | } else { |
| 7822 | out.writeInt(0); |
| 7823 | } |
| 7824 | } |
| 7825 | |
| 7826 | out.writeInt(mWakeupReasonStats.size()); |
| 7827 | for (Map.Entry<String, LongSamplingCounter> ent : mWakeupReasonStats.entrySet()) { |
| 7828 | LongSamplingCounter counter = ent.getValue(); |
| 7829 | if (counter != null) { |
| 7830 | out.writeInt(1); |
| 7831 | out.writeString(ent.getKey()); |
| 7832 | counter.writeSummaryFromParcelLocked(out); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7833 | } else { |
| 7834 | out.writeInt(0); |
| 7835 | } |
| 7836 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7837 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7838 | out.writeInt(sNumSpeedSteps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7839 | final int NU = mUidStats.size(); |
| 7840 | out.writeInt(NU); |
| 7841 | for (int iu = 0; iu < NU; iu++) { |
| 7842 | out.writeInt(mUidStats.keyAt(iu)); |
| 7843 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7844 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7845 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7846 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7847 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7848 | } else { |
| 7849 | out.writeInt(0); |
| 7850 | } |
| 7851 | if (u.mFullWifiLockTimer != null) { |
| 7852 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7853 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7854 | } else { |
| 7855 | out.writeInt(0); |
| 7856 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7857 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7858 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7859 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7860 | } else { |
| 7861 | out.writeInt(0); |
| 7862 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7863 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7864 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 7865 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7866 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7867 | } else { |
| 7868 | out.writeInt(0); |
| 7869 | } |
| 7870 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7871 | if (u.mWifiMulticastTimer != null) { |
| 7872 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7873 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7874 | } else { |
| 7875 | out.writeInt(0); |
| 7876 | } |
| 7877 | if (u.mAudioTurnedOnTimer != null) { |
| 7878 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7879 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7880 | } else { |
| 7881 | out.writeInt(0); |
| 7882 | } |
| 7883 | if (u.mVideoTurnedOnTimer != null) { |
| 7884 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7885 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7886 | } else { |
| 7887 | out.writeInt(0); |
| 7888 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7889 | if (u.mForegroundActivityTimer != null) { |
| 7890 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7891 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7892 | } else { |
| 7893 | out.writeInt(0); |
| 7894 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7895 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 7896 | if (u.mProcessStateTimer[i] != null) { |
| 7897 | out.writeInt(1); |
| 7898 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7899 | } else { |
| 7900 | out.writeInt(0); |
| 7901 | } |
| 7902 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7903 | if (u.mVibratorOnTimer != null) { |
| 7904 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7905 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7906 | } else { |
| 7907 | out.writeInt(0); |
| 7908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7909 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7910 | if (u.mUserActivityCounters == null) { |
| 7911 | out.writeInt(0); |
| 7912 | } else { |
| 7913 | out.writeInt(1); |
| 7914 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 7915 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 7916 | } |
| 7917 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7918 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7919 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7920 | out.writeInt(0); |
| 7921 | } else { |
| 7922 | out.writeInt(1); |
| 7923 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7924 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 7925 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7926 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7927 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 7928 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7929 | } |
| 7930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7931 | int NW = u.mWakelockStats.size(); |
| 7932 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7933 | for (int iw=0; iw<NW; iw++) { |
| 7934 | out.writeString(u.mWakelockStats.keyAt(iw)); |
| 7935 | Uid.Wakelock wl = u.mWakelockStats.valueAt(iw); |
| 7936 | if (wl.mTimerFull != null) { |
| 7937 | out.writeInt(1); |
| 7938 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7939 | } else { |
| 7940 | out.writeInt(0); |
| 7941 | } |
| 7942 | if (wl.mTimerPartial != null) { |
| 7943 | out.writeInt(1); |
| 7944 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7945 | } else { |
| 7946 | out.writeInt(0); |
| 7947 | } |
| 7948 | if (wl.mTimerWindow != null) { |
| 7949 | out.writeInt(1); |
| 7950 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7951 | } else { |
| 7952 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | } |
| 7954 | } |
| 7955 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7956 | int NS = u.mSyncStats.size(); |
| 7957 | out.writeInt(NS); |
| 7958 | for (int is=0; is<NS; is++) { |
| 7959 | out.writeString(u.mSyncStats.keyAt(is)); |
| 7960 | u.mSyncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7961 | } |
| 7962 | |
| 7963 | int NJ = u.mJobStats.size(); |
| 7964 | out.writeInt(NJ); |
| 7965 | for (int ij=0; ij<NJ; ij++) { |
| 7966 | out.writeString(u.mJobStats.keyAt(ij)); |
| 7967 | u.mJobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7968 | } |
| 7969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7970 | int NSE = u.mSensorStats.size(); |
| 7971 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7972 | for (int ise=0; ise<NSE; ise++) { |
| 7973 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 7974 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 7975 | if (se.mTimer != null) { |
| 7976 | out.writeInt(1); |
| 7977 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7978 | } else { |
| 7979 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | } |
| 7981 | } |
| 7982 | |
| 7983 | int NP = u.mProcessStats.size(); |
| 7984 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7985 | for (int ip=0; ip<NP; ip++) { |
| 7986 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 7987 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 7988 | out.writeLong(ps.mUserTime); |
| 7989 | out.writeLong(ps.mSystemTime); |
| 7990 | out.writeLong(ps.mForegroundTime); |
| 7991 | out.writeInt(ps.mStarts); |
| 7992 | final int N = ps.mSpeedBins.length; |
| 7993 | out.writeInt(N); |
| 7994 | for (int i=0; i<N; i++) { |
| 7995 | if (ps.mSpeedBins[i] != null) { |
| 7996 | out.writeInt(1); |
| 7997 | ps.mSpeedBins[i].writeSummaryFromParcelLocked(out); |
| 7998 | } else { |
| 7999 | out.writeInt(0); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8000 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8002 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | NP = u.mPackageStats.size(); |
| 8006 | out.writeInt(NP); |
| 8007 | if (NP > 0) { |
| 8008 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 8009 | : u.mPackageStats.entrySet()) { |
| 8010 | out.writeString(ent.getKey()); |
| 8011 | Uid.Pkg ps = ent.getValue(); |
| 8012 | out.writeInt(ps.mWakeups); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8013 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8014 | out.writeInt(NS); |
| 8015 | if (NS > 0) { |
| 8016 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg.Serv> sent |
| 8017 | : ps.mServiceStats.entrySet()) { |
| 8018 | out.writeString(sent.getKey()); |
| 8019 | BatteryStatsImpl.Uid.Pkg.Serv ss = sent.getValue(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8020 | long time = ss.getStartTimeToNowLocked( |
| 8021 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8022 | out.writeLong(time); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8023 | out.writeInt(ss.mStarts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8024 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | } |
| 8026 | } |
| 8027 | } |
| 8028 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8029 | } |
| 8030 | } |
| 8031 | |
| 8032 | public void readFromParcel(Parcel in) { |
| 8033 | readFromParcelLocked(in); |
| 8034 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | void readFromParcelLocked(Parcel in) { |
| 8037 | int magic = in.readInt(); |
| 8038 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8039 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8040 | } |
| 8041 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8042 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8044 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8045 | mStartClockTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8046 | mUptime = in.readLong(); |
| 8047 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | mRealtime = in.readLong(); |
| 8049 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8050 | mOnBattery = in.readInt() != 0; |
| 8051 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8052 | mOnBatteryTimeBase.readFromParcel(in); |
| 8053 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 8054 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8055 | mScreenState = Display.STATE_UNKNOWN; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8056 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in); |
| 8057 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 8058 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, |
| 8059 | in); |
| 8060 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8061 | mInteractive = false; |
| 8062 | mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8063 | mPhoneOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8064 | mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in); |
| 8065 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8066 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 8067 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 8068 | null, mOnBatteryTimeBase, in); |
| 8069 | } |
| 8070 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase, in); |
| 8071 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 8072 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 8073 | null, mOnBatteryTimeBase, in); |
| 8074 | } |
| 8075 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 8076 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 8077 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 8078 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8079 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8080 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); |
| 8081 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, |
| 8082 | in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8083 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8084 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 8085 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 8086 | mWifiOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8087 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8088 | mGlobalWifiRunning = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8089 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8090 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 8091 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, |
| 8092 | null, mOnBatteryTimeBase, in); |
| 8093 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8094 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8095 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, |
| 8096 | null, mOnBatteryTimeBase, in); |
| 8097 | } |
| 8098 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8099 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, |
| 8100 | null, mOnBatteryTimeBase, in); |
| 8101 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8102 | mBluetoothOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8103 | mBluetoothOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8104 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 8105 | mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, |
| 8106 | null, mOnBatteryTimeBase, in); |
| 8107 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 8108 | mAudioOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8109 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 8110 | mVideoOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8111 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8112 | mFlashlightOn = false; |
| 8113 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8114 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8115 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8116 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8117 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8118 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 8119 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8120 | mDischargeAmountScreenOn = in.readInt(); |
| 8121 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 8122 | mDischargeAmountScreenOff = in.readInt(); |
| 8123 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8124 | mNumDischargeStepDurations = in.readInt(); |
| 8125 | in.readLongArray(mDischargeStepDurations); |
| 8126 | mNumChargeStepDurations = in.readInt(); |
| 8127 | in.readLongArray(mChargeStepDurations); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | mLastWriteTime = in.readLong(); |
| 8129 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 8130 | mBluetoothPingCount = in.readInt(); |
| 8131 | mBluetoothPingStart = -1; |
| 8132 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8133 | mKernelWakelockStats.clear(); |
| 8134 | int NKW = in.readInt(); |
| 8135 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 8136 | if (in.readInt() != 0) { |
| 8137 | String wakelockName = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8138 | SamplingTimer kwlt = new SamplingTimer(mOnBatteryTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8139 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 8140 | } |
| 8141 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8142 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8143 | mWakeupReasonStats.clear(); |
| 8144 | int NWR = in.readInt(); |
| 8145 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 8146 | if (in.readInt() != 0) { |
| 8147 | String reasonName = in.readString(); |
| 8148 | LongSamplingCounter counter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, |
| 8149 | in); |
| 8150 | mWakeupReasonStats.put(reasonName, counter); |
| 8151 | } |
| 8152 | } |
| 8153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8154 | mPartialTimers.clear(); |
| 8155 | mFullTimers.clear(); |
| 8156 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8157 | mWifiRunningTimers.clear(); |
| 8158 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8159 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8160 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8161 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame^] | 8162 | mAudioTurnedOnTimers.clear(); |
| 8163 | mVideoTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8165 | sNumSpeedSteps = in.readInt(); |
| 8166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8167 | int numUids = in.readInt(); |
| 8168 | mUidStats.clear(); |
| 8169 | for (int i = 0; i < numUids; i++) { |
| 8170 | int uid = in.readInt(); |
| 8171 | Uid u = new Uid(uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8172 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | mUidStats.append(uid, u); |
| 8174 | } |
| 8175 | } |
| 8176 | |
| 8177 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8178 | writeToParcelLocked(out, true, flags); |
| 8179 | } |
| 8180 | |
| 8181 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 8182 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8183 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8184 | |
| 8185 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8186 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8187 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8188 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8190 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 8191 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8192 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 8193 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8195 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8196 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8197 | writeHistory(out, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | out.writeInt(mStartCount); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8200 | out.writeLong(mStartClockTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | out.writeLong(mUptime); |
| 8202 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8203 | out.writeLong(mRealtime); |
| 8204 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8205 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8206 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 8207 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 8208 | |
| 8209 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 8210 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 8211 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 8212 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8213 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8214 | mLowPowerModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8215 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 8216 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 8217 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 8218 | } |
| 8219 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 8220 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 8221 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 8222 | } |
| 8223 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 8224 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 8225 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 8226 | } |
| 8227 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 8228 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8229 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8230 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 8231 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 8232 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 8233 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 8234 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 8235 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 8236 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8237 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8238 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 8239 | } |
| 8240 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8241 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 8242 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8243 | mBluetoothOnTimer.writeToParcel(out, uSecRealtime); |
| 8244 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 8245 | mBluetoothStateTimer[i].writeToParcel(out, uSecRealtime); |
| 8246 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8247 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8248 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8249 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8250 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8251 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8252 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 8253 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8254 | out.writeInt(mDischargeAmountScreenOn); |
| 8255 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 8256 | out.writeInt(mDischargeAmountScreenOff); |
| 8257 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8258 | out.writeInt(mNumDischargeStepDurations); |
| 8259 | out.writeLongArray(mDischargeStepDurations); |
| 8260 | out.writeInt(mNumChargeStepDurations); |
| 8261 | out.writeLongArray(mChargeStepDurations); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | out.writeLong(mLastWriteTime); |
| 8263 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 8264 | out.writeInt(getBluetoothPingCount()); |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 8265 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8266 | if (inclUids) { |
| 8267 | out.writeInt(mKernelWakelockStats.size()); |
| 8268 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 8269 | SamplingTimer kwlt = ent.getValue(); |
| 8270 | if (kwlt != null) { |
| 8271 | out.writeInt(1); |
| 8272 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8273 | kwlt.writeToParcel(out, uSecRealtime); |
| 8274 | } else { |
| 8275 | out.writeInt(0); |
| 8276 | } |
| 8277 | } |
| 8278 | out.writeInt(mWakeupReasonStats.size()); |
| 8279 | for (Map.Entry<String, LongSamplingCounter> ent : mWakeupReasonStats.entrySet()) { |
| 8280 | LongSamplingCounter counter = ent.getValue(); |
| 8281 | if (counter != null) { |
| 8282 | out.writeInt(1); |
| 8283 | out.writeString(ent.getKey()); |
| 8284 | counter.writeToParcel(out); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8285 | } else { |
| 8286 | out.writeInt(0); |
| 8287 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8288 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8289 | } else { |
| 8290 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8291 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8292 | |
| 8293 | out.writeInt(sNumSpeedSteps); |
| 8294 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8295 | if (inclUids) { |
| 8296 | int size = mUidStats.size(); |
| 8297 | out.writeInt(size); |
| 8298 | for (int i = 0; i < size; i++) { |
| 8299 | out.writeInt(mUidStats.keyAt(i)); |
| 8300 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8301 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8302 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8303 | } |
| 8304 | } else { |
| 8305 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8306 | } |
| 8307 | } |
| 8308 | |
| 8309 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 8310 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 8311 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 8312 | return new BatteryStatsImpl(in); |
| 8313 | } |
| 8314 | |
| 8315 | public BatteryStatsImpl[] newArray(int size) { |
| 8316 | return new BatteryStatsImpl[size]; |
| 8317 | } |
| 8318 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8319 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8320 | public void prepareForDumpLocked() { |
| 8321 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8322 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8323 | } |
| 8324 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 8325 | 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] | 8326 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8327 | pw.println("mOnBatteryTimeBase:"); |
| 8328 | mOnBatteryTimeBase.dump(pw, " "); |
| 8329 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 8330 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8331 | Printer pr = new PrintWriterPrinter(pw); |
| 8332 | pr.println("*** Screen timer:"); |
| 8333 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8334 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8335 | pr.println("*** Screen brightness #" + i + ":"); |
| 8336 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8337 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8338 | pr.println("*** Interactive timer:"); |
| 8339 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 8340 | pr.println("*** Low power mode timer:"); |
| 8341 | mLowPowerModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8342 | pr.println("*** Phone timer:"); |
| 8343 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8344 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8345 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8346 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8347 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8348 | pr.println("*** Signal scanning :"); |
| 8349 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8350 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8351 | pr.println("*** Data connection type #" + i + ":"); |
| 8352 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8353 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8354 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 8355 | pr.println("*** Mobile network active timer:"); |
| 8356 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8357 | pr.println("*** Mobile network active adjusted timer:"); |
| 8358 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8359 | pr.println("*** Wifi timer:"); |
| 8360 | mWifiOnTimer.logState(pr, " "); |
| 8361 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8362 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8363 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 8364 | pr.println("*** Wifi state #" + i + ":"); |
| 8365 | mWifiStateTimer[i].logState(pr, " "); |
| 8366 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8367 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8368 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 8369 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 8370 | } |
| 8371 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8372 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 8373 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 8374 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8375 | pr.println("*** Bluetooth timer:"); |
| 8376 | mBluetoothOnTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8377 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 8378 | pr.println("*** Bluetooth active type #" + i + ":"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8379 | mBluetoothStateTimer[i].logState(pr, " "); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 8380 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8381 | pr.println("*** Flashlight timer:"); |
| 8382 | mFlashlightOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8383 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 8384 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8385 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8386 | } |