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 | |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothDevice; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothHeadset; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 25 | import android.net.ConnectivityManager; |
| 26 | import android.net.NetworkStats; |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 27 | import android.os.BadParcelableException; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 28 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.BatteryStats; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 30 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 32 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 33 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.os.Parcel; |
| 35 | import android.os.ParcelFormatException; |
| 36 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 37 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 39 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 40 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 41 | import android.telephony.DataConnectionRealTimeInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 42 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 43 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 44 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 46 | import android.util.LogWriter; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 47 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 49 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 51 | import android.util.SparseIntArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 52 | import android.util.TimeUtils; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 53 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 55 | import com.android.internal.annotations.GuardedBy; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 56 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 57 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 58 | import com.android.internal.util.FastPrintWriter; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 59 | import com.android.internal.util.JournaledFile; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 60 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import java.io.File; |
| 62 | import java.io.FileInputStream; |
| 63 | import java.io.FileOutputStream; |
| 64 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 65 | import java.io.PrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import java.util.ArrayList; |
| 67 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 68 | import java.util.Iterator; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 69 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 71 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 72 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * All information we are collecting about things that can happen that impact |
| 76 | * battery life. All times are represented in microseconds except where indicated |
| 77 | * otherwise. |
| 78 | */ |
| 79 | public final class BatteryStatsImpl extends BatteryStats { |
| 80 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 81 | private static final boolean DEBUG = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 82 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 83 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 84 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 85 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | // 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] | 88 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
| 90 | // Current on-disk Parcel version |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 91 | private static final int VERSION = 106 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 92 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 93 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 94 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 95 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 96 | // No, really, THIS is the maximum number of items we will record in the history. |
| 97 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 98 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 99 | // The maximum number of names wakelocks we will keep track of |
| 100 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 101 | // in to one common name. |
Dianne Hackborn | af17baa | 2013-05-09 15:27:47 -0700 | [diff] [blame] | 102 | private static final int MAX_WAKELOCKS_PER_UID = 50; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 103 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 104 | private static final String BATCHED_WAKELOCK_NAME = "*overflow*"; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 105 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 106 | private static int sNumSpeedSteps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 108 | private final JournaledFile mFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 110 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 111 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 112 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 113 | |
| 114 | public interface BatteryCallback { |
| 115 | public void batteryNeedsCpuUpdate(); |
| 116 | public void batteryPowerChanged(boolean onBattery); |
| 117 | } |
| 118 | |
| 119 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 120 | public MyHandler(Looper looper) { |
| 121 | super(looper, null, true); |
| 122 | } |
| 123 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 124 | @Override |
| 125 | public void handleMessage(Message msg) { |
| 126 | BatteryCallback cb = mCallback; |
| 127 | switch (msg.what) { |
| 128 | case MSG_UPDATE_WAKELOCKS: |
| 129 | if (cb != null) { |
| 130 | cb.batteryNeedsCpuUpdate(); |
| 131 | } |
| 132 | break; |
| 133 | case MSG_REPORT_POWER_CHANGE: |
| 134 | if (cb != null) { |
| 135 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 136 | } |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private final MyHandler mHandler; |
| 143 | |
| 144 | private BatteryCallback mCallback; |
| 145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 147 | * Mapping isolated uids to the actual owning app uid. |
| 148 | */ |
| 149 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 150 | |
| 151 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | * The statistics we have collected organized by uids. |
| 153 | */ |
| 154 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 155 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 156 | |
| 157 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 158 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 159 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 160 | // changes. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 161 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<StopwatchTimer>(); |
| 162 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<StopwatchTimer>(); |
| 163 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<StopwatchTimer>(); |
| 164 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers |
| 165 | = new SparseArray<ArrayList<StopwatchTimer>>(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 166 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<StopwatchTimer>(); |
| 167 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<StopwatchTimer>(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 168 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<StopwatchTimer>(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 169 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 170 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = |
| 171 | new SparseArray<ArrayList<StopwatchTimer>>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 173 | // Last partial timers we use for distributing CPU usage. |
| 174 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); |
| 175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | // These are the objects that will want to do something when the device |
| 177 | // is unplugged from power. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 178 | final TimeBase mOnBatteryTimeBase = new TimeBase(); |
| 179 | |
| 180 | // These are the objects that will want to do something when the device |
| 181 | // is unplugged from power *and* the screen is off. |
| 182 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 183 | |
| 184 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 185 | // CPU update, even if we aren't currently running wake locks. |
| 186 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 187 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 188 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 189 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 190 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 191 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 192 | long mHistoryBaseTime; |
| 193 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 194 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 195 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 196 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 197 | static final int MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 198 | static final int MAX_MAX_HISTORY_BUFFER = 144*1024; // 144KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 199 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 200 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 201 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 202 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 203 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 204 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<HistoryTag, Integer>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 205 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 206 | int[] mReadHistoryUids; |
| 207 | int mReadHistoryChars; |
| 208 | int mNextHistoryTagIdx = 0; |
| 209 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 210 | int mHistoryBufferLastPos = -1; |
| 211 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 212 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 213 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 214 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 215 | |
| 216 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 217 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 218 | HistoryItem mHistory; |
| 219 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 220 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 221 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 222 | |
| 223 | private HistoryItem mHistoryIterator; |
| 224 | private boolean mReadOverflow; |
| 225 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | int mStartCount; |
| 228 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 229 | long mStartClockTime; |
| 230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | long mUptime; |
| 232 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | long mRealtime; |
| 234 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 235 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 236 | int mWakeLockNesting; |
| 237 | boolean mWakeLockImportant; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 238 | boolean mRecordAllWakeLocks; |
| 239 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 240 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 241 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 242 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 243 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 244 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 245 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 246 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 247 | boolean mInteractive; |
| 248 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 249 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 250 | boolean mLowPowerModeEnabled; |
| 251 | StopwatchTimer mLowPowerModeEnabledTimer; |
| 252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 254 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 255 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 256 | boolean mAudioOn; |
| 257 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 258 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 259 | boolean mVideoOn; |
| 260 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 261 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 262 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 263 | int mPhoneSignalStrengthBinRaw = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 264 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 265 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 266 | |
| 267 | StopwatchTimer mPhoneSignalScanningTimer; |
| 268 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 269 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 270 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 271 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 272 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 273 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 274 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 275 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 276 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 277 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 278 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 279 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 280 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 281 | boolean mGlobalWifiRunning; |
| 282 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 283 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 284 | int mWifiState = -1; |
| 285 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 286 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 287 | boolean mBluetoothOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 288 | StopwatchTimer mBluetoothOnTimer; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 289 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 290 | int mBluetoothState = -1; |
| 291 | final StopwatchTimer[] mBluetoothStateTimer = new StopwatchTimer[NUM_BLUETOOTH_STATES]; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 292 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 293 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 294 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 295 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 296 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 297 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 298 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 299 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 300 | /** Bluetooth headset object */ |
| 301 | BluetoothHeadset mBtHeadset; |
| 302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | /** |
| 304 | * These provide time bases that discount the time the device is plugged |
| 305 | * in to power. |
| 306 | */ |
| 307 | boolean mOnBattery; |
| 308 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 309 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 310 | /* |
| 311 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 312 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 313 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 314 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 315 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 316 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 317 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 318 | int mLowDischargeAmountSinceCharge; |
| 319 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 320 | int mDischargeScreenOnUnplugLevel; |
| 321 | int mDischargeScreenOffUnplugLevel; |
| 322 | int mDischargeAmountScreenOn; |
| 323 | int mDischargeAmountScreenOnSinceCharge; |
| 324 | int mDischargeAmountScreenOff; |
| 325 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 326 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 327 | static final int MAX_LEVEL_STEPS = 100; |
| 328 | |
| 329 | int mLastDischargeStepLevel; |
| 330 | long mLastDischargeStepTime; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 331 | int mMinDischargeStepLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 332 | int mNumDischargeStepDurations; |
| 333 | final long[] mDischargeStepDurations = new long[MAX_LEVEL_STEPS]; |
| 334 | |
| 335 | int mLastChargeStepLevel; |
| 336 | long mLastChargeStepTime; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 337 | int mMaxChargeStepLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 338 | int mNumChargeStepDurations; |
| 339 | final long[] mChargeStepDurations = new long[MAX_LEVEL_STEPS]; |
| 340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 342 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 343 | private int mBluetoothPingCount; |
| 344 | private int mBluetoothPingStart = -1; |
| 345 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 346 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 347 | private int mPhoneServiceStateRaw = -1; |
| 348 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 349 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 350 | /* |
| 351 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 352 | */ |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 353 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 354 | new HashMap<String, SamplingTimer>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 355 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 356 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 357 | return mKernelWakelockStats; |
| 358 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 359 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 360 | private static int sKernelWakelockUpdateVersion = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 361 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 362 | String mLastWakeupReason = null; |
| 363 | long mLastWakeupUptimeMs = 0; |
| 364 | private final HashMap<String, LongSamplingCounter> mWakeupReasonStats = |
| 365 | new HashMap<String, LongSamplingCounter>(); |
| 366 | |
| 367 | public Map<String, ? extends LongCounter> getWakeupReasonStats() { |
| 368 | return mWakeupReasonStats; |
| 369 | } |
| 370 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 371 | private static final int[] PROC_WAKELOCKS_FORMAT = new int[] { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 372 | Process.PROC_TAB_TERM|Process.PROC_OUT_STRING| // 0: name |
| 373 | Process.PROC_QUOTES, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 374 | Process.PROC_TAB_TERM|Process.PROC_OUT_LONG, // 1: count |
| 375 | Process.PROC_TAB_TERM, |
| 376 | Process.PROC_TAB_TERM, |
| 377 | Process.PROC_TAB_TERM, |
| 378 | Process.PROC_TAB_TERM|Process.PROC_OUT_LONG, // 5: totalTime |
| 379 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 380 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 381 | private static final int[] WAKEUP_SOURCES_FORMAT = new int[] { |
| 382 | Process.PROC_TAB_TERM|Process.PROC_OUT_STRING, // 0: name |
| 383 | Process.PROC_TAB_TERM|Process.PROC_COMBINE| |
| 384 | Process.PROC_OUT_LONG, // 1: count |
| 385 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 386 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 387 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 388 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 389 | Process.PROC_TAB_TERM|Process.PROC_COMBINE |
| 390 | |Process.PROC_OUT_LONG, // 6: totalTime |
| 391 | }; |
| 392 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 393 | private final String[] mProcWakelocksName = new String[3]; |
| 394 | private final long[] mProcWakelocksData = new long[3]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 395 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 396 | /* |
| 397 | * Used as a buffer for reading in data from /proc/wakelocks before it is processed and added |
| 398 | * to mKernelWakelockStats. |
| 399 | */ |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 400 | private final Map<String, KernelWakelockStats> mProcWakelockFileStats = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 401 | new HashMap<String, KernelWakelockStats>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 403 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 404 | private NetworkStats mCurMobileSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
| 405 | private NetworkStats mLastMobileSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
| 406 | private NetworkStats mCurWifiSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
| 407 | private NetworkStats mLastWifiSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 408 | private NetworkStats mTmpNetworkStats; |
| 409 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 410 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 411 | @GuardedBy("this") |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 412 | private String[] mMobileIfaces = new String[0]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 413 | @GuardedBy("this") |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 414 | private String[] mWifiIfaces = new String[0]; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | // For debugging |
| 417 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 418 | mFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 419 | mHandler = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 422 | public static interface TimeBaseObs { |
| 423 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 424 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 425 | } |
| 426 | |
| 427 | static class TimeBase { |
| 428 | private final ArrayList<TimeBaseObs> mObservers = new ArrayList<TimeBaseObs>(); |
| 429 | |
| 430 | private long mUptime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 431 | private long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 432 | |
| 433 | private boolean mRunning; |
| 434 | |
| 435 | private long mPastUptime; |
| 436 | private long mUptimeStart; |
| 437 | private long mPastRealtime; |
| 438 | private long mRealtimeStart; |
| 439 | private long mUnpluggedUptime; |
| 440 | private long mUnpluggedRealtime; |
| 441 | |
| 442 | public void dump(PrintWriter pw, String prefix) { |
| 443 | StringBuilder sb = new StringBuilder(128); |
| 444 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 445 | sb.setLength(0); |
| 446 | sb.append(prefix); |
| 447 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 448 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 449 | pw.println(sb.toString()); |
| 450 | sb.setLength(0); |
| 451 | sb.append(prefix); |
| 452 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 453 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 454 | pw.println(sb.toString()); |
| 455 | sb.setLength(0); |
| 456 | sb.append(prefix); |
| 457 | sb.append("mPastUptime="); |
| 458 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 459 | formatTimeMs(sb, mUptimeStart / 1000); |
| 460 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 461 | pw.println(sb.toString()); |
| 462 | sb.setLength(0); |
| 463 | sb.append(prefix); |
| 464 | sb.append("mPastRealtime="); |
| 465 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 466 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 467 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 468 | pw.println(sb.toString()); |
| 469 | } |
| 470 | |
| 471 | public void add(TimeBaseObs observer) { |
| 472 | mObservers.add(observer); |
| 473 | } |
| 474 | |
| 475 | public void remove(TimeBaseObs observer) { |
| 476 | if (!mObservers.remove(observer)) { |
| 477 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | public void init(long uptime, long realtime) { |
| 482 | mRealtime = 0; |
| 483 | mUptime = 0; |
| 484 | mPastUptime = 0; |
| 485 | mPastRealtime = 0; |
| 486 | mUptimeStart = uptime; |
| 487 | mRealtimeStart = realtime; |
| 488 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 489 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 490 | } |
| 491 | |
| 492 | public void reset(long uptime, long realtime) { |
| 493 | if (!mRunning) { |
| 494 | mPastUptime = 0; |
| 495 | mPastRealtime = 0; |
| 496 | } else { |
| 497 | mUptimeStart = uptime; |
| 498 | mRealtimeStart = realtime; |
| 499 | mUnpluggedUptime = getUptime(uptime); |
| 500 | mUnpluggedRealtime = getRealtime(realtime); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | public long computeUptime(long curTime, int which) { |
| 505 | switch (which) { |
| 506 | case STATS_SINCE_CHARGED: |
| 507 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 508 | case STATS_CURRENT: |
| 509 | return getUptime(curTime); |
| 510 | case STATS_SINCE_UNPLUGGED: |
| 511 | return getUptime(curTime) - mUnpluggedUptime; |
| 512 | } |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | public long computeRealtime(long curTime, int which) { |
| 517 | switch (which) { |
| 518 | case STATS_SINCE_CHARGED: |
| 519 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 520 | case STATS_CURRENT: |
| 521 | return getRealtime(curTime); |
| 522 | case STATS_SINCE_UNPLUGGED: |
| 523 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 524 | } |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | public long getUptime(long curTime) { |
| 529 | long time = mPastUptime; |
| 530 | if (mRunning) { |
| 531 | time += curTime - mUptimeStart; |
| 532 | } |
| 533 | return time; |
| 534 | } |
| 535 | |
| 536 | public long getRealtime(long curTime) { |
| 537 | long time = mPastRealtime; |
| 538 | if (mRunning) { |
| 539 | time += curTime - mRealtimeStart; |
| 540 | } |
| 541 | return time; |
| 542 | } |
| 543 | |
| 544 | public long getUptimeStart() { |
| 545 | return mUptimeStart; |
| 546 | } |
| 547 | |
| 548 | public long getRealtimeStart() { |
| 549 | return mRealtimeStart; |
| 550 | } |
| 551 | |
| 552 | public boolean isRunning() { |
| 553 | return mRunning; |
| 554 | } |
| 555 | |
| 556 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 557 | if (mRunning != running) { |
| 558 | mRunning = running; |
| 559 | if (running) { |
| 560 | mUptimeStart = uptime; |
| 561 | mRealtimeStart = realtime; |
| 562 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 563 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 564 | |
| 565 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 566 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 567 | } |
| 568 | } else { |
| 569 | mPastUptime += uptime - mUptimeStart; |
| 570 | mPastRealtime += realtime - mRealtimeStart; |
| 571 | |
| 572 | long batteryUptime = getUptime(uptime); |
| 573 | long batteryRealtime = getRealtime(realtime); |
| 574 | |
| 575 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 576 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 577 | } |
| 578 | } |
| 579 | return true; |
| 580 | } |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | public void readSummaryFromParcel(Parcel in) { |
| 585 | mUptime = in.readLong(); |
| 586 | mRealtime = in.readLong(); |
| 587 | } |
| 588 | |
| 589 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 590 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 591 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 592 | } |
| 593 | |
| 594 | public void readFromParcel(Parcel in) { |
| 595 | mRunning = false; |
| 596 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 597 | mPastUptime = in.readLong(); |
| 598 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 599 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 600 | mPastRealtime = in.readLong(); |
| 601 | mRealtimeStart = in.readLong(); |
| 602 | mUnpluggedUptime = in.readLong(); |
| 603 | mUnpluggedRealtime = in.readLong(); |
| 604 | } |
| 605 | |
| 606 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 607 | final long runningUptime = getUptime(uptime); |
| 608 | final long runningRealtime = getRealtime(realtime); |
| 609 | out.writeLong(mUptime); |
| 610 | out.writeLong(runningUptime); |
| 611 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 612 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 613 | out.writeLong(runningRealtime); |
| 614 | out.writeLong(mRealtimeStart); |
| 615 | out.writeLong(mUnpluggedUptime); |
| 616 | out.writeLong(mUnpluggedRealtime); |
| 617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 621 | * State for keeping track of counting information. |
| 622 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 623 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 624 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 625 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 626 | int mLoadedCount; |
| 627 | int mLastCount; |
| 628 | int mUnpluggedCount; |
| 629 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 630 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 631 | Counter(TimeBase timeBase, Parcel in) { |
| 632 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 633 | mPluggedCount = in.readInt(); |
| 634 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 635 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 636 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 637 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 638 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 641 | Counter(TimeBase timeBase) { |
| 642 | mTimeBase = timeBase; |
| 643 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 644 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 645 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 646 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 647 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 648 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 649 | out.writeInt(mUnpluggedCount); |
| 650 | } |
| 651 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 652 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 653 | mUnpluggedCount = mPluggedCount; |
| 654 | mCount.set(mPluggedCount); |
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 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 658 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 659 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 660 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 661 | /** |
| 662 | * Writes a possibly null Counter to a Parcel. |
| 663 | * |
| 664 | * @param out the Parcel to be written to. |
| 665 | * @param counter a Counter, or null. |
| 666 | */ |
| 667 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 668 | if (counter == null) { |
| 669 | out.writeInt(0); // indicates null |
| 670 | return; |
| 671 | } |
| 672 | out.writeInt(1); // indicates non-null |
| 673 | |
| 674 | counter.writeToParcel(out); |
| 675 | } |
| 676 | |
| 677 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 678 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 679 | int val = mCount.get(); |
| 680 | if (which == STATS_SINCE_UNPLUGGED) { |
| 681 | val -= mUnpluggedCount; |
| 682 | } else if (which != STATS_SINCE_CHARGED) { |
| 683 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | return val; |
| 687 | } |
| 688 | |
| 689 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 690 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 691 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 692 | + " mUnpluggedCount=" + mUnpluggedCount |
| 693 | + " mPluggedCount=" + mPluggedCount); |
| 694 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 695 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 696 | void stepAtomic() { |
| 697 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 700 | /** |
| 701 | * Clear state of this counter. |
| 702 | */ |
| 703 | void reset(boolean detachIfReset) { |
| 704 | mCount.set(0); |
| 705 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 706 | if (detachIfReset) { |
| 707 | detach(); |
| 708 | } |
| 709 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 710 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 711 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 712 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 713 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 714 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 715 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 716 | int count = mCount.get(); |
| 717 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 721 | mLoadedCount = in.readInt(); |
| 722 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 723 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 724 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 727 | |
| 728 | public static class SamplingCounter extends Counter { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 729 | SamplingCounter(TimeBase timeBase, Parcel in) { |
| 730 | super(timeBase, in); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 733 | SamplingCounter(TimeBase timeBase) { |
| 734 | super(timeBase); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 737 | public void addCountAtomic(long count) { |
| 738 | mCount.addAndGet((int)count); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 742 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 743 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 744 | long mCount; |
| 745 | long mLoadedCount; |
| 746 | long mLastCount; |
| 747 | long mUnpluggedCount; |
| 748 | long mPluggedCount; |
| 749 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 750 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 751 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 752 | mPluggedCount = in.readLong(); |
| 753 | mCount = mPluggedCount; |
| 754 | mLoadedCount = in.readLong(); |
| 755 | mLastCount = 0; |
| 756 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 757 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 760 | LongSamplingCounter(TimeBase timeBase) { |
| 761 | mTimeBase = timeBase; |
| 762 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | public void writeToParcel(Parcel out) { |
| 766 | out.writeLong(mCount); |
| 767 | out.writeLong(mLoadedCount); |
| 768 | out.writeLong(mUnpluggedCount); |
| 769 | } |
| 770 | |
| 771 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 772 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 773 | mUnpluggedCount = mPluggedCount; |
| 774 | mCount = mPluggedCount; |
| 775 | } |
| 776 | |
| 777 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 778 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 779 | mPluggedCount = mCount; |
| 780 | } |
| 781 | |
| 782 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 783 | long val = mCount; |
| 784 | if (which == STATS_SINCE_UNPLUGGED) { |
| 785 | val -= mUnpluggedCount; |
| 786 | } else if (which != STATS_SINCE_CHARGED) { |
| 787 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | return val; |
| 791 | } |
| 792 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 793 | @Override |
| 794 | public void logState(Printer pw, String prefix) { |
| 795 | pw.println(prefix + "mCount=" + mCount |
| 796 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 797 | + " mUnpluggedCount=" + mUnpluggedCount |
| 798 | + " mPluggedCount=" + mPluggedCount); |
| 799 | } |
| 800 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 801 | void addCountLocked(long count) { |
| 802 | mCount += count; |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * Clear state of this counter. |
| 807 | */ |
| 808 | void reset(boolean detachIfReset) { |
| 809 | mCount = 0; |
| 810 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 811 | if (detachIfReset) { |
| 812 | detach(); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 817 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | void writeSummaryFromParcelLocked(Parcel out) { |
| 821 | out.writeLong(mCount); |
| 822 | } |
| 823 | |
| 824 | void readSummaryFromParcelLocked(Parcel in) { |
| 825 | mLoadedCount = in.readLong(); |
| 826 | mCount = mLoadedCount; |
| 827 | mLastCount = 0; |
| 828 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 829 | } |
| 830 | } |
| 831 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 832 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | * State for keeping track of timing information. |
| 834 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 835 | 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] | 836 | final int mType; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 837 | final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | int mCount; |
| 840 | int mLoadedCount; |
| 841 | int mLastCount; |
| 842 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | // Times are in microseconds for better accuracy when dividing by the |
| 845 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | /** |
| 848 | * The total time we have accumulated since the start of the original |
| 849 | * boot, to the last time something interesting happened in the |
| 850 | * current run. |
| 851 | */ |
| 852 | long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | /** |
| 855 | * The total time we loaded for the previous runs. Subtract this from |
| 856 | * mTotalTime to find the time for the current run of the system. |
| 857 | */ |
| 858 | long mLoadedTime; |
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 | /** |
| 861 | * The run time of the last run of the system, as loaded from the |
| 862 | * saved data. |
| 863 | */ |
| 864 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | /** |
| 867 | * The value of mTotalTime when unplug() was last called. Subtract |
| 868 | * this from mTotalTime to find the time since the last unplug from |
| 869 | * power. |
| 870 | */ |
| 871 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 872 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 873 | /** |
| 874 | * Constructs from a parcel. |
| 875 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 876 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 877 | * @param in |
| 878 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 879 | Timer(int type, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 881 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | mCount = in.readInt(); |
| 884 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 885 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | mUnpluggedCount = in.readInt(); |
| 887 | mTotalTime = in.readLong(); |
| 888 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 889 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | mUnpluggedTime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 891 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 892 | 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] | 893 | } |
| 894 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 895 | Timer(int type, TimeBase timeBase) { |
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; |
| 898 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 900 | |
| 901 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 902 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 903 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 904 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 905 | /** |
| 906 | * Clear state of this timer. Returns true if the timer is inactive |
| 907 | * so can be completely dropped. |
| 908 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 909 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 910 | mTotalTime = mLoadedTime = mLastTime = 0; |
| 911 | mCount = mLoadedCount = mLastCount = 0; |
| 912 | if (detachIfReset) { |
| 913 | detach(); |
| 914 | } |
| 915 | return true; |
| 916 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 917 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 918 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 919 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 920 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 921 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 922 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 923 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 924 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | out.writeInt(mCount); |
| 926 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 928 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 930 | out.writeLong(mUnpluggedTime); |
| 931 | } |
| 932 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 933 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 935 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 937 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 938 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 939 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | mUnpluggedCount = mCount; |
| 941 | if (DEBUG && mType < 0) { |
| 942 | Log.v(TAG, "unplug #" + mType |
| 943 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 944 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 945 | } |
| 946 | } |
| 947 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 948 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 949 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 950 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 951 | + " old mTotalTime=" + mTotalTime); |
| 952 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 953 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 954 | mCount = computeCurrentCountLocked(); |
| 955 | if (DEBUG && mType < 0) { |
| 956 | Log.v(TAG, "plug #" + mType |
| 957 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | } |
| 959 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | /** |
| 962 | * Writes a possibly null Timer to a Parcel. |
| 963 | * |
| 964 | * @param out the Parcel to be written to. |
| 965 | * @param timer a Timer, or null. |
| 966 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 967 | 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] | 968 | if (timer == null) { |
| 969 | out.writeInt(0); // indicates null |
| 970 | return; |
| 971 | } |
| 972 | out.writeInt(1); // indicates non-null |
| 973 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 974 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 978 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 979 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 980 | if (which == STATS_SINCE_UNPLUGGED) { |
| 981 | val -= mUnpluggedTime; |
| 982 | } else if (which != STATS_SINCE_CHARGED) { |
| 983 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | return val; |
| 987 | } |
| 988 | |
| 989 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 990 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 991 | int val = computeCurrentCountLocked(); |
| 992 | if (which == STATS_SINCE_UNPLUGGED) { |
| 993 | val -= mUnpluggedCount; |
| 994 | } else if (which != STATS_SINCE_CHARGED) { |
| 995 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | return val; |
| 999 | } |
| 1000 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1001 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1002 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1004 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1005 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1007 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1009 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1010 | |
| 1011 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1012 | void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1013 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1014 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1015 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | void readSummaryFromParcelLocked(Parcel in) { |
| 1019 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1020 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1021 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1022 | mUnpluggedTime = mTotalTime; |
| 1023 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1024 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1025 | mUnpluggedCount = mCount; |
| 1026 | } |
| 1027 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1028 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1029 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1030 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1031 | /** |
| 1032 | * The most recent reported count from /proc/wakelocks. |
| 1033 | */ |
| 1034 | int mCurrentReportedCount; |
| 1035 | |
| 1036 | /** |
| 1037 | * The reported count from /proc/wakelocks when unplug() was last |
| 1038 | * called. |
| 1039 | */ |
| 1040 | int mUnpluggedReportedCount; |
| 1041 | |
| 1042 | /** |
| 1043 | * The most recent reported total_time from /proc/wakelocks. |
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 | long mCurrentReportedTotalTime; |
| 1046 | |
| 1047 | |
| 1048 | /** |
| 1049 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1050 | * called. |
| 1051 | */ |
| 1052 | long mUnpluggedReportedTotalTime; |
| 1053 | |
| 1054 | /** |
| 1055 | * Whether we are currently in a discharge cycle. |
| 1056 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1057 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1058 | |
| 1059 | /** |
| 1060 | * Whether we are currently recording reported values. |
| 1061 | */ |
| 1062 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1063 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1064 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1065 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1066 | */ |
| 1067 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1068 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1069 | SamplingTimer(TimeBase timeBase, Parcel in) { |
| 1070 | super(0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1071 | mCurrentReportedCount = in.readInt(); |
| 1072 | mUnpluggedReportedCount = in.readInt(); |
| 1073 | mCurrentReportedTotalTime = in.readLong(); |
| 1074 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1075 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1076 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1077 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1078 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1079 | SamplingTimer(TimeBase timeBase, boolean trackReportedValues) { |
| 1080 | super(0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1081 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1082 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1083 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1084 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1085 | public void setStale() { |
| 1086 | mTrackingReportedValues = false; |
| 1087 | mUnpluggedReportedTotalTime = 0; |
| 1088 | mUnpluggedReportedCount = 0; |
| 1089 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1090 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1091 | public void setUpdateVersion(int version) { |
| 1092 | mUpdateVersion = version; |
| 1093 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1094 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1095 | public int getUpdateVersion() { |
| 1096 | return mUpdateVersion; |
| 1097 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1098 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1099 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1100 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1101 | // Updating the reported value for the first time. |
| 1102 | mUnpluggedReportedCount = count; |
| 1103 | // If we are receiving an update update mTrackingReportedValues; |
| 1104 | mTrackingReportedValues = true; |
| 1105 | } |
| 1106 | mCurrentReportedCount = count; |
| 1107 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1108 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1109 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1110 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1111 | // Updating the reported value for the first time. |
| 1112 | mUnpluggedReportedTotalTime = totalTime; |
| 1113 | // If we are receiving an update update mTrackingReportedValues; |
| 1114 | mTrackingReportedValues = true; |
| 1115 | } |
| 1116 | mCurrentReportedTotalTime = totalTime; |
| 1117 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1118 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1119 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1120 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1121 | if (mTrackingReportedValues) { |
| 1122 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1123 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1124 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1125 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1128 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1129 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1130 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1131 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1132 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1133 | public void logState(Printer pw, String prefix) { |
| 1134 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1135 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1136 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1137 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1138 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1139 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1140 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1141 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1142 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1143 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1144 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1145 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1146 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1147 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1148 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1149 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1150 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1151 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1152 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1153 | out.writeInt(mCurrentReportedCount); |
| 1154 | out.writeInt(mUnpluggedReportedCount); |
| 1155 | out.writeLong(mCurrentReportedTotalTime); |
| 1156 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1157 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1158 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1159 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1160 | boolean reset(boolean detachIfReset) { |
| 1161 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1162 | setStale(); |
| 1163 | return true; |
| 1164 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1165 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1166 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 1167 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1168 | out.writeLong(mCurrentReportedTotalTime); |
| 1169 | out.writeInt(mCurrentReportedCount); |
| 1170 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1171 | } |
| 1172 | |
| 1173 | void readSummaryFromParcelLocked(Parcel in) { |
| 1174 | super.readSummaryFromParcelLocked(in); |
| 1175 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1176 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1177 | mTrackingReportedValues = in.readInt() == 1; |
| 1178 | } |
| 1179 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1180 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1181 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1182 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1183 | * for a pre-determined amount. |
| 1184 | */ |
| 1185 | public static final class BatchTimer extends Timer { |
| 1186 | final Uid mUid; |
| 1187 | |
| 1188 | /** |
| 1189 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1190 | */ |
| 1191 | long mLastAddedTime; |
| 1192 | |
| 1193 | /** |
| 1194 | * The last duration that we added to the timer. This is in microseconds. |
| 1195 | */ |
| 1196 | long mLastAddedDuration; |
| 1197 | |
| 1198 | /** |
| 1199 | * Whether we are currently in a discharge cycle. |
| 1200 | */ |
| 1201 | boolean mInDischarge; |
| 1202 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1203 | BatchTimer(Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1204 | super(type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1205 | mUid = uid; |
| 1206 | mLastAddedTime = in.readLong(); |
| 1207 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1208 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1209 | } |
| 1210 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1211 | BatchTimer(Uid uid, int type, TimeBase timeBase) { |
| 1212 | super(type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1213 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1214 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1218 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1219 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1220 | out.writeLong(mLastAddedTime); |
| 1221 | out.writeLong(mLastAddedDuration); |
| 1222 | } |
| 1223 | |
| 1224 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1225 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1226 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 1227 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1228 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1232 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1233 | recomputeLastDuration(elapsedRealtime, false); |
| 1234 | mInDischarge = true; |
| 1235 | // If we are still within the last added duration, then re-added whatever remains. |
| 1236 | if (mLastAddedTime == elapsedRealtime) { |
| 1237 | mTotalTime += mLastAddedDuration; |
| 1238 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1239 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | @Override |
| 1243 | public void logState(Printer pw, String prefix) { |
| 1244 | super.logState(pw, prefix); |
| 1245 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1246 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1247 | } |
| 1248 | |
| 1249 | private long computeOverage(long curTime) { |
| 1250 | if (mLastAddedTime > 0) { |
| 1251 | return mLastTime + mLastAddedDuration - curTime; |
| 1252 | } |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
| 1256 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1257 | final long overage = computeOverage(curTime); |
| 1258 | if (overage > 0) { |
| 1259 | // Aborting before the duration ran out -- roll back the remaining |
| 1260 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1261 | // actually add the time. |
| 1262 | if (mInDischarge) { |
| 1263 | mTotalTime -= overage; |
| 1264 | } |
| 1265 | if (abort) { |
| 1266 | mLastAddedTime = 0; |
| 1267 | } else { |
| 1268 | mLastAddedTime = curTime; |
| 1269 | mLastAddedDuration -= overage; |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1275 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1276 | recomputeLastDuration(now, true); |
| 1277 | mLastAddedTime = now; |
| 1278 | mLastAddedDuration = durationMillis * 1000; |
| 1279 | if (mInDischarge) { |
| 1280 | mTotalTime += mLastAddedDuration; |
| 1281 | mCount++; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1286 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1287 | recomputeLastDuration(now, true); |
| 1288 | } |
| 1289 | |
| 1290 | @Override |
| 1291 | protected int computeCurrentCountLocked() { |
| 1292 | return mCount; |
| 1293 | } |
| 1294 | |
| 1295 | @Override |
| 1296 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1297 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1298 | if (overage > 0) { |
| 1299 | return mTotalTime = overage; |
| 1300 | } |
| 1301 | return mTotalTime; |
| 1302 | } |
| 1303 | |
| 1304 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1305 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1306 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1307 | recomputeLastDuration(now, true); |
| 1308 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1309 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1310 | return !stillActive; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1315 | * State for keeping track of timing information. |
| 1316 | */ |
| 1317 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1318 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1319 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1320 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1321 | int mNesting; |
| 1322 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1323 | /** |
| 1324 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1325 | * subtract this from the current battery time to find the amount of |
| 1326 | * time we have been running since we last computed an update. |
| 1327 | */ |
| 1328 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1329 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1330 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1331 | * 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] | 1332 | * was actually held for an interesting duration. |
| 1333 | */ |
| 1334 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1335 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1336 | long mTimeout; |
| 1337 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1338 | /** |
| 1339 | * For partial wake locks, keep track of whether we are in the list |
| 1340 | * to consume CPU cycles. |
| 1341 | */ |
| 1342 | boolean mInList; |
| 1343 | |
| 1344 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1345 | TimeBase timeBase, Parcel in) { |
| 1346 | super(type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1347 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1348 | mTimerPool = timerPool; |
| 1349 | mUpdateTime = in.readLong(); |
| 1350 | } |
| 1351 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1352 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1353 | TimeBase timeBase) { |
| 1354 | super(type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1355 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1356 | mTimerPool = timerPool; |
| 1357 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1358 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1359 | void setTimeout(long timeout) { |
| 1360 | mTimeout = timeout; |
| 1361 | } |
| 1362 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1363 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1364 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1365 | out.writeLong(mUpdateTime); |
| 1366 | } |
| 1367 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1368 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1369 | if (mNesting > 0) { |
| 1370 | if (DEBUG && mType < 0) { |
| 1371 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1372 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1373 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1374 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1375 | if (DEBUG && mType < 0) { |
| 1376 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | public void logState(Printer pw, String prefix) { |
| 1382 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1383 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | + " mAcquireTime=" + mAcquireTime); |
| 1385 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1386 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1387 | void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1389 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1390 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | if (mTimerPool != null) { |
| 1392 | // Accumulate time to all currently active timers before adding |
| 1393 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1394 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | // Add this timer to the active pool |
| 1396 | mTimerPool.add(this); |
| 1397 | } |
| 1398 | // Increment the count |
| 1399 | mCount++; |
| 1400 | mAcquireTime = mTotalTime; |
| 1401 | if (DEBUG && mType < 0) { |
| 1402 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1403 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1404 | + " mAcquireTime=" + mAcquireTime); |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1409 | boolean isRunningLocked() { |
| 1410 | return mNesting > 0; |
| 1411 | } |
| 1412 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1413 | long checkpointRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1414 | if (mNesting > 0) { |
| 1415 | // We are running... |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1416 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1417 | if (mTimerPool != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1418 | return refreshTimersLocked(batteryRealtime, mTimerPool, this); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1419 | } |
| 1420 | final long heldTime = batteryRealtime - mUpdateTime; |
| 1421 | mUpdateTime = batteryRealtime; |
| 1422 | mTotalTime += heldTime; |
| 1423 | return heldTime; |
| 1424 | } |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1428 | long getLastUpdateTimeMs() { |
| 1429 | return mUpdateTime; |
| 1430 | } |
| 1431 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1432 | void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | // Ignore attempt to stop a timer that isn't running |
| 1434 | if (mNesting == 0) { |
| 1435 | return; |
| 1436 | } |
| 1437 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1438 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | if (mTimerPool != null) { |
| 1440 | // Accumulate time to all active counters, scaled by the total |
| 1441 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1442 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | // Remove this timer from the active pool |
| 1444 | mTimerPool.remove(this); |
| 1445 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | mNesting = 1; |
| 1447 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1448 | mNesting = 0; |
| 1449 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | if (DEBUG && mType < 0) { |
| 1452 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1453 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1454 | + " mAcquireTime=" + mAcquireTime); |
| 1455 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | if (mTotalTime == mAcquireTime) { |
| 1458 | // If there was no change in the time, then discard this |
| 1459 | // count. A somewhat cheezy strategy, but hey. |
| 1460 | mCount--; |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | // Update the total time for all other running Timers with the same type as this Timer |
| 1466 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1467 | private static long refreshTimersLocked(long batteryRealtime, |
| 1468 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1469 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | final int N = pool.size(); |
| 1471 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1472 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1474 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1475 | final long myTime = heldTime / N; |
| 1476 | if (t == self) { |
| 1477 | selfTime = myTime; |
| 1478 | } |
| 1479 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | } |
| 1481 | t.mUpdateTime = batteryRealtime; |
| 1482 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1483 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1486 | @Override |
| 1487 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1488 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1489 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | return mTotalTime + (mNesting > 0 |
| 1492 | ? (curBatteryRealtime - mUpdateTime) |
| 1493 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1494 | : 0); |
| 1495 | } |
| 1496 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1497 | @Override |
| 1498 | protected int computeCurrentCountLocked() { |
| 1499 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1502 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1503 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1504 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1505 | if (mNesting > 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1506 | mUpdateTime = mTimeBase.getRealtime(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1507 | } |
| 1508 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1509 | return canDetach; |
| 1510 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1511 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1512 | void detach() { |
| 1513 | super.detach(); |
| 1514 | if (mTimerPool != null) { |
| 1515 | mTimerPool.remove(this); |
| 1516 | } |
| 1517 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1520 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | mNesting = 0; |
| 1522 | } |
| 1523 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1524 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1525 | /* |
| 1526 | * Get the wakeup reason counter, and create a new one if one |
| 1527 | * doesn't already exist. |
| 1528 | */ |
| 1529 | public LongSamplingCounter getWakeupReasonCounterLocked(String name) { |
| 1530 | LongSamplingCounter counter = mWakeupReasonStats.get(name); |
| 1531 | if (counter == null) { |
| 1532 | counter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
| 1533 | mWakeupReasonStats.put(name, counter); |
| 1534 | } |
| 1535 | return counter; |
| 1536 | } |
| 1537 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1538 | private final Map<String, KernelWakelockStats> readKernelWakelockStats() { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1539 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1540 | FileInputStream is; |
Johannes Carlsson | 3372f2e | 2010-06-30 08:45:55 +0200 | [diff] [blame] | 1541 | byte[] buffer = new byte[8192]; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1542 | int len; |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1543 | boolean wakeup_sources = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1544 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1545 | try { |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1546 | try { |
| 1547 | is = new FileInputStream("/proc/wakelocks"); |
| 1548 | } catch (java.io.FileNotFoundException e) { |
| 1549 | try { |
| 1550 | is = new FileInputStream("/d/wakeup_sources"); |
| 1551 | wakeup_sources = true; |
| 1552 | } catch (java.io.FileNotFoundException e2) { |
| 1553 | return null; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1554 | } |
| 1555 | } |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1556 | |
| 1557 | len = is.read(buffer); |
| 1558 | is.close(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1559 | } catch (java.io.IOException e) { |
| 1560 | return null; |
| 1561 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1562 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1563 | if (len > 0) { |
| 1564 | int i; |
| 1565 | for (i=0; i<len; i++) { |
| 1566 | if (buffer[i] == '\0') { |
| 1567 | len = i; |
| 1568 | break; |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | return parseProcWakelocks(buffer, len, wakeup_sources); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1574 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1575 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1576 | private final Map<String, KernelWakelockStats> parseProcWakelocks( |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1577 | byte[] wlBuffer, int len, boolean wakeup_sources) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1578 | String name; |
| 1579 | int count; |
| 1580 | long totalTime; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 1581 | int startIndex; |
| 1582 | int endIndex; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1583 | int numUpdatedWlNames = 0; |
| 1584 | |
| 1585 | // Advance past the first line. |
| 1586 | int i; |
| 1587 | for (i = 0; i < len && wlBuffer[i] != '\n' && wlBuffer[i] != '\0'; i++); |
| 1588 | startIndex = endIndex = i + 1; |
| 1589 | |
| 1590 | synchronized(this) { |
| 1591 | Map<String, KernelWakelockStats> m = mProcWakelockFileStats; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1592 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1593 | sKernelWakelockUpdateVersion++; |
| 1594 | while (endIndex < len) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1595 | for (endIndex=startIndex; |
| 1596 | endIndex < len && wlBuffer[endIndex] != '\n' && wlBuffer[endIndex] != '\0'; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1597 | endIndex++); |
Johannes Carlsson | 3372f2e | 2010-06-30 08:45:55 +0200 | [diff] [blame] | 1598 | endIndex++; // endIndex is an exclusive upper bound. |
| 1599 | // Don't go over the end of the buffer, Process.parseProcLine might |
| 1600 | // write to wlBuffer[endIndex] |
| 1601 | if (endIndex >= (len - 1) ) { |
| 1602 | return m; |
Amith Yamasani | e579561 | 2010-04-05 12:43:44 -0700 | [diff] [blame] | 1603 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1604 | |
| 1605 | String[] nameStringArray = mProcWakelocksName; |
| 1606 | long[] wlData = mProcWakelocksData; |
Amith Yamasani | 2098ead | 2010-04-02 13:46:49 -0700 | [diff] [blame] | 1607 | // Stomp out any bad characters since this is from a circular buffer |
| 1608 | // A corruption is seen sometimes that results in the vm crashing |
| 1609 | // This should prevent crashes and the line will probably fail to parse |
| 1610 | for (int j = startIndex; j < endIndex; j++) { |
| 1611 | if ((wlBuffer[j] & 0x80) != 0) wlBuffer[j] = (byte) '?'; |
| 1612 | } |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1613 | boolean parsed = Process.parseProcLine(wlBuffer, startIndex, endIndex, |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1614 | wakeup_sources ? WAKEUP_SOURCES_FORMAT : |
| 1615 | PROC_WAKELOCKS_FORMAT, |
| 1616 | nameStringArray, wlData, null); |
Amith Yamasani | 2098ead | 2010-04-02 13:46:49 -0700 | [diff] [blame] | 1617 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1618 | name = nameStringArray[0]; |
| 1619 | count = (int) wlData[1]; |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1620 | |
| 1621 | if (wakeup_sources) { |
| 1622 | // convert milliseconds to microseconds |
| 1623 | totalTime = wlData[2] * 1000; |
| 1624 | } else { |
| 1625 | // convert nanoseconds to microseconds with rounding. |
| 1626 | totalTime = (wlData[2] + 500) / 1000; |
| 1627 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1628 | |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1629 | if (parsed && name.length() > 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1630 | if (!m.containsKey(name)) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1631 | m.put(name, new KernelWakelockStats(count, totalTime, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1632 | sKernelWakelockUpdateVersion)); |
| 1633 | numUpdatedWlNames++; |
| 1634 | } else { |
| 1635 | KernelWakelockStats kwlStats = m.get(name); |
| 1636 | if (kwlStats.mVersion == sKernelWakelockUpdateVersion) { |
| 1637 | kwlStats.mCount += count; |
| 1638 | kwlStats.mTotalTime += totalTime; |
| 1639 | } else { |
| 1640 | kwlStats.mCount = count; |
| 1641 | kwlStats.mTotalTime = totalTime; |
| 1642 | kwlStats.mVersion = sKernelWakelockUpdateVersion; |
| 1643 | numUpdatedWlNames++; |
| 1644 | } |
| 1645 | } |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1646 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1647 | startIndex = endIndex; |
| 1648 | } |
| 1649 | |
| 1650 | if (m.size() != numUpdatedWlNames) { |
| 1651 | // Don't report old data. |
| 1652 | Iterator<KernelWakelockStats> itr = m.values().iterator(); |
| 1653 | while (itr.hasNext()) { |
| 1654 | if (itr.next().mVersion != sKernelWakelockUpdateVersion) { |
| 1655 | itr.remove(); |
| 1656 | } |
| 1657 | } |
| 1658 | } |
| 1659 | return m; |
| 1660 | } |
| 1661 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1662 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1663 | private class KernelWakelockStats { |
| 1664 | public int mCount; |
| 1665 | public long mTotalTime; |
| 1666 | public int mVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1667 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1668 | KernelWakelockStats(int count, long totalTime, int version) { |
| 1669 | mCount = count; |
| 1670 | mTotalTime = totalTime; |
| 1671 | mVersion = version; |
| 1672 | } |
| 1673 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1674 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1675 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1676 | * 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] | 1677 | * doesn't already exist. |
| 1678 | */ |
| 1679 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1680 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1681 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1682 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1683 | mKernelWakelockStats.put(name, kwlt); |
| 1684 | } |
| 1685 | return kwlt; |
| 1686 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1687 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1688 | private int getCurrentBluetoothPingCount() { |
| 1689 | if (mBtHeadset != null) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1690 | List<BluetoothDevice> deviceList = mBtHeadset.getConnectedDevices(); |
| 1691 | if (deviceList.size() > 0) { |
| 1692 | return mBtHeadset.getBatteryUsageHint(deviceList.get(0)); |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 1693 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1694 | } |
| 1695 | return -1; |
| 1696 | } |
| 1697 | |
| 1698 | public int getBluetoothPingCount() { |
| 1699 | if (mBluetoothPingStart == -1) { |
| 1700 | return mBluetoothPingCount; |
| 1701 | } else if (mBtHeadset != null) { |
| 1702 | return getCurrentBluetoothPingCount() - mBluetoothPingStart; |
| 1703 | } |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1704 | return 0; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | public void setBtHeadset(BluetoothHeadset headset) { |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1708 | if (headset != null && mBtHeadset == null && isOnBattery() && mBluetoothPingStart == -1) { |
| 1709 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 1710 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1711 | mBtHeadset = headset; |
| 1712 | } |
| 1713 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1714 | private int writeHistoryTag(HistoryTag tag) { |
| 1715 | Integer idxObj = mHistoryTagPool.get(tag); |
| 1716 | int idx; |
| 1717 | if (idxObj != null) { |
| 1718 | idx = idxObj; |
| 1719 | } else { |
| 1720 | idx = mNextHistoryTagIdx; |
| 1721 | HistoryTag key = new HistoryTag(); |
| 1722 | key.setTo(tag); |
| 1723 | tag.poolIdx = idx; |
| 1724 | mHistoryTagPool.put(key, idx); |
| 1725 | mNextHistoryTagIdx++; |
| 1726 | mNumHistoryTagChars += key.string.length() + 1; |
| 1727 | } |
| 1728 | return idx; |
| 1729 | } |
| 1730 | |
| 1731 | private void readHistoryTag(int index, HistoryTag tag) { |
| 1732 | tag.string = mReadHistoryStrings[index]; |
| 1733 | tag.uid = mReadHistoryUids[index]; |
| 1734 | tag.poolIdx = index; |
| 1735 | } |
| 1736 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1737 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1738 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 1739 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 1740 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 1741 | 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] | 1742 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1743 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1744 | // 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] | 1745 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 1746 | // Flag in delta int: a new full state2 int follows. |
| 1747 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1748 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1749 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1750 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1751 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1752 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1753 | static final int DELTA_STATE_MASK = 0xff000000; |
| 1754 | |
| 1755 | // These are the pieces of battery state that are packed in to the upper bits of |
| 1756 | // the state int that have been packed in to the first delta int. They must fit |
| 1757 | // in DELTA_STATE_MASK. |
| 1758 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 1759 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 1760 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 1761 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 1762 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 1763 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1764 | |
| 1765 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1766 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1767 | dest.writeInt(DELTA_TIME_ABS); |
| 1768 | cur.writeToParcel(dest, 0); |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | final long deltaTime = cur.time - last.time; |
| 1773 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 1774 | final int lastStateInt = buildStateInt(last); |
| 1775 | |
| 1776 | int deltaTimeToken; |
| 1777 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 1778 | deltaTimeToken = DELTA_TIME_LONG; |
| 1779 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 1780 | deltaTimeToken = DELTA_TIME_INT; |
| 1781 | } else { |
| 1782 | deltaTimeToken = (int)deltaTime; |
| 1783 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1784 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1785 | final int batteryLevelInt = buildBatteryLevelInt(cur); |
| 1786 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 1787 | if (batteryLevelIntChanged) { |
| 1788 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 1789 | } |
| 1790 | final int stateInt = buildStateInt(cur); |
| 1791 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 1792 | if (stateIntChanged) { |
| 1793 | firstToken |= DELTA_STATE_FLAG; |
| 1794 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1795 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 1796 | if (state2IntChanged) { |
| 1797 | firstToken |= DELTA_STATE2_FLAG; |
| 1798 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1799 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1800 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 1801 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1802 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 1803 | firstToken |= DELTA_EVENT_FLAG; |
| 1804 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1805 | dest.writeInt(firstToken); |
| 1806 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1807 | + " deltaTime=" + deltaTime); |
| 1808 | |
| 1809 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 1810 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 1811 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 1812 | dest.writeInt((int)deltaTime); |
| 1813 | } else { |
| 1814 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 1815 | dest.writeLong(deltaTime); |
| 1816 | } |
| 1817 | } |
| 1818 | if (batteryLevelIntChanged) { |
| 1819 | dest.writeInt(batteryLevelInt); |
| 1820 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 1821 | + Integer.toHexString(batteryLevelInt) |
| 1822 | + " batteryLevel=" + cur.batteryLevel |
| 1823 | + " batteryTemp=" + cur.batteryTemperature |
| 1824 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1825 | } |
| 1826 | if (stateIntChanged) { |
| 1827 | dest.writeInt(stateInt); |
| 1828 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 1829 | + Integer.toHexString(stateInt) |
| 1830 | + " batteryStatus=" + cur.batteryStatus |
| 1831 | + " batteryHealth=" + cur.batteryHealth |
| 1832 | + " batteryPlugType=" + cur.batteryPlugType |
| 1833 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1834 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1835 | if (state2IntChanged) { |
| 1836 | dest.writeInt(cur.states2); |
| 1837 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 1838 | + Integer.toHexString(cur.states2)); |
| 1839 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1840 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 1841 | int wakeLockIndex; |
| 1842 | int wakeReasonIndex; |
| 1843 | if (cur.wakelockTag != null) { |
| 1844 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 1845 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1846 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1847 | } else { |
| 1848 | wakeLockIndex = 0xffff; |
| 1849 | } |
| 1850 | if (cur.wakeReasonTag != null) { |
| 1851 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 1852 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1853 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1854 | } else { |
| 1855 | wakeReasonIndex = 0xffff; |
| 1856 | } |
| 1857 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1858 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1859 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1860 | int index = writeHistoryTag(cur.eventTag); |
| 1861 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1862 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1863 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 1864 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 1865 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | private int buildBatteryLevelInt(HistoryItem h) { |
| 1870 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
| 1871 | | ((((int)h.batteryTemperature)<<14)&0x01ffc000) |
| 1872 | | (((int)h.batteryVoltage)&0x00003fff); |
| 1873 | } |
| 1874 | |
| 1875 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1876 | int plugType = 0; |
| 1877 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 1878 | plugType = 1; |
| 1879 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 1880 | plugType = 2; |
| 1881 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 1882 | plugType = 3; |
| 1883 | } |
| 1884 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 1885 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 1886 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1887 | | (h.states&(~DELTA_STATE_MASK)); |
| 1888 | } |
| 1889 | |
| 1890 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 1891 | int firstToken = src.readInt(); |
| 1892 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1893 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1894 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1895 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1896 | + " deltaTimeToken=" + deltaTimeToken); |
| 1897 | |
| 1898 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 1899 | cur.time += deltaTimeToken; |
| 1900 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 1901 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1902 | cur.numReadInts += 2; |
| 1903 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1904 | cur.readFromParcel(src); |
| 1905 | return; |
| 1906 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 1907 | int delta = src.readInt(); |
| 1908 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1909 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1910 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 1911 | } else { |
| 1912 | long delta = src.readLong(); |
| 1913 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 1914 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1915 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
| 1919 | int batteryLevelInt = src.readInt(); |
| 1920 | cur.batteryLevel = (byte)((batteryLevelInt>>25)&0x7f); |
| 1921 | cur.batteryTemperature = (short)((batteryLevelInt<<7)>>21); |
| 1922 | cur.batteryVoltage = (char)(batteryLevelInt&0x3fff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1923 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1924 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 1925 | + Integer.toHexString(batteryLevelInt) |
| 1926 | + " batteryLevel=" + cur.batteryLevel |
| 1927 | + " batteryTemp=" + cur.batteryTemperature |
| 1928 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1929 | } |
| 1930 | |
| 1931 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 1932 | int stateInt = src.readInt(); |
| 1933 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1934 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 1935 | & STATE_BATTERY_STATUS_MASK); |
| 1936 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 1937 | & STATE_BATTERY_HEALTH_MASK); |
| 1938 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 1939 | & STATE_BATTERY_PLUG_MASK); |
| 1940 | switch (cur.batteryPlugType) { |
| 1941 | case 1: |
| 1942 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 1943 | break; |
| 1944 | case 2: |
| 1945 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 1946 | break; |
| 1947 | case 3: |
| 1948 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 1949 | break; |
| 1950 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1951 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1952 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 1953 | + Integer.toHexString(stateInt) |
| 1954 | + " batteryStatus=" + cur.batteryStatus |
| 1955 | + " batteryHealth=" + cur.batteryHealth |
| 1956 | + " batteryPlugType=" + cur.batteryPlugType |
| 1957 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1958 | } else { |
| 1959 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 1960 | } |
| 1961 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1962 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 1963 | cur.states2 = src.readInt(); |
| 1964 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 1965 | + Integer.toHexString(cur.states2)); |
| 1966 | } |
| 1967 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1968 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1969 | int indexes = src.readInt(); |
| 1970 | int wakeLockIndex = indexes&0xffff; |
| 1971 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 1972 | if (wakeLockIndex != 0xffff) { |
| 1973 | cur.wakelockTag = cur.localWakelockTag; |
| 1974 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 1975 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1976 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1977 | } else { |
| 1978 | cur.wakelockTag = null; |
| 1979 | } |
| 1980 | if (wakeReasonIndex != 0xffff) { |
| 1981 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 1982 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 1983 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1984 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1985 | } else { |
| 1986 | cur.wakeReasonTag = null; |
| 1987 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1988 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1989 | } else { |
| 1990 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1991 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1992 | } |
| 1993 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1994 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1995 | cur.eventTag = cur.localEventTag; |
| 1996 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1997 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1998 | final int index = ((codeAndIndex>>16)&0xffff); |
| 1999 | readHistoryTag(index, cur.eventTag); |
| 2000 | cur.numReadInts += 1; |
| 2001 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2002 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2003 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2004 | } else { |
| 2005 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2006 | } |
| 2007 | } |
| 2008 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2009 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2010 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2011 | return; |
| 2012 | } |
| 2013 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2014 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2015 | final int diffStates = mHistoryLastWritten.states^cur.states; |
| 2016 | final int diffStates2 = mHistoryLastWritten.states2^cur.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2017 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2018 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2019 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2020 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2021 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2022 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2023 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2024 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2025 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2026 | && (diffStates2&lastDiffStates2) == 0 |
| 2027 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2028 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2029 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2030 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2031 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2032 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2033 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2034 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2035 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2036 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2037 | // 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] | 2038 | // 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] | 2039 | // as long as no bit has changed both between now and the last entry, as |
| 2040 | // well as the last entry and the one before it (so we capture any toggles). |
| 2041 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2042 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2043 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2044 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2045 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2046 | // If the last written history had a wakelock tag, we need to retain it. |
| 2047 | // Note that the condition above made sure that we aren't in a case where |
| 2048 | // both it and the current history item have a wakelock tag. |
| 2049 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2050 | cur.wakelockTag = cur.localWakelockTag; |
| 2051 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2052 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2053 | // If the last written history had a wake reason tag, we need to retain it. |
| 2054 | // Note that the condition above made sure that we aren't in a case where |
| 2055 | // both it and the current history item have a wakelock tag. |
| 2056 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2057 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2058 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2059 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2060 | // If the last written history had an event, we need to retain it. |
| 2061 | // Note that the condition above made sure that we aren't in a case where |
| 2062 | // both it and the current history item have an event. |
| 2063 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2064 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2065 | cur.eventTag = cur.localEventTag; |
| 2066 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2067 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2068 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2072 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2073 | if (!mHistoryOverflow) { |
| 2074 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2075 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2076 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2077 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | // Once we've reached the maximum number of items, we only |
| 2081 | // record changes to the battery level and the most interesting states. |
| 2082 | // Once we've reached the maximum maximum number of items, we only |
| 2083 | // record changes to the battery level. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2084 | if (mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2085 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2086 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2087 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
| 2088 | return; |
| 2089 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2090 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2091 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2092 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2095 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2098 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2099 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2100 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2101 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2102 | } |
| 2103 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2104 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2105 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2106 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2107 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2108 | cur.wakelockTag = null; |
| 2109 | cur.wakeReasonTag = null; |
| 2110 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2111 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2112 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2113 | + " now " + mHistoryBuffer.dataPosition() |
| 2114 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2117 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2118 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2119 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2120 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2121 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2122 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2123 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2124 | if (diffUptime < (diffElapsed-20)) { |
| 2125 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2126 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2127 | mHistoryAddTmp.wakelockTag = null; |
| 2128 | mHistoryAddTmp.wakeReasonTag = null; |
| 2129 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2130 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2131 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2132 | } |
| 2133 | } |
| 2134 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2135 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2136 | mTrackRunningHistoryUptime = uptimeMs; |
| 2137 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2138 | } |
| 2139 | |
| 2140 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2141 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2142 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2143 | if (!USE_OLD_HISTORY) { |
| 2144 | return; |
| 2145 | } |
| 2146 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2147 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2148 | return; |
| 2149 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2150 | |
| 2151 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2152 | // and no states have since the last recorded entry changed and |
| 2153 | // are now resetting back to their original value, then just collapse |
| 2154 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2155 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2156 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2157 | && ((mHistoryEnd.states^cur.states)&mChangedStates) == 0 |
| 2158 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2159 | // If the current is the same as the one before, then we no |
| 2160 | // longer need the entry. |
| 2161 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2162 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2163 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2164 | mHistoryLastEnd.next = null; |
| 2165 | mHistoryEnd.next = mHistoryCache; |
| 2166 | mHistoryCache = mHistoryEnd; |
| 2167 | mHistoryEnd = mHistoryLastEnd; |
| 2168 | mHistoryLastEnd = null; |
| 2169 | } else { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2170 | mChangedStates |= mHistoryEnd.states^cur.states; |
| 2171 | mChangedStates2 |= mHistoryEnd.states^cur.states2; |
| 2172 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2173 | } |
| 2174 | return; |
| 2175 | } |
| 2176 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2177 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2178 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2179 | |
| 2180 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2181 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2182 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2185 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2186 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2187 | // record changes to the battery level and the most interesting states. |
| 2188 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2189 | // record changes to the battery level. |
| 2190 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2191 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2192 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2193 | || ((mHistoryEnd.states^cur.states) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2194 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2195 | return; |
| 2196 | } |
| 2197 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2198 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2199 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2200 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2201 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2202 | void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
| 2203 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2204 | mHistoryCur.eventCode = code; |
| 2205 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2206 | mHistoryCur.eventTag.string = name; |
| 2207 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2208 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2211 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2212 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2213 | if (rec != null) { |
| 2214 | mHistoryCache = rec.next; |
| 2215 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2216 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2217 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2218 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2219 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2220 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2221 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2222 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2223 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2224 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2225 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2226 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2227 | if (mHistoryEnd != null) { |
| 2228 | mHistoryEnd.next = rec; |
| 2229 | mHistoryEnd = rec; |
| 2230 | } else { |
| 2231 | mHistory = mHistoryEnd = rec; |
| 2232 | } |
| 2233 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2234 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2235 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2236 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2237 | if (USE_OLD_HISTORY) { |
| 2238 | if (mHistory != null) { |
| 2239 | mHistoryEnd.next = mHistoryCache; |
| 2240 | mHistoryCache = mHistory; |
| 2241 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2242 | } |
| 2243 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2244 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2245 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2246 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2247 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2248 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2249 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2250 | |
| 2251 | mHistoryBuffer.setDataSize(0); |
| 2252 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2253 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2254 | mHistoryLastLastWritten.clear(); |
| 2255 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2256 | mHistoryTagPool.clear(); |
| 2257 | mNextHistoryTagIdx = 0; |
| 2258 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2259 | mHistoryBufferLastPos = -1; |
| 2260 | mHistoryOverflow = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2261 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2262 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2263 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2264 | long realtime) { |
| 2265 | if (mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime)) { |
| 2266 | if (unplugged) { |
| 2267 | // Track bt headset ping count |
| 2268 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 2269 | mBluetoothPingCount = 0; |
| 2270 | } else { |
| 2271 | // Track bt headset ping count |
| 2272 | mBluetoothPingCount = getBluetoothPingCount(); |
| 2273 | mBluetoothPingStart = -1; |
| 2274 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2276 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2277 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2278 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2279 | updateKernelWakelocksLocked(); |
| 2280 | requestWakelockCpuUpdate(); |
| 2281 | if (!unpluggedScreenOff) { |
| 2282 | // We are switching to no longer tracking wake locks, but we want |
| 2283 | // the next CPU update we receive to take them in to account. |
| 2284 | mDistributeWakelockCpu = true; |
| 2285 | } |
| 2286 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | } |
| 2288 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2289 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2290 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2291 | mIsolatedUids.put(isolatedUid, appUid); |
| 2292 | } |
| 2293 | |
| 2294 | public void removeIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2295 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2296 | if (curUid == appUid) { |
| 2297 | mIsolatedUids.delete(isolatedUid); |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | public int mapUid(int uid) { |
| 2302 | int isolated = mIsolatedUids.get(uid, -1); |
| 2303 | return isolated > 0 ? isolated : uid; |
| 2304 | } |
| 2305 | |
| 2306 | public void noteEventLocked(int code, String name, int uid) { |
| 2307 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2308 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2309 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2310 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2311 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2312 | final long uptime = SystemClock.uptimeMillis(); |
| 2313 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2314 | } |
| 2315 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2316 | private void requestWakelockCpuUpdate() { |
| 2317 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2318 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2319 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2320 | } |
| 2321 | } |
| 2322 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2323 | public void setRecordAllWakeLocksLocked(boolean enabled) { |
| 2324 | mRecordAllWakeLocks = enabled; |
| 2325 | if (!enabled) { |
| 2326 | // Clear out any existing state. |
| 2327 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
| 2328 | } |
| 2329 | } |
| 2330 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2331 | public void setNoAutoReset(boolean enabled) { |
| 2332 | mNoAutoReset = enabled; |
| 2333 | } |
| 2334 | |
| 2335 | private String mInitialAcquireWakeName; |
| 2336 | private int mInitialAcquireWakeUid = -1; |
| 2337 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2338 | 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] | 2339 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2340 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2341 | if (type == WAKE_TYPE_PARTIAL) { |
| 2342 | // Only care about partial wake locks, since full wake locks |
| 2343 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2344 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame^] | 2345 | if (mRecordAllWakeLocks) { |
| 2346 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, name, uid, 0)) { |
| 2347 | addHistoryEventLocked(elapsedRealtime, uptime, |
| 2348 | HistoryItem.EVENT_WAKE_LOCK_START, name, uid); |
| 2349 | } |
| 2350 | } |
| 2351 | historyName = historyName == null ? name : historyName; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2352 | if (mWakeLockNesting == 0) { |
| 2353 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2354 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 2355 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2356 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2357 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2358 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2359 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2360 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame^] | 2361 | } else if (!mWakeLockImportant && !unimportantForLogging) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2362 | if (mHistoryLastWritten.wakelockTag != null) { |
| 2363 | // We'll try to update the last tag. |
| 2364 | mHistoryLastWritten.wakelockTag = null; |
| 2365 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2366 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2367 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2368 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2369 | } |
| 2370 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2371 | } |
| 2372 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2373 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2374 | if (uid >= 0) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2375 | //if (uid == 0) { |
| 2376 | // Slog.wtf(TAG, "Acquiring wake lock from root: " + name); |
| 2377 | //} |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2378 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2379 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2383 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 2384 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2385 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2386 | if (type == WAKE_TYPE_PARTIAL) { |
| 2387 | mWakeLockNesting--; |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame^] | 2388 | if (mRecordAllWakeLocks) { |
| 2389 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, name, uid, 0)) { |
| 2390 | addHistoryEventLocked(elapsedRealtime, uptime, |
| 2391 | HistoryItem.EVENT_WAKE_LOCK_FINISH, name, uid); |
| 2392 | } |
| 2393 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2394 | if (mWakeLockNesting == 0) { |
| 2395 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2396 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 2397 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2398 | mInitialAcquireWakeName = null; |
| 2399 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2400 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2401 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2402 | } |
| 2403 | if (uid >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2404 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2405 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2406 | } |
| 2407 | } |
| 2408 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2409 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2410 | String historyName, int type, boolean unimportantForLogging) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2411 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2412 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2413 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2414 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2415 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2416 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2420 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 2421 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2422 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
| 2423 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2424 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2425 | // For correct semantics, we start the need worksources first, so that we won't |
| 2426 | // make inappropriate history items as if all wake locks went away and new ones |
| 2427 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2428 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2429 | for (int i=0; i<NN; i++) { |
| 2430 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2431 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2432 | } |
| 2433 | final int NO = ws.size(); |
| 2434 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2435 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2439 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2440 | String historyName, int type) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2441 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2442 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2443 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2444 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2445 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2449 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 2450 | if (mLastWakeupReason != null) { |
| 2451 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
| 2452 | LongSamplingCounter timer = getWakeupReasonCounterLocked(mLastWakeupReason); |
| 2453 | timer.addCountLocked(deltaUptime); |
| 2454 | mLastWakeupReason = null; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | public void noteWakeupReasonLocked(String reason) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2459 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2460 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2461 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2462 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2463 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2464 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 2465 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2466 | mHistoryCur.wakeReasonTag.uid = 0; |
| 2467 | mLastWakeupReason = reason; |
| 2468 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2469 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2470 | } |
| 2471 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2472 | public int startAddingCpuLocked() { |
| 2473 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2474 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2475 | final int N = mPartialTimers.size(); |
| 2476 | if (N == 0) { |
| 2477 | mLastPartialTimers.clear(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2478 | mDistributeWakelockCpu = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2479 | return 0; |
| 2480 | } |
| 2481 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2482 | if (!mOnBatteryScreenOffTimeBase.isRunning() && !mDistributeWakelockCpu) { |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
| 2486 | mDistributeWakelockCpu = false; |
| 2487 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2488 | // How many timers should consume CPU? Only want to include ones |
| 2489 | // that have already been in the list. |
| 2490 | for (int i=0; i<N; i++) { |
| 2491 | StopwatchTimer st = mPartialTimers.get(i); |
| 2492 | if (st.mInList) { |
| 2493 | Uid uid = st.mUid; |
| 2494 | // We don't include the system UID, because it so often |
| 2495 | // holds wake locks at one request or another of an app. |
| 2496 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2497 | return 50; |
| 2498 | } |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | return 0; |
| 2503 | } |
| 2504 | |
| 2505 | public void finishAddingCpuLocked(int perc, int utime, int stime, long[] cpuSpeedTimes) { |
| 2506 | final int N = mPartialTimers.size(); |
| 2507 | if (perc != 0) { |
| 2508 | int num = 0; |
| 2509 | for (int i=0; i<N; i++) { |
| 2510 | StopwatchTimer st = mPartialTimers.get(i); |
| 2511 | if (st.mInList) { |
| 2512 | Uid uid = st.mUid; |
| 2513 | // We don't include the system UID, because it so often |
| 2514 | // holds wake locks at one request or another of an app. |
| 2515 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2516 | num++; |
| 2517 | } |
| 2518 | } |
| 2519 | } |
| 2520 | if (num != 0) { |
| 2521 | for (int i=0; i<N; i++) { |
| 2522 | StopwatchTimer st = mPartialTimers.get(i); |
| 2523 | if (st.mInList) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2524 | Uid uid = st.mUid; |
| 2525 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
Dianne Hackborn | 618b8c1 | 2010-09-09 23:10:38 -0700 | [diff] [blame] | 2526 | int myUTime = utime/num; |
| 2527 | int mySTime = stime/num; |
| 2528 | utime -= myUTime; |
| 2529 | stime -= mySTime; |
| 2530 | num--; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2531 | Uid.Proc proc = uid.getProcessStatsLocked("*wakelock*"); |
| 2532 | proc.addCpuTimeLocked(myUTime, mySTime); |
| 2533 | proc.addSpeedStepTimes(cpuSpeedTimes); |
| 2534 | } |
| 2535 | } |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | // Just in case, collect any lost CPU time. |
| 2540 | if (utime != 0 || stime != 0) { |
| 2541 | Uid uid = getUidStatsLocked(Process.SYSTEM_UID); |
| 2542 | if (uid != null) { |
| 2543 | Uid.Proc proc = uid.getProcessStatsLocked("*lost*"); |
| 2544 | proc.addCpuTimeLocked(utime, stime); |
| 2545 | proc.addSpeedStepTimes(cpuSpeedTimes); |
| 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | final int NL = mLastPartialTimers.size(); |
| 2551 | boolean diff = N != NL; |
| 2552 | for (int i=0; i<NL && !diff; i++) { |
| 2553 | diff |= mPartialTimers.get(i) != mLastPartialTimers.get(i); |
| 2554 | } |
| 2555 | if (!diff) { |
| 2556 | for (int i=0; i<NL; i++) { |
| 2557 | mPartialTimers.get(i).mInList = true; |
| 2558 | } |
| 2559 | return; |
| 2560 | } |
| 2561 | |
| 2562 | for (int i=0; i<NL; i++) { |
| 2563 | mLastPartialTimers.get(i).mInList = false; |
| 2564 | } |
| 2565 | mLastPartialTimers.clear(); |
| 2566 | for (int i=0; i<N; i++) { |
| 2567 | StopwatchTimer st = mPartialTimers.get(i); |
| 2568 | st.mInList = true; |
| 2569 | mLastPartialTimers.add(st); |
| 2570 | } |
| 2571 | } |
| 2572 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2573 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2574 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2575 | Uid u = mUidStats.get(uid); |
| 2576 | if (u != null) { |
| 2577 | u.mPids.remove(pid); |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2582 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2583 | Uid u = mUidStats.get(uid); |
| 2584 | if (u != null) { |
| 2585 | Uid.Pid p = u.mPids.get(pid); |
| 2586 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2587 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | return 0; |
| 2591 | } |
| 2592 | |
| 2593 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2594 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2595 | Uid u = mUidStats.get(uid); |
| 2596 | if (u != null) { |
| 2597 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 2598 | } |
| 2599 | } |
| 2600 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2601 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2602 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2603 | Uid u = mUidStats.get(uid); |
| 2604 | if (u != null) { |
| 2605 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 2606 | } |
| 2607 | } |
| 2608 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2609 | int mSensorNesting; |
| 2610 | |
| 2611 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2612 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2613 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2614 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2615 | if (mSensorNesting == 0) { |
| 2616 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2617 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 2618 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2619 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2620 | } |
| 2621 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2622 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2626 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2627 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2628 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2629 | mSensorNesting--; |
| 2630 | if (mSensorNesting == 0) { |
| 2631 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2632 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 2633 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2634 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2635 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2636 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2639 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2640 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2641 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2642 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2643 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2644 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2645 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2646 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2647 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 2648 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2649 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2650 | } |
| 2651 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2652 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2654 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2655 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2656 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2657 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2658 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2659 | mGpsNesting--; |
| 2660 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2661 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2662 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 2663 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2664 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2665 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2666 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2668 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2669 | public void noteScreenStateLocked(int state) { |
| 2670 | if (mScreenState != state) { |
| 2671 | final int oldState = mScreenState; |
| 2672 | mScreenState = state; |
| 2673 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 2674 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2675 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2676 | if (state == Display.STATE_ON) { |
| 2677 | // Screen turning on. |
| 2678 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2679 | final long uptime = SystemClock.uptimeMillis(); |
| 2680 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 2681 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 2682 | + Integer.toHexString(mHistoryCur.states)); |
| 2683 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2684 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 2685 | if (mScreenBrightnessBin >= 0) { |
| 2686 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 2687 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2688 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2689 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
| 2690 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2691 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2692 | // Fake a wake lock, so we consider the device waked as long |
| 2693 | // as the screen is on. |
| 2694 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 2695 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2696 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2697 | // Update discharge amounts. |
| 2698 | if (mOnBatteryInternal) { |
| 2699 | updateDischargeScreenLevelsLocked(false, true); |
| 2700 | } |
| 2701 | } else if (oldState == Display.STATE_ON) { |
| 2702 | // Screen turning off or dozing. |
| 2703 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2704 | final long uptime = SystemClock.uptimeMillis(); |
| 2705 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 2706 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 2707 | + Integer.toHexString(mHistoryCur.states)); |
| 2708 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2709 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 2710 | if (mScreenBrightnessBin >= 0) { |
| 2711 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 2712 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2713 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2714 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2715 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2716 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2717 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
| 2718 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2719 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2720 | // Update discharge amounts. |
| 2721 | if (mOnBatteryInternal) { |
| 2722 | updateDischargeScreenLevelsLocked(true, false); |
| 2723 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2724 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2725 | } |
| 2726 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2727 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2728 | public void noteScreenBrightnessLocked(int brightness) { |
| 2729 | // Bin the brightness. |
| 2730 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 2731 | if (bin < 0) bin = 0; |
| 2732 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 2733 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2734 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2735 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2736 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 2737 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2738 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 2739 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2740 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2741 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2742 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2743 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2744 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2745 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2746 | } |
| 2747 | mScreenBrightnessBin = bin; |
| 2748 | } |
| 2749 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2750 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2751 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2752 | if (mOnBatteryInternal) { |
| 2753 | uid = mapUid(uid); |
| 2754 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 2755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2757 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2758 | public void noteInteractiveLocked(boolean interactive) { |
| 2759 | if (mInteractive != interactive) { |
| 2760 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2761 | mInteractive = interactive; |
| 2762 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 2763 | if (interactive) { |
| 2764 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 2765 | } else { |
| 2766 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 2767 | } |
| 2768 | } |
| 2769 | } |
| 2770 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2771 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
| 2772 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2773 | final long uptime = SystemClock.uptimeMillis(); |
| 2774 | if (mMobileRadioPowerState != powerState) { |
| 2775 | long realElapsedRealtimeMs; |
| 2776 | final boolean active = |
| 2777 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 2778 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 2779 | if (active) { |
| 2780 | realElapsedRealtimeMs = elapsedRealtime; |
| 2781 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 2782 | } else { |
| 2783 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
| 2784 | long lastUpdateTimeMs = mMobileRadioActiveTimer.getLastUpdateTimeMs(); |
| 2785 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 2786 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 2787 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2788 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2789 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 2790 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 2791 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2792 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2793 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 2794 | } |
| 2795 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 2796 | + Integer.toHexString(mHistoryCur.states)); |
| 2797 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2798 | mMobileRadioPowerState = powerState; |
| 2799 | if (active) { |
| 2800 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 2801 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 2802 | } else { |
| 2803 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
| 2804 | updateNetworkActivityLocked(NET_UPDATE_MOBILE, realElapsedRealtimeMs); |
| 2805 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2806 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2807 | } |
| 2808 | } |
| 2809 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2810 | public void noteLowPowerMode(boolean enabled) { |
| 2811 | if (mLowPowerModeEnabled != enabled) { |
| 2812 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2813 | final long uptime = SystemClock.uptimeMillis(); |
| 2814 | mLowPowerModeEnabled = enabled; |
| 2815 | if (enabled) { |
| 2816 | mHistoryCur.states2 |= HistoryItem.STATE2_LOW_POWER_FLAG; |
| 2817 | if (DEBUG_HISTORY) Slog.v(TAG, "Low power mode enabled to: " |
| 2818 | + Integer.toHexString(mHistoryCur.states2)); |
| 2819 | mLowPowerModeEnabledTimer.startRunningLocked(elapsedRealtime); |
| 2820 | } else { |
| 2821 | mHistoryCur.states2 &= ~HistoryItem.STATE2_LOW_POWER_FLAG; |
| 2822 | if (DEBUG_HISTORY) Slog.v(TAG, "Low power mode disabled to: " |
| 2823 | + Integer.toHexString(mHistoryCur.states2)); |
| 2824 | mLowPowerModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
| 2825 | } |
| 2826 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 2827 | } |
| 2828 | } |
| 2829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2830 | public void notePhoneOnLocked() { |
| 2831 | if (!mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2832 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2833 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2834 | mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2835 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 2836 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2837 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2839 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | } |
| 2841 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | public void notePhoneOffLocked() { |
| 2844 | if (mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2845 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2846 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2847 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2848 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 2849 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2850 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2852 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | } |
| 2854 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2855 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2856 | void stopAllSignalStrengthTimersLocked(int except) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2857 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2858 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2859 | if (i == except) { |
| 2860 | continue; |
| 2861 | } |
| 2862 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2863 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | } |
| 2867 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2868 | private int fixPhoneServiceState(int state, int signalBin) { |
| 2869 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 2870 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 2871 | // to infer that we are scanning from other data. |
| 2872 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2873 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2874 | state = ServiceState.STATE_IN_SERVICE; |
| 2875 | } |
| 2876 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2877 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2878 | return state; |
| 2879 | } |
| 2880 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2881 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2882 | boolean scanning = false; |
| 2883 | boolean newHistory = false; |
| 2884 | |
| 2885 | mPhoneServiceStateRaw = state; |
| 2886 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2887 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 2888 | |
| 2889 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2890 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2891 | |
| 2892 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 2893 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 2894 | // to infer that we are scanning from other data. |
| 2895 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2896 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2897 | state = ServiceState.STATE_IN_SERVICE; |
| 2898 | } |
| 2899 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2900 | |
| 2901 | // If the phone is powered off, stop all timers. |
| 2902 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2903 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2904 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2905 | // If we are in service, make sure the correct signal string timer is running. |
| 2906 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 2907 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2908 | |
| 2909 | // If we're out of service, we are in the lowest signal strength |
| 2910 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2911 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2912 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2913 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2914 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2915 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2916 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2917 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 2918 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2919 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2920 | } |
| 2921 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2922 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2923 | if (!scanning) { |
| 2924 | // If we are no longer scanning, then stop the scanning timer. |
| 2925 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 2926 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 2927 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 2928 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2929 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2930 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2931 | } |
| 2932 | } |
| 2933 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2934 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2935 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 2936 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2937 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2938 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2939 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2940 | mPhoneServiceState = state; |
| 2941 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2942 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2943 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2944 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2945 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2946 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2947 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2948 | if (strengthBin >= 0) { |
| 2949 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2950 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2951 | } |
| 2952 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_SIGNAL_STRENGTH_MASK) |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2953 | | (strengthBin << HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT); |
| 2954 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2955 | + Integer.toHexString(mHistoryCur.states)); |
| 2956 | newHistory = true; |
| 2957 | } else { |
| 2958 | stopAllSignalStrengthTimersLocked(-1); |
| 2959 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2960 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2964 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | /** |
| 2969 | * Telephony stack updates the phone state. |
| 2970 | * @param state phone state from ServiceState.getState() |
| 2971 | */ |
| 2972 | public void notePhoneStateLocked(int state, int simState) { |
| 2973 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2976 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2977 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2978 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2979 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2980 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2981 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2982 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 2983 | int bin = DATA_CONNECTION_NONE; |
| 2984 | if (hasData) { |
| 2985 | switch (dataType) { |
| 2986 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 2987 | bin = DATA_CONNECTION_EDGE; |
| 2988 | break; |
| 2989 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 2990 | bin = DATA_CONNECTION_GPRS; |
| 2991 | break; |
| 2992 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 2993 | bin = DATA_CONNECTION_UMTS; |
| 2994 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2995 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 2996 | bin = DATA_CONNECTION_CDMA; |
| 2997 | break; |
| 2998 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 2999 | bin = DATA_CONNECTION_EVDO_0; |
| 3000 | break; |
| 3001 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3002 | bin = DATA_CONNECTION_EVDO_A; |
| 3003 | break; |
| 3004 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3005 | bin = DATA_CONNECTION_1xRTT; |
| 3006 | break; |
| 3007 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3008 | bin = DATA_CONNECTION_HSDPA; |
| 3009 | break; |
| 3010 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3011 | bin = DATA_CONNECTION_HSUPA; |
| 3012 | break; |
| 3013 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3014 | bin = DATA_CONNECTION_HSPA; |
| 3015 | break; |
| 3016 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3017 | bin = DATA_CONNECTION_IDEN; |
| 3018 | break; |
| 3019 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3020 | bin = DATA_CONNECTION_EVDO_B; |
| 3021 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3022 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3023 | bin = DATA_CONNECTION_LTE; |
| 3024 | break; |
| 3025 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3026 | bin = DATA_CONNECTION_EHRPD; |
| 3027 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3028 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3029 | bin = DATA_CONNECTION_HSPAP; |
| 3030 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3031 | default: |
| 3032 | bin = DATA_CONNECTION_OTHER; |
| 3033 | break; |
| 3034 | } |
| 3035 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3036 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3037 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3038 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3039 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3040 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3041 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3042 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3043 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3044 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3045 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3046 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3047 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3048 | } |
| 3049 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3050 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3051 | } |
| 3052 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3053 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3054 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3055 | if (!mWifiOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3056 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3057 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3058 | mHistoryCur.states |= HistoryItem.STATE_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3059 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3060 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3061 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3062 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3063 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3064 | } |
| 3065 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3066 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3067 | public void noteWifiOffLocked() { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3068 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3069 | final long uptime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3070 | if (mWifiOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3071 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3072 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3073 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3074 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3075 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3076 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3079 | |
| 3080 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3081 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3082 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3083 | final long uptime = SystemClock.uptimeMillis(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3084 | if (!mAudioOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3085 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3086 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3087 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3088 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3089 | mAudioOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3090 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3091 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3092 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3093 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3094 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3095 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3096 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3097 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3098 | final long uptime = SystemClock.uptimeMillis(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3099 | if (mAudioOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3100 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3101 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3102 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3103 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3104 | mAudioOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3105 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3106 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3107 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3111 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3112 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3113 | final long uptime = SystemClock.uptimeMillis(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3114 | if (!mVideoOn) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3115 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3116 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3117 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3118 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3119 | mVideoOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3120 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3121 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3122 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3123 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3124 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3125 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3126 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3127 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3128 | final long uptime = SystemClock.uptimeMillis(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3129 | if (mVideoOn) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3130 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3131 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3132 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3133 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3134 | mVideoOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3135 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3136 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3137 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3140 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3141 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3142 | getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3146 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3147 | getUidStatsLocked(uid).noteActivityPausedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3150 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3151 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3152 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3153 | } |
| 3154 | |
| 3155 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3156 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3157 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3158 | } |
| 3159 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3160 | public void noteWifiRunningLocked(WorkSource ws) { |
| 3161 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3162 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3163 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3164 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3165 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 3166 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3167 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3168 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3169 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3170 | int N = ws.size(); |
| 3171 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3172 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3173 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3174 | } |
| 3175 | } else { |
| 3176 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3180 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 3181 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3182 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3183 | int N = oldWs.size(); |
| 3184 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3185 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3186 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3187 | } |
| 3188 | N = newWs.size(); |
| 3189 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3190 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3191 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3192 | } |
| 3193 | } else { |
| 3194 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 3199 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3200 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3201 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3202 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3203 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 3204 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3205 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3206 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3207 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3208 | int N = ws.size(); |
| 3209 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3210 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3211 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3212 | } |
| 3213 | } else { |
| 3214 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3215 | } |
| 3216 | } |
| 3217 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3218 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 3219 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 3220 | if (mWifiState != wifiState) { |
| 3221 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3222 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3223 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3224 | } |
| 3225 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3226 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3227 | } |
| 3228 | } |
| 3229 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3230 | public void noteBluetoothOnLocked() { |
| 3231 | if (!mBluetoothOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3232 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3233 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3234 | mHistoryCur.states |= HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3235 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth on to: " |
| 3236 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3237 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3238 | mBluetoothOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3239 | mBluetoothOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3240 | } |
| 3241 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3242 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3243 | public void noteBluetoothOffLocked() { |
| 3244 | if (mBluetoothOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3245 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3246 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3247 | mHistoryCur.states &= ~HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3248 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth off to: " |
| 3249 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3250 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3251 | mBluetoothOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3252 | mBluetoothOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3253 | } |
| 3254 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3255 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3256 | public void noteBluetoothStateLocked(int bluetoothState) { |
| 3257 | if (DEBUG) Log.i(TAG, "Bluetooth state -> " + bluetoothState); |
| 3258 | if (mBluetoothState != bluetoothState) { |
| 3259 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3260 | if (mBluetoothState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3261 | mBluetoothStateTimer[mBluetoothState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3262 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3263 | mBluetoothState = bluetoothState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3264 | mBluetoothStateTimer[bluetoothState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3265 | } |
| 3266 | } |
| 3267 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3268 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3269 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3270 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3271 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3272 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3273 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3274 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3275 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3276 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 3277 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3278 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3279 | } |
| 3280 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3281 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3285 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3286 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3287 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3288 | mWifiFullLockNesting--; |
| 3289 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3290 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3291 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 3292 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3293 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3294 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3295 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3298 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3299 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3300 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3301 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3302 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3303 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3304 | if (mWifiScanNesting == 0) { |
| 3305 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3306 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3307 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3308 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3309 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3310 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3311 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3314 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3315 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3316 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3317 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3318 | mWifiScanNesting--; |
| 3319 | if (mWifiScanNesting == 0) { |
| 3320 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3321 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3322 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3323 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3324 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3325 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3326 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3327 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3328 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3329 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3330 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3331 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3335 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3336 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3337 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3340 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3341 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3342 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3343 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3344 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3345 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3346 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3347 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3348 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 3349 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3350 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3351 | } |
| 3352 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3353 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3357 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3358 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3359 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3360 | mWifiMulticastNesting--; |
| 3361 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3362 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3363 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 3364 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3365 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3366 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3367 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3370 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 3371 | int N = ws.size(); |
| 3372 | for (int i=0; i<N; i++) { |
| 3373 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 3378 | int N = ws.size(); |
| 3379 | for (int i=0; i<N; i++) { |
| 3380 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 3381 | } |
| 3382 | } |
| 3383 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3384 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3385 | int N = ws.size(); |
| 3386 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3387 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3388 | } |
| 3389 | } |
| 3390 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3391 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3392 | int N = ws.size(); |
| 3393 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3394 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3395 | } |
| 3396 | } |
| 3397 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3398 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 3399 | int N = ws.size(); |
| 3400 | for (int i=0; i<N; i++) { |
| 3401 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 3406 | int N = ws.size(); |
| 3407 | for (int i=0; i<N; i++) { |
| 3408 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 3409 | } |
| 3410 | } |
| 3411 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3412 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 3413 | int N = ws.size(); |
| 3414 | for (int i=0; i<N; i++) { |
| 3415 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 3420 | int N = ws.size(); |
| 3421 | for (int i=0; i<N; i++) { |
| 3422 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 3423 | } |
| 3424 | } |
| 3425 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3426 | private static String[] includeInStringArray(String[] array, String str) { |
| 3427 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 3428 | return array; |
| 3429 | } |
| 3430 | String[] newArray = new String[array.length+1]; |
| 3431 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 3432 | newArray[array.length] = str; |
| 3433 | return newArray; |
| 3434 | } |
| 3435 | |
| 3436 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 3437 | int index = ArrayUtils.indexOf(array, str); |
| 3438 | if (index >= 0) { |
| 3439 | String[] newArray = new String[array.length-1]; |
| 3440 | if (index > 0) { |
| 3441 | System.arraycopy(array, 0, newArray, 0, index); |
| 3442 | } |
| 3443 | if (index < array.length-1) { |
| 3444 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 3445 | } |
| 3446 | return newArray; |
| 3447 | } |
| 3448 | return array; |
| 3449 | } |
| 3450 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3451 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
| 3452 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3453 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 3454 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3455 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3456 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 3457 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3458 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3459 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3460 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 3461 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3462 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 3463 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 3464 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | public void noteNetworkStatsEnabledLocked() { |
| 3469 | // During device boot, qtaguid isn't enabled until after the inital |
| 3470 | // loading of battery stats. Now that they're enabled, take our initial |
| 3471 | // snapshot for future delta calculation. |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3472 | updateNetworkActivityLocked(NET_UPDATE_ALL, SystemClock.elapsedRealtime()); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3473 | } |
| 3474 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3475 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 3476 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3478 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3479 | @Override public int getScreenOnCount(int which) { |
| 3480 | return mScreenOnTimer.getCountLocked(which); |
| 3481 | } |
| 3482 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3483 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3484 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3485 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3486 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3487 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3488 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3489 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 3490 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3491 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3492 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3493 | @Override public long getLowPowerModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 3494 | return mLowPowerModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 3495 | } |
| 3496 | |
| 3497 | @Override public int getLowPowerModeEnabledCount(int which) { |
| 3498 | return mLowPowerModeEnabledTimer.getCountLocked(which); |
| 3499 | } |
| 3500 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3501 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 3502 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3504 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3505 | @Override public int getPhoneOnCount(int which) { |
| 3506 | return mPhoneOnTimer.getCountLocked(which); |
| 3507 | } |
| 3508 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3509 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3510 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3511 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3512 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3513 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3514 | |
| 3515 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3516 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3517 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3518 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 3521 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 3522 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3523 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3524 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3525 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3526 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3527 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3528 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3529 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3530 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3531 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3532 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3533 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3534 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3535 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 3536 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3537 | } |
| 3538 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3539 | @Override public int getMobileRadioActiveCount(int which) { |
| 3540 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 3541 | } |
| 3542 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3543 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 3544 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 3545 | } |
| 3546 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3547 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 3548 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 3549 | } |
| 3550 | |
| 3551 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 3552 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 3553 | } |
| 3554 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3555 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 3556 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3557 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3558 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3559 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 3560 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3563 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3564 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3565 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3566 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 3570 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 3571 | } |
| 3572 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3573 | @Override public long getBluetoothOnTime(long elapsedRealtimeUs, int which) { |
| 3574 | return mBluetoothOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3575 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3576 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3577 | @Override public long getBluetoothStateTime(int bluetoothState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3578 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3579 | return mBluetoothStateTimer[bluetoothState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3580 | elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3581 | } |
| 3582 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3583 | @Override public int getBluetoothStateCount(int bluetoothState, int which) { |
| 3584 | return mBluetoothStateTimer[bluetoothState].getCountLocked(which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3585 | } |
| 3586 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3587 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3588 | public long getNetworkActivityBytes(int type, int which) { |
| 3589 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 3590 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 3591 | } else { |
| 3592 | return 0; |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | @Override |
| 3597 | public long getNetworkActivityPackets(int type, int which) { |
| 3598 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 3599 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3600 | } else { |
| 3601 | return 0; |
| 3602 | } |
| 3603 | } |
| 3604 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3605 | @Override public long getStartClockTime() { |
| 3606 | return mStartClockTime; |
| 3607 | } |
| 3608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | @Override public boolean getIsOnBattery() { |
| 3610 | return mOnBattery; |
| 3611 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 3614 | return mUidStats; |
| 3615 | } |
| 3616 | |
| 3617 | /** |
| 3618 | * The statistics associated with a particular uid. |
| 3619 | */ |
| 3620 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3623 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3624 | boolean mWifiRunning; |
| 3625 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3626 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3627 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3628 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3629 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3630 | boolean mWifiScanStarted; |
| 3631 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3632 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3633 | private static final int NO_BATCHED_SCAN_STARTED = -1; |
| 3634 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 3635 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 3636 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3637 | boolean mWifiMulticastEnabled; |
| 3638 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3639 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3640 | boolean mAudioTurnedOn; |
| 3641 | StopwatchTimer mAudioTurnedOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3642 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3643 | boolean mVideoTurnedOn; |
| 3644 | StopwatchTimer mVideoTurnedOnTimer; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3645 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3646 | StopwatchTimer mForegroundActivityTimer; |
| 3647 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3648 | BatchTimer mVibratorOnTimer; |
| 3649 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3650 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3651 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3652 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 3653 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3654 | LongSamplingCounter mMobileRadioActiveTime; |
| 3655 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | /** |
| 3658 | * The statistics we have collected for this uid's wake locks. |
| 3659 | */ |
| 3660 | final HashMap<String, Wakelock> mWakelockStats = new HashMap<String, Wakelock>(); |
| 3661 | |
| 3662 | /** |
| 3663 | * The statistics we have collected for this uid's sensor activations. |
| 3664 | */ |
| 3665 | final HashMap<Integer, Sensor> mSensorStats = new HashMap<Integer, Sensor>(); |
| 3666 | |
| 3667 | /** |
| 3668 | * The statistics we have collected for this uid's processes. |
| 3669 | */ |
| 3670 | final HashMap<String, Proc> mProcessStats = new HashMap<String, Proc>(); |
| 3671 | |
| 3672 | /** |
| 3673 | * The statistics we have collected for this uid's processes. |
| 3674 | */ |
| 3675 | final HashMap<String, Pkg> mPackageStats = new HashMap<String, Pkg>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3676 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3677 | /** |
| 3678 | * The transient wake stats we have collected for this uid's pids. |
| 3679 | */ |
| 3680 | final SparseArray<Pid> mPids = new SparseArray<Pid>(); |
| 3681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | public Uid(int uid) { |
| 3683 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3684 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3685 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3686 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3687 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3688 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3689 | mWifiScanTimers, mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3690 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3691 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3692 | mWifiMulticastTimers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | @Override |
| 3696 | public Map<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
| 3697 | return mWakelockStats; |
| 3698 | } |
| 3699 | |
| 3700 | @Override |
| 3701 | public Map<Integer, ? extends BatteryStats.Uid.Sensor> getSensorStats() { |
| 3702 | return mSensorStats; |
| 3703 | } |
| 3704 | |
| 3705 | @Override |
| 3706 | public Map<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
| 3707 | return mProcessStats; |
| 3708 | } |
| 3709 | |
| 3710 | @Override |
| 3711 | public Map<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
| 3712 | return mPackageStats; |
| 3713 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3714 | |
| 3715 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | public int getUid() { |
| 3717 | return mUid; |
| 3718 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3719 | |
| 3720 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3721 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3722 | if (!mWifiRunning) { |
| 3723 | mWifiRunning = true; |
| 3724 | if (mWifiRunningTimer == null) { |
| 3725 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3726 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3727 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3728 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3729 | } |
| 3730 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3731 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3732 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3733 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3734 | if (mWifiRunning) { |
| 3735 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3736 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3737 | } |
| 3738 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3739 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3740 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3741 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3742 | if (!mFullWifiLockOut) { |
| 3743 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3744 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3745 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3746 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3747 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3748 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3749 | } |
| 3750 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3751 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3752 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3753 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3754 | if (mFullWifiLockOut) { |
| 3755 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3756 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3757 | } |
| 3758 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3759 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3760 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3761 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3762 | if (!mWifiScanStarted) { |
| 3763 | mWifiScanStarted = true; |
| 3764 | if (mWifiScanTimer == null) { |
| 3765 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3766 | mWifiScanTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3767 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3768 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3769 | } |
| 3770 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3771 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3772 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3773 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3774 | if (mWifiScanStarted) { |
| 3775 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3776 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3777 | } |
| 3778 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3779 | |
| 3780 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3781 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3782 | int bin = 0; |
| 3783 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS) { |
| 3784 | csph = csph >> 3; |
| 3785 | bin++; |
| 3786 | } |
| 3787 | |
| 3788 | if (mWifiBatchedScanBinStarted == bin) return; |
| 3789 | |
| 3790 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 3791 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3792 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3793 | } |
| 3794 | mWifiBatchedScanBinStarted = bin; |
| 3795 | if (mWifiBatchedScanTimer[bin] == null) { |
| 3796 | makeWifiBatchedScanBin(bin, null); |
| 3797 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3798 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3802 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3803 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 3804 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3805 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3806 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3811 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3812 | if (!mWifiMulticastEnabled) { |
| 3813 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3814 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3815 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3816 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3817 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3818 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3823 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3824 | if (mWifiMulticastEnabled) { |
| 3825 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3826 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3827 | } |
| 3828 | } |
| 3829 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3830 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 3831 | if (mAudioTurnedOnTimer == null) { |
| 3832 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3833 | null, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3834 | } |
| 3835 | return mAudioTurnedOnTimer; |
| 3836 | } |
| 3837 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3838 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3839 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3840 | if (!mAudioTurnedOn) { |
| 3841 | mAudioTurnedOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3842 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3847 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3848 | if (mAudioTurnedOn) { |
| 3849 | mAudioTurnedOn = false; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3850 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3851 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3852 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3853 | } |
| 3854 | } |
| 3855 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3856 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 3857 | if (mVideoTurnedOnTimer == null) { |
| 3858 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3859 | null, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3860 | } |
| 3861 | return mVideoTurnedOnTimer; |
| 3862 | } |
| 3863 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3864 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3865 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3866 | if (!mVideoTurnedOn) { |
| 3867 | mVideoTurnedOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3868 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3873 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3874 | if (mVideoTurnedOn) { |
| 3875 | mVideoTurnedOn = false; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3876 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3877 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3878 | } |
| 3879 | } |
| 3880 | } |
| 3881 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3882 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 3883 | if (mForegroundActivityTimer == null) { |
| 3884 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3885 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3886 | } |
| 3887 | return mForegroundActivityTimer; |
| 3888 | } |
| 3889 | |
| 3890 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3891 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3892 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3893 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3897 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3898 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3899 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3900 | } |
| 3901 | } |
| 3902 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3903 | public BatchTimer createVibratorOnTimerLocked() { |
| 3904 | if (mVibratorOnTimer == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3905 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3906 | } |
| 3907 | return mVibratorOnTimer; |
| 3908 | } |
| 3909 | |
| 3910 | public void noteVibratorOnLocked(long durationMillis) { |
| 3911 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 3912 | } |
| 3913 | |
| 3914 | public void noteVibratorOffLocked() { |
| 3915 | if (mVibratorOnTimer != null) { |
| 3916 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3917 | } |
| 3918 | } |
| 3919 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3920 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3921 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3922 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3923 | return 0; |
| 3924 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3925 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3926 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3927 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3928 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3929 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3930 | if (mFullWifiLockTimer == null) { |
| 3931 | return 0; |
| 3932 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3933 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3934 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3935 | |
| 3936 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3937 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3938 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3939 | return 0; |
| 3940 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3941 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3942 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3943 | |
| 3944 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3945 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3946 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 3947 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 3948 | return 0; |
| 3949 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3950 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3954 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3955 | if (mWifiMulticastTimer == null) { |
| 3956 | return 0; |
| 3957 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3958 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3959 | } |
| 3960 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3961 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3962 | public long getAudioTurnedOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3963 | if (mAudioTurnedOnTimer == null) { |
| 3964 | return 0; |
| 3965 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3966 | return mAudioTurnedOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3969 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3970 | public long getVideoTurnedOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3971 | if (mVideoTurnedOnTimer == null) { |
| 3972 | return 0; |
| 3973 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3974 | return mVideoTurnedOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3977 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3978 | public Timer getForegroundActivityTimer() { |
| 3979 | return mForegroundActivityTimer; |
| 3980 | } |
| 3981 | |
| 3982 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3983 | public Timer getVibratorOnTimer() { |
| 3984 | return mVibratorOnTimer; |
| 3985 | } |
| 3986 | |
| 3987 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3988 | public void noteUserActivityLocked(int type) { |
| 3989 | if (mUserActivityCounters == null) { |
| 3990 | initUserActivityLocked(); |
| 3991 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 3992 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 3993 | mUserActivityCounters[type].stepAtomic(); |
| 3994 | } else { |
| 3995 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 3996 | new Throwable()); |
| 3997 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3998 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3999 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4000 | @Override |
| 4001 | public boolean hasUserActivity() { |
| 4002 | return mUserActivityCounters != null; |
| 4003 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4004 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4005 | @Override |
| 4006 | public int getUserActivityCount(int type, int which) { |
| 4007 | if (mUserActivityCounters == null) { |
| 4008 | return 0; |
| 4009 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4010 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4011 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4012 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4013 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 4014 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 4015 | |
| 4016 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 4017 | if (collected == null) { |
| 4018 | collected = new ArrayList<StopwatchTimer>(); |
| 4019 | mWifiBatchedScanTimers.put(i, collected); |
| 4020 | } |
| 4021 | if (in == null) { |
| 4022 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4023 | mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4024 | } else { |
| 4025 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4026 | mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4031 | void initUserActivityLocked() { |
| 4032 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4033 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4034 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4035 | } |
| 4036 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4037 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4038 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 4039 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4040 | initNetworkActivityLocked(); |
| 4041 | } |
| 4042 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4043 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 4044 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4045 | } else { |
| 4046 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 4047 | new Throwable()); |
| 4048 | } |
| 4049 | } |
| 4050 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4051 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 4052 | if (mNetworkByteActivityCounters == null) { |
| 4053 | initNetworkActivityLocked(); |
| 4054 | } |
| 4055 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 4056 | mMobileRadioActiveCount.addCountLocked(1); |
| 4057 | } |
| 4058 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4059 | @Override |
| 4060 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4061 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4065 | public long getNetworkActivityBytes(int type, int which) { |
| 4066 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 4067 | && type < mNetworkByteActivityCounters.length) { |
| 4068 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4069 | } else { |
| 4070 | return 0; |
| 4071 | } |
| 4072 | } |
| 4073 | |
| 4074 | @Override |
| 4075 | public long getNetworkActivityPackets(int type, int which) { |
| 4076 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 4077 | && type < mNetworkPacketActivityCounters.length) { |
| 4078 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4079 | } else { |
| 4080 | return 0; |
| 4081 | } |
| 4082 | } |
| 4083 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4084 | @Override |
| 4085 | public long getMobileRadioActiveTime(int which) { |
| 4086 | return mMobileRadioActiveTime != null |
| 4087 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 4088 | } |
| 4089 | |
| 4090 | @Override |
| 4091 | public int getMobileRadioActiveCount(int which) { |
| 4092 | return mMobileRadioActiveCount != null |
| 4093 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 4094 | } |
| 4095 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4096 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4097 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 4098 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4099 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4100 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4101 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4102 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4103 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4104 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4105 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4106 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4107 | /** |
| 4108 | * Clear all stats for this uid. Returns true if the uid is completely |
| 4109 | * inactive so can be dropped. |
| 4110 | */ |
| 4111 | boolean reset() { |
| 4112 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4113 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4114 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4115 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4116 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4117 | } |
| 4118 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4119 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4120 | active |= mFullWifiLockOut; |
| 4121 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4122 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4123 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4124 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4125 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4126 | if (mWifiBatchedScanTimer != null) { |
| 4127 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4128 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4129 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 4133 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4134 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4135 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4136 | active |= mWifiMulticastEnabled; |
| 4137 | } |
| 4138 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4139 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4140 | active |= mAudioTurnedOn; |
| 4141 | } |
| 4142 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4143 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4144 | active |= mVideoTurnedOn; |
| 4145 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4146 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4147 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4148 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4149 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4150 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4151 | mVibratorOnTimer.detach(); |
| 4152 | mVibratorOnTimer = null; |
| 4153 | } else { |
| 4154 | active = true; |
| 4155 | } |
| 4156 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4157 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4158 | if (mUserActivityCounters != null) { |
| 4159 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 4160 | mUserActivityCounters[i].reset(false); |
| 4161 | } |
| 4162 | } |
| 4163 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4164 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4165 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4166 | mNetworkByteActivityCounters[i].reset(false); |
| 4167 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4168 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4169 | mMobileRadioActiveTime.reset(false); |
| 4170 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4173 | if (mWakelockStats.size() > 0) { |
| 4174 | Iterator<Map.Entry<String, Wakelock>> it = mWakelockStats.entrySet().iterator(); |
| 4175 | while (it.hasNext()) { |
| 4176 | Map.Entry<String, Wakelock> wakelockEntry = it.next(); |
| 4177 | Wakelock wl = wakelockEntry.getValue(); |
| 4178 | if (wl.reset()) { |
| 4179 | it.remove(); |
| 4180 | } else { |
| 4181 | active = true; |
| 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | if (mSensorStats.size() > 0) { |
| 4186 | Iterator<Map.Entry<Integer, Sensor>> it = mSensorStats.entrySet().iterator(); |
| 4187 | while (it.hasNext()) { |
| 4188 | Map.Entry<Integer, Sensor> sensorEntry = it.next(); |
| 4189 | Sensor s = sensorEntry.getValue(); |
| 4190 | if (s.reset()) { |
| 4191 | it.remove(); |
| 4192 | } else { |
| 4193 | active = true; |
| 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | if (mProcessStats.size() > 0) { |
| 4198 | Iterator<Map.Entry<String, Proc>> it = mProcessStats.entrySet().iterator(); |
| 4199 | while (it.hasNext()) { |
| 4200 | Map.Entry<String, Proc> procEntry = it.next(); |
| 4201 | procEntry.getValue().detach(); |
| 4202 | } |
| 4203 | mProcessStats.clear(); |
| 4204 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4205 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4206 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4207 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4208 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4209 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4210 | } else { |
| 4211 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4212 | } |
| 4213 | } |
| 4214 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4215 | if (mPackageStats.size() > 0) { |
| 4216 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 4217 | while (it.hasNext()) { |
| 4218 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 4219 | Pkg p = pkgEntry.getValue(); |
| 4220 | p.detach(); |
| 4221 | if (p.mServiceStats.size() > 0) { |
| 4222 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 4223 | = p.mServiceStats.entrySet().iterator(); |
| 4224 | while (it2.hasNext()) { |
| 4225 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 4226 | servEntry.getValue().detach(); |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | mPackageStats.clear(); |
| 4231 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4232 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4233 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4234 | if (mWifiRunningTimer != null) { |
| 4235 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4236 | } |
| 4237 | if (mFullWifiLockTimer != null) { |
| 4238 | mFullWifiLockTimer.detach(); |
| 4239 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4240 | if (mWifiScanTimer != null) { |
| 4241 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4242 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4243 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4244 | if (mWifiBatchedScanTimer[i] != null) { |
| 4245 | mWifiBatchedScanTimer[i].detach(); |
| 4246 | } |
| 4247 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4248 | if (mWifiMulticastTimer != null) { |
| 4249 | mWifiMulticastTimer.detach(); |
| 4250 | } |
| 4251 | if (mAudioTurnedOnTimer != null) { |
| 4252 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4253 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4254 | } |
| 4255 | if (mVideoTurnedOnTimer != null) { |
| 4256 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4257 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4258 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4259 | if (mForegroundActivityTimer != null) { |
| 4260 | mForegroundActivityTimer.detach(); |
| 4261 | mForegroundActivityTimer = null; |
| 4262 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4263 | if (mUserActivityCounters != null) { |
| 4264 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 4265 | mUserActivityCounters[i].detach(); |
| 4266 | } |
| 4267 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4268 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4269 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4270 | mNetworkByteActivityCounters[i].detach(); |
| 4271 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4272 | } |
| 4273 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4274 | mPids.clear(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4275 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4276 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4277 | return !active; |
| 4278 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4279 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4280 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | out.writeInt(mWakelockStats.size()); |
| 4282 | for (Map.Entry<String, Uid.Wakelock> wakelockEntry : mWakelockStats.entrySet()) { |
| 4283 | out.writeString(wakelockEntry.getKey()); |
| 4284 | Uid.Wakelock wakelock = wakelockEntry.getValue(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4285 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | out.writeInt(mSensorStats.size()); |
| 4289 | for (Map.Entry<Integer, Uid.Sensor> sensorEntry : mSensorStats.entrySet()) { |
| 4290 | out.writeInt(sensorEntry.getKey()); |
| 4291 | Uid.Sensor sensor = sensorEntry.getValue(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4292 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | out.writeInt(mProcessStats.size()); |
| 4296 | for (Map.Entry<String, Uid.Proc> procEntry : mProcessStats.entrySet()) { |
| 4297 | out.writeString(procEntry.getKey()); |
| 4298 | Uid.Proc proc = procEntry.getValue(); |
| 4299 | proc.writeToParcelLocked(out); |
| 4300 | } |
| 4301 | |
| 4302 | out.writeInt(mPackageStats.size()); |
| 4303 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 4304 | out.writeString(pkgEntry.getKey()); |
| 4305 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 4306 | pkg.writeToParcelLocked(out); |
| 4307 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4308 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4309 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4310 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4311 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4312 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4313 | out.writeInt(0); |
| 4314 | } |
| 4315 | if (mFullWifiLockTimer != null) { |
| 4316 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4317 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4318 | } else { |
| 4319 | out.writeInt(0); |
| 4320 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4321 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4322 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4323 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4324 | } else { |
| 4325 | out.writeInt(0); |
| 4326 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4327 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4328 | if (mWifiBatchedScanTimer[i] != null) { |
| 4329 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4330 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4331 | } else { |
| 4332 | out.writeInt(0); |
| 4333 | } |
| 4334 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4335 | if (mWifiMulticastTimer != null) { |
| 4336 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4337 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4338 | } else { |
| 4339 | out.writeInt(0); |
| 4340 | } |
| 4341 | if (mAudioTurnedOnTimer != null) { |
| 4342 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4343 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4344 | } else { |
| 4345 | out.writeInt(0); |
| 4346 | } |
| 4347 | if (mVideoTurnedOnTimer != null) { |
| 4348 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4349 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4350 | } else { |
| 4351 | out.writeInt(0); |
| 4352 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4353 | if (mForegroundActivityTimer != null) { |
| 4354 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4355 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4356 | } else { |
| 4357 | out.writeInt(0); |
| 4358 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4359 | if (mVibratorOnTimer != null) { |
| 4360 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4361 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4362 | } else { |
| 4363 | out.writeInt(0); |
| 4364 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4365 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4366 | out.writeInt(1); |
| 4367 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 4368 | mUserActivityCounters[i].writeToParcel(out); |
| 4369 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4370 | } else { |
| 4371 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4372 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4373 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4374 | out.writeInt(1); |
| 4375 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4376 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 4377 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4378 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4379 | mMobileRadioActiveTime.writeToParcel(out); |
| 4380 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4381 | } else { |
| 4382 | out.writeInt(0); |
| 4383 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | } |
| 4385 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4386 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | int numWakelocks = in.readInt(); |
| 4388 | mWakelockStats.clear(); |
| 4389 | for (int j = 0; j < numWakelocks; j++) { |
| 4390 | String wakelockName = in.readString(); |
| 4391 | Uid.Wakelock wakelock = new Wakelock(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4392 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 4393 | // We will just drop some random set of wakelocks if |
| 4394 | // the previous run of the system was an older version |
| 4395 | // that didn't impose a limit. |
| 4396 | mWakelockStats.put(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | int numSensors = in.readInt(); |
| 4400 | mSensorStats.clear(); |
| 4401 | for (int k = 0; k < numSensors; k++) { |
| 4402 | int sensorNumber = in.readInt(); |
| 4403 | Uid.Sensor sensor = new Sensor(sensorNumber); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4404 | sensor.readFromParcelLocked(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4405 | mSensorStats.put(sensorNumber, sensor); |
| 4406 | } |
| 4407 | |
| 4408 | int numProcs = in.readInt(); |
| 4409 | mProcessStats.clear(); |
| 4410 | for (int k = 0; k < numProcs; k++) { |
| 4411 | String processName = in.readString(); |
| 4412 | Uid.Proc proc = new Proc(); |
| 4413 | proc.readFromParcelLocked(in); |
| 4414 | mProcessStats.put(processName, proc); |
| 4415 | } |
| 4416 | |
| 4417 | int numPkgs = in.readInt(); |
| 4418 | mPackageStats.clear(); |
| 4419 | for (int l = 0; l < numPkgs; l++) { |
| 4420 | String packageName = in.readString(); |
| 4421 | Uid.Pkg pkg = new Pkg(); |
| 4422 | pkg.readFromParcelLocked(in); |
| 4423 | mPackageStats.put(packageName, pkg); |
| 4424 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4425 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4426 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4427 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4428 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4429 | mWifiRunningTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4430 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4431 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4432 | } |
| 4433 | mFullWifiLockOut = false; |
| 4434 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4435 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4436 | mFullWifiLockTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4437 | } else { |
| 4438 | mFullWifiLockTimer = null; |
| 4439 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4440 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4441 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4442 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4443 | mWifiScanTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4444 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4445 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4446 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4447 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4448 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 4449 | if (in.readInt() != 0) { |
| 4450 | makeWifiBatchedScanBin(i, in); |
| 4451 | } else { |
| 4452 | mWifiBatchedScanTimer[i] = null; |
| 4453 | } |
| 4454 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4455 | mWifiMulticastEnabled = false; |
| 4456 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4457 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4458 | mWifiMulticastTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4459 | } else { |
| 4460 | mWifiMulticastTimer = null; |
| 4461 | } |
| 4462 | mAudioTurnedOn = false; |
| 4463 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4464 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4465 | null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4466 | } else { |
| 4467 | mAudioTurnedOnTimer = null; |
| 4468 | } |
| 4469 | mVideoTurnedOn = false; |
| 4470 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4471 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4472 | null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4473 | } else { |
| 4474 | mVideoTurnedOnTimer = null; |
| 4475 | } |
| 4476 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4477 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4478 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4479 | } else { |
| 4480 | mForegroundActivityTimer = null; |
| 4481 | } |
| 4482 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4483 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4484 | } else { |
| 4485 | mVibratorOnTimer = null; |
| 4486 | } |
| 4487 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4488 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4489 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4490 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4491 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4492 | } else { |
| 4493 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4494 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4495 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4496 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 4497 | mNetworkPacketActivityCounters |
| 4498 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4499 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4500 | mNetworkByteActivityCounters[i] |
| 4501 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 4502 | mNetworkPacketActivityCounters[i] |
| 4503 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4504 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4505 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 4506 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4507 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4508 | mNetworkByteActivityCounters = null; |
| 4509 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | /** |
| 4514 | * The statistics associated with a particular wake lock. |
| 4515 | */ |
| 4516 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 4517 | /** |
| 4518 | * How long (in ms) this uid has been keeping the device partially awake. |
| 4519 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4520 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | |
| 4522 | /** |
| 4523 | * How long (in ms) this uid has been keeping the device fully awake. |
| 4524 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4525 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | |
| 4527 | /** |
| 4528 | * How long (in ms) this uid has had a window keeping the device awake. |
| 4529 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4530 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | |
| 4532 | /** |
| 4533 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 4534 | * proper timer pool from the given BatteryStatsImpl object. |
| 4535 | * |
| 4536 | * @param in the Parcel to be read from. |
| 4537 | * return a new Timer, or null. |
| 4538 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4539 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4540 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | if (in.readInt() == 0) { |
| 4542 | return null; |
| 4543 | } |
| 4544 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4545 | return new StopwatchTimer(Uid.this, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4546 | } |
| 4547 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4548 | boolean reset() { |
| 4549 | boolean wlactive = false; |
| 4550 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4551 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4552 | } |
| 4553 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4554 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4555 | } |
| 4556 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4557 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4558 | } |
| 4559 | if (!wlactive) { |
| 4560 | if (mTimerFull != null) { |
| 4561 | mTimerFull.detach(); |
| 4562 | mTimerFull = null; |
| 4563 | } |
| 4564 | if (mTimerPartial != null) { |
| 4565 | mTimerPartial.detach(); |
| 4566 | mTimerPartial = null; |
| 4567 | } |
| 4568 | if (mTimerWindow != null) { |
| 4569 | mTimerWindow.detach(); |
| 4570 | mTimerWindow = null; |
| 4571 | } |
| 4572 | } |
| 4573 | return !wlactive; |
| 4574 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4575 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4576 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4577 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4578 | mPartialTimers, screenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4580 | mFullTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4582 | mWindowTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | } |
| 4584 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4585 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 4586 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 4587 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 4588 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | @Override |
| 4592 | public Timer getWakeTime(int type) { |
| 4593 | switch (type) { |
| 4594 | case WAKE_TYPE_FULL: return mTimerFull; |
| 4595 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 4596 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
| 4597 | default: throw new IllegalArgumentException("type = " + type); |
| 4598 | } |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 4603 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4604 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4606 | public Sensor(int handle) { |
| 4607 | mHandle = handle; |
| 4608 | } |
| 4609 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4610 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | if (in.readInt() == 0) { |
| 4612 | return null; |
| 4613 | } |
| 4614 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4615 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4616 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4617 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4618 | mSensorTimers.put(mHandle, pool); |
| 4619 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4620 | return new StopwatchTimer(Uid.this, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | } |
| 4622 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4623 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4624 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4625 | mTimer = null; |
| 4626 | return true; |
| 4627 | } |
| 4628 | return false; |
| 4629 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4630 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4631 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 4632 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | } |
| 4634 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4635 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 4636 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | @Override |
| 4640 | public Timer getSensorTime() { |
| 4641 | return mTimer; |
| 4642 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4643 | |
| 4644 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4645 | public int getHandle() { |
| 4646 | return mHandle; |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | /** |
| 4651 | * The statistics associated with a particular process. |
| 4652 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4653 | 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] | 4654 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4655 | * Remains true until removed from the stats. |
| 4656 | */ |
| 4657 | boolean mActive = true; |
| 4658 | |
| 4659 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | * Total time (in 1/100 sec) spent executing in user code. |
| 4661 | */ |
| 4662 | long mUserTime; |
| 4663 | |
| 4664 | /** |
| 4665 | * Total time (in 1/100 sec) spent executing in kernel code. |
| 4666 | */ |
| 4667 | long mSystemTime; |
| 4668 | |
| 4669 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4670 | * Amount of time the process was running in the foreground. |
| 4671 | */ |
| 4672 | long mForegroundTime; |
| 4673 | |
| 4674 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4675 | * Number of times the process has been started. |
| 4676 | */ |
| 4677 | int mStarts; |
| 4678 | |
| 4679 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4680 | * The amount of user time loaded from a previous save. |
| 4681 | */ |
| 4682 | long mLoadedUserTime; |
| 4683 | |
| 4684 | /** |
| 4685 | * The amount of system time loaded from a previous save. |
| 4686 | */ |
| 4687 | long mLoadedSystemTime; |
| 4688 | |
| 4689 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4690 | * The amount of foreground time loaded from a previous save. |
| 4691 | */ |
| 4692 | long mLoadedForegroundTime; |
| 4693 | |
| 4694 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4695 | * The number of times the process has started from a previous save. |
| 4696 | */ |
| 4697 | int mLoadedStarts; |
| 4698 | |
| 4699 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4700 | * The amount of user time loaded from the previous run. |
| 4701 | */ |
| 4702 | long mLastUserTime; |
| 4703 | |
| 4704 | /** |
| 4705 | * The amount of system time loaded from the previous run. |
| 4706 | */ |
| 4707 | long mLastSystemTime; |
| 4708 | |
| 4709 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4710 | * The amount of foreground time loaded from the previous run |
| 4711 | */ |
| 4712 | long mLastForegroundTime; |
| 4713 | |
| 4714 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4715 | * The number of times the process has started from the previous run. |
| 4716 | */ |
| 4717 | int mLastStarts; |
| 4718 | |
| 4719 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | * The amount of user time when last unplugged. |
| 4721 | */ |
| 4722 | long mUnpluggedUserTime; |
| 4723 | |
| 4724 | /** |
| 4725 | * The amount of system time when last unplugged. |
| 4726 | */ |
| 4727 | long mUnpluggedSystemTime; |
| 4728 | |
| 4729 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4730 | * The amount of foreground time since unplugged. |
| 4731 | */ |
| 4732 | long mUnpluggedForegroundTime; |
| 4733 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4734 | /** |
| 4735 | * The number of times the process has started before unplugged. |
| 4736 | */ |
| 4737 | int mUnpluggedStarts; |
| 4738 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4739 | SamplingCounter[] mSpeedBins; |
| 4740 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4741 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4743 | Proc() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4744 | mOnBatteryTimeBase.add(this); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4745 | mSpeedBins = new SamplingCounter[getCpuSpeedSteps()]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4746 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4747 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4748 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | mUnpluggedUserTime = mUserTime; |
| 4750 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4751 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4752 | mUnpluggedStarts = mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | } |
| 4754 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4755 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4757 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4758 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4759 | mActive = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4760 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4761 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 4762 | SamplingCounter c = mSpeedBins[i]; |
| 4763 | if (c != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4764 | mOnBatteryTimeBase.remove(c); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4765 | mSpeedBins[i] = null; |
| 4766 | } |
| 4767 | } |
| 4768 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4769 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4770 | public int countExcessivePowers() { |
| 4771 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4774 | public ExcessivePower getExcessivePower(int i) { |
| 4775 | if (mExcessivePower != null) { |
| 4776 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4777 | } |
| 4778 | return null; |
| 4779 | } |
| 4780 | |
| 4781 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4782 | if (mExcessivePower == null) { |
| 4783 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4784 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4785 | ExcessivePower ew = new ExcessivePower(); |
| 4786 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4787 | ew.overTime = overTime; |
| 4788 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4789 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4790 | } |
| 4791 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4792 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 4793 | if (mExcessivePower == null) { |
| 4794 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 4795 | } |
| 4796 | ExcessivePower ew = new ExcessivePower(); |
| 4797 | ew.type = ExcessivePower.TYPE_CPU; |
| 4798 | ew.overTime = overTime; |
| 4799 | ew.usedTime = usedTime; |
| 4800 | mExcessivePower.add(ew); |
| 4801 | } |
| 4802 | |
| 4803 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 4804 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4805 | out.writeInt(0); |
| 4806 | return; |
| 4807 | } |
| 4808 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4809 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4810 | out.writeInt(N); |
| 4811 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4812 | ExcessivePower ew = mExcessivePower.get(i); |
| 4813 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4814 | out.writeLong(ew.overTime); |
| 4815 | out.writeLong(ew.usedTime); |
| 4816 | } |
| 4817 | } |
| 4818 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 4819 | boolean readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4820 | final int N = in.readInt(); |
| 4821 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4822 | mExcessivePower = null; |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 4823 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4824 | } |
| 4825 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 4826 | if (N > 10000) { |
| 4827 | Slog.w(TAG, "File corrupt: too many excessive power entries " + N); |
| 4828 | return false; |
| 4829 | } |
| 4830 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4831 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4832 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4833 | ExcessivePower ew = new ExcessivePower(); |
| 4834 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4835 | ew.overTime = in.readLong(); |
| 4836 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4837 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4838 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 4839 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | void writeToParcelLocked(Parcel out) { |
| 4843 | out.writeLong(mUserTime); |
| 4844 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4845 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | out.writeInt(mStarts); |
| 4847 | out.writeLong(mLoadedUserTime); |
| 4848 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4849 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4850 | out.writeInt(mLoadedStarts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4851 | out.writeLong(mUnpluggedUserTime); |
| 4852 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4853 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4854 | out.writeInt(mUnpluggedStarts); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4855 | |
| 4856 | out.writeInt(mSpeedBins.length); |
| 4857 | for (int i = 0; i < mSpeedBins.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4858 | SamplingCounter c = mSpeedBins[i]; |
| 4859 | if (c != null) { |
| 4860 | out.writeInt(1); |
| 4861 | c.writeToParcel(out); |
| 4862 | } else { |
| 4863 | out.writeInt(0); |
| 4864 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4865 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4866 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4867 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | void readFromParcelLocked(Parcel in) { |
| 4871 | mUserTime = in.readLong(); |
| 4872 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4873 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4874 | mStarts = in.readInt(); |
| 4875 | mLoadedUserTime = in.readLong(); |
| 4876 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4877 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4879 | mLastUserTime = 0; |
| 4880 | mLastSystemTime = 0; |
| 4881 | mLastForegroundTime = 0; |
| 4882 | mLastStarts = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | mUnpluggedUserTime = in.readLong(); |
| 4884 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4885 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | mUnpluggedStarts = in.readInt(); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4887 | |
| 4888 | int bins = in.readInt(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4889 | int steps = getCpuSpeedSteps(); |
| 4890 | mSpeedBins = new SamplingCounter[bins >= steps ? bins : steps]; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4891 | for (int i = 0; i < bins; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4892 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4893 | mSpeedBins[i] = new SamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4894 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4895 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4896 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4897 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | public BatteryStatsImpl getBatteryStats() { |
| 4901 | return BatteryStatsImpl.this; |
| 4902 | } |
| 4903 | |
| 4904 | public void addCpuTimeLocked(int utime, int stime) { |
| 4905 | mUserTime += utime; |
| 4906 | mSystemTime += stime; |
| 4907 | } |
| 4908 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4909 | public void addForegroundTimeLocked(long ttime) { |
| 4910 | mForegroundTime += ttime; |
| 4911 | } |
| 4912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4913 | public void incStartsLocked() { |
| 4914 | mStarts++; |
| 4915 | } |
| 4916 | |
| 4917 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4918 | public boolean isActive() { |
| 4919 | return mActive; |
| 4920 | } |
| 4921 | |
| 4922 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4923 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 4924 | long val = mUserTime; |
| 4925 | if (which == STATS_CURRENT) { |
| 4926 | val -= mLoadedUserTime; |
| 4927 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4928 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | } |
| 4930 | return val; |
| 4931 | } |
| 4932 | |
| 4933 | @Override |
| 4934 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 4935 | long val = mSystemTime; |
| 4936 | if (which == STATS_CURRENT) { |
| 4937 | val -= mLoadedSystemTime; |
| 4938 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4939 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | } |
| 4941 | return val; |
| 4942 | } |
| 4943 | |
| 4944 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4945 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 4946 | long val = mForegroundTime; |
| 4947 | if (which == STATS_CURRENT) { |
| 4948 | val -= mLoadedForegroundTime; |
| 4949 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4950 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4951 | } |
| 4952 | return val; |
| 4953 | } |
| 4954 | |
| 4955 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4956 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 4957 | int val = mStarts; |
| 4958 | if (which == STATS_CURRENT) { |
| 4959 | val -= mLoadedStarts; |
| 4960 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4961 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | } |
| 4963 | return val; |
| 4964 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4965 | |
| 4966 | /* Called by ActivityManagerService when CPU times are updated. */ |
| 4967 | public void addSpeedStepTimes(long[] values) { |
| 4968 | for (int i = 0; i < mSpeedBins.length && i < values.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4969 | long amt = values[i]; |
| 4970 | if (amt != 0) { |
| 4971 | SamplingCounter c = mSpeedBins[i]; |
| 4972 | if (c == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4973 | mSpeedBins[i] = c = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4974 | } |
| 4975 | c.addCountAtomic(values[i]); |
| 4976 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | @Override |
| 4981 | public long getTimeAtCpuSpeedStep(int speedStep, int which) { |
| 4982 | if (speedStep < mSpeedBins.length) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4983 | SamplingCounter c = mSpeedBins[speedStep]; |
| 4984 | return c != null ? c.getCountLocked(which) : 0; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4985 | } else { |
| 4986 | return 0; |
| 4987 | } |
| 4988 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | /** |
| 4992 | * The statistics associated with a particular package. |
| 4993 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4994 | 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] | 4995 | /** |
| 4996 | * Number of times this package has done something that could wake up the |
| 4997 | * device from sleep. |
| 4998 | */ |
| 4999 | int mWakeups; |
| 5000 | |
| 5001 | /** |
| 5002 | * Number of things that could wake up the device loaded from a |
| 5003 | * previous save. |
| 5004 | */ |
| 5005 | int mLoadedWakeups; |
| 5006 | |
| 5007 | /** |
| 5008 | * Number of things that could wake up the device as of the |
| 5009 | * last run. |
| 5010 | */ |
| 5011 | int mLastWakeups; |
| 5012 | |
| 5013 | /** |
| 5014 | * Number of things that could wake up the device as of the |
| 5015 | * last run. |
| 5016 | */ |
| 5017 | int mUnpluggedWakeups; |
| 5018 | |
| 5019 | /** |
| 5020 | * The statics we have collected for this package's services. |
| 5021 | */ |
| 5022 | final HashMap<String, Serv> mServiceStats = new HashMap<String, Serv>(); |
| 5023 | |
| 5024 | Pkg() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5025 | mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5027 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5028 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5029 | mUnpluggedWakeups = mWakeups; |
| 5030 | } |
| 5031 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5032 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5034 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5035 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5036 | mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5037 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5039 | void readFromParcelLocked(Parcel in) { |
| 5040 | mWakeups = in.readInt(); |
| 5041 | mLoadedWakeups = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5042 | mLastWakeups = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5043 | mUnpluggedWakeups = in.readInt(); |
| 5044 | |
| 5045 | int numServs = in.readInt(); |
| 5046 | mServiceStats.clear(); |
| 5047 | for (int m = 0; m < numServs; m++) { |
| 5048 | String serviceName = in.readString(); |
| 5049 | Uid.Pkg.Serv serv = new Serv(); |
| 5050 | mServiceStats.put(serviceName, serv); |
| 5051 | |
| 5052 | serv.readFromParcelLocked(in); |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | void writeToParcelLocked(Parcel out) { |
| 5057 | out.writeInt(mWakeups); |
| 5058 | out.writeInt(mLoadedWakeups); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5059 | out.writeInt(mUnpluggedWakeups); |
| 5060 | |
| 5061 | out.writeInt(mServiceStats.size()); |
| 5062 | for (Map.Entry<String, Uid.Pkg.Serv> servEntry : mServiceStats.entrySet()) { |
| 5063 | out.writeString(servEntry.getKey()); |
| 5064 | Uid.Pkg.Serv serv = servEntry.getValue(); |
| 5065 | |
| 5066 | serv.writeToParcelLocked(out); |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | @Override |
| 5071 | public Map<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 5072 | return mServiceStats; |
| 5073 | } |
| 5074 | |
| 5075 | @Override |
| 5076 | public int getWakeups(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5077 | int val = mWakeups; |
| 5078 | if (which == STATS_CURRENT) { |
| 5079 | val -= mLoadedWakeups; |
| 5080 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5081 | val -= mUnpluggedWakeups; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5082 | } |
| 5083 | |
| 5084 | return val; |
| 5085 | } |
| 5086 | |
| 5087 | /** |
| 5088 | * The statistics associated with a particular service. |
| 5089 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5090 | 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] | 5091 | /** |
| 5092 | * Total time (ms in battery uptime) the service has been left started. |
| 5093 | */ |
| 5094 | long mStartTime; |
| 5095 | |
| 5096 | /** |
| 5097 | * If service has been started and not yet stopped, this is |
| 5098 | * when it was started. |
| 5099 | */ |
| 5100 | long mRunningSince; |
| 5101 | |
| 5102 | /** |
| 5103 | * True if we are currently running. |
| 5104 | */ |
| 5105 | boolean mRunning; |
| 5106 | |
| 5107 | /** |
| 5108 | * Total number of times startService() has been called. |
| 5109 | */ |
| 5110 | int mStarts; |
| 5111 | |
| 5112 | /** |
| 5113 | * Total time (ms in battery uptime) the service has been left launched. |
| 5114 | */ |
| 5115 | long mLaunchedTime; |
| 5116 | |
| 5117 | /** |
| 5118 | * If service has been launched and not yet exited, this is |
| 5119 | * when it was launched (ms in battery uptime). |
| 5120 | */ |
| 5121 | long mLaunchedSince; |
| 5122 | |
| 5123 | /** |
| 5124 | * True if we are currently launched. |
| 5125 | */ |
| 5126 | boolean mLaunched; |
| 5127 | |
| 5128 | /** |
| 5129 | * Total number times the service has been launched. |
| 5130 | */ |
| 5131 | int mLaunches; |
| 5132 | |
| 5133 | /** |
| 5134 | * The amount of time spent started loaded from a previous save |
| 5135 | * (ms in battery uptime). |
| 5136 | */ |
| 5137 | long mLoadedStartTime; |
| 5138 | |
| 5139 | /** |
| 5140 | * The number of starts loaded from a previous save. |
| 5141 | */ |
| 5142 | int mLoadedStarts; |
| 5143 | |
| 5144 | /** |
| 5145 | * The number of launches loaded from a previous save. |
| 5146 | */ |
| 5147 | int mLoadedLaunches; |
| 5148 | |
| 5149 | /** |
| 5150 | * The amount of time spent started as of the last run (ms |
| 5151 | * in battery uptime). |
| 5152 | */ |
| 5153 | long mLastStartTime; |
| 5154 | |
| 5155 | /** |
| 5156 | * The number of starts as of the last run. |
| 5157 | */ |
| 5158 | int mLastStarts; |
| 5159 | |
| 5160 | /** |
| 5161 | * The number of launches as of the last run. |
| 5162 | */ |
| 5163 | int mLastLaunches; |
| 5164 | |
| 5165 | /** |
| 5166 | * The amount of time spent started when last unplugged (ms |
| 5167 | * in battery uptime). |
| 5168 | */ |
| 5169 | long mUnpluggedStartTime; |
| 5170 | |
| 5171 | /** |
| 5172 | * The number of starts when last unplugged. |
| 5173 | */ |
| 5174 | int mUnpluggedStarts; |
| 5175 | |
| 5176 | /** |
| 5177 | * The number of launches when last unplugged. |
| 5178 | */ |
| 5179 | int mUnpluggedLaunches; |
| 5180 | |
| 5181 | Serv() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5182 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5184 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5185 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 5186 | long baseRealtime) { |
| 5187 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | mUnpluggedStarts = mStarts; |
| 5189 | mUnpluggedLaunches = mLaunches; |
| 5190 | } |
| 5191 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5192 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 5193 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5194 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5195 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5196 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5197 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5198 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | void readFromParcelLocked(Parcel in) { |
| 5201 | mStartTime = in.readLong(); |
| 5202 | mRunningSince = in.readLong(); |
| 5203 | mRunning = in.readInt() != 0; |
| 5204 | mStarts = in.readInt(); |
| 5205 | mLaunchedTime = in.readLong(); |
| 5206 | mLaunchedSince = in.readLong(); |
| 5207 | mLaunched = in.readInt() != 0; |
| 5208 | mLaunches = in.readInt(); |
| 5209 | mLoadedStartTime = in.readLong(); |
| 5210 | mLoadedStarts = in.readInt(); |
| 5211 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5212 | mLastStartTime = 0; |
| 5213 | mLastStarts = 0; |
| 5214 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5215 | mUnpluggedStartTime = in.readLong(); |
| 5216 | mUnpluggedStarts = in.readInt(); |
| 5217 | mUnpluggedLaunches = in.readInt(); |
| 5218 | } |
| 5219 | |
| 5220 | void writeToParcelLocked(Parcel out) { |
| 5221 | out.writeLong(mStartTime); |
| 5222 | out.writeLong(mRunningSince); |
| 5223 | out.writeInt(mRunning ? 1 : 0); |
| 5224 | out.writeInt(mStarts); |
| 5225 | out.writeLong(mLaunchedTime); |
| 5226 | out.writeLong(mLaunchedSince); |
| 5227 | out.writeInt(mLaunched ? 1 : 0); |
| 5228 | out.writeInt(mLaunches); |
| 5229 | out.writeLong(mLoadedStartTime); |
| 5230 | out.writeInt(mLoadedStarts); |
| 5231 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5232 | out.writeLong(mUnpluggedStartTime); |
| 5233 | out.writeInt(mUnpluggedStarts); |
| 5234 | out.writeInt(mUnpluggedLaunches); |
| 5235 | } |
| 5236 | |
| 5237 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 5238 | if (!mLaunched) return mLaunchedTime; |
| 5239 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 5240 | } |
| 5241 | |
| 5242 | long getStartTimeToNowLocked(long batteryUptime) { |
| 5243 | if (!mRunning) return mStartTime; |
| 5244 | return mStartTime + batteryUptime - mRunningSince; |
| 5245 | } |
| 5246 | |
| 5247 | public void startLaunchedLocked() { |
| 5248 | if (!mLaunched) { |
| 5249 | mLaunches++; |
| 5250 | mLaunchedSince = getBatteryUptimeLocked(); |
| 5251 | mLaunched = true; |
| 5252 | } |
| 5253 | } |
| 5254 | |
| 5255 | public void stopLaunchedLocked() { |
| 5256 | if (mLaunched) { |
| 5257 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 5258 | if (time > 0) { |
| 5259 | mLaunchedTime += time; |
| 5260 | } else { |
| 5261 | mLaunches--; |
| 5262 | } |
| 5263 | mLaunched = false; |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | public void startRunningLocked() { |
| 5268 | if (!mRunning) { |
| 5269 | mStarts++; |
| 5270 | mRunningSince = getBatteryUptimeLocked(); |
| 5271 | mRunning = true; |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | public void stopRunningLocked() { |
| 5276 | if (mRunning) { |
| 5277 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 5278 | if (time > 0) { |
| 5279 | mStartTime += time; |
| 5280 | } else { |
| 5281 | mStarts--; |
| 5282 | } |
| 5283 | mRunning = false; |
| 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | public BatteryStatsImpl getBatteryStats() { |
| 5288 | return BatteryStatsImpl.this; |
| 5289 | } |
| 5290 | |
| 5291 | @Override |
| 5292 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5293 | int val = mLaunches; |
| 5294 | if (which == STATS_CURRENT) { |
| 5295 | val -= mLoadedLaunches; |
| 5296 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5297 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5299 | return val; |
| 5300 | } |
| 5301 | |
| 5302 | @Override |
| 5303 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5304 | long val = getStartTimeToNowLocked(now); |
| 5305 | if (which == STATS_CURRENT) { |
| 5306 | val -= mLoadedStartTime; |
| 5307 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5308 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | return val; |
| 5311 | } |
| 5312 | |
| 5313 | @Override |
| 5314 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5315 | int val = mStarts; |
| 5316 | if (which == STATS_CURRENT) { |
| 5317 | val -= mLoadedStarts; |
| 5318 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5319 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | return val; |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | public BatteryStatsImpl getBatteryStats() { |
| 5327 | return BatteryStatsImpl.this; |
| 5328 | } |
| 5329 | |
| 5330 | public void incWakeupsLocked() { |
| 5331 | mWakeups++; |
| 5332 | } |
| 5333 | |
| 5334 | final Serv newServiceStatsLocked() { |
| 5335 | return new Serv(); |
| 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | /** |
| 5340 | * Retrieve the statistics object for a particular process, creating |
| 5341 | * if needed. |
| 5342 | */ |
| 5343 | public Proc getProcessStatsLocked(String name) { |
| 5344 | Proc ps = mProcessStats.get(name); |
| 5345 | if (ps == null) { |
| 5346 | ps = new Proc(); |
| 5347 | mProcessStats.put(name, ps); |
| 5348 | } |
| 5349 | |
| 5350 | return ps; |
| 5351 | } |
| 5352 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5353 | public SparseArray<? extends Pid> getPidStats() { |
| 5354 | return mPids; |
| 5355 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5356 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5357 | public Pid getPidStatsLocked(int pid) { |
| 5358 | Pid p = mPids.get(pid); |
| 5359 | if (p == null) { |
| 5360 | p = new Pid(); |
| 5361 | mPids.put(pid, p); |
| 5362 | } |
| 5363 | return p; |
| 5364 | } |
| 5365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | /** |
| 5367 | * Retrieve the statistics object for a particular service, creating |
| 5368 | * if needed. |
| 5369 | */ |
| 5370 | public Pkg getPackageStatsLocked(String name) { |
| 5371 | Pkg ps = mPackageStats.get(name); |
| 5372 | if (ps == null) { |
| 5373 | ps = new Pkg(); |
| 5374 | mPackageStats.put(name, ps); |
| 5375 | } |
| 5376 | |
| 5377 | return ps; |
| 5378 | } |
| 5379 | |
| 5380 | /** |
| 5381 | * Retrieve the statistics object for a particular service, creating |
| 5382 | * if needed. |
| 5383 | */ |
| 5384 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 5385 | Pkg ps = getPackageStatsLocked(pkg); |
| 5386 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 5387 | if (ss == null) { |
| 5388 | ss = ps.newServiceStatsLocked(); |
| 5389 | ps.mServiceStats.put(serv, ss); |
| 5390 | } |
| 5391 | |
| 5392 | return ss; |
| 5393 | } |
| 5394 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5395 | public StopwatchTimer getWakeTimerLocked(String name, int type) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | Wakelock wl = mWakelockStats.get(name); |
| 5397 | if (wl == null) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 5398 | final int N = mWakelockStats.size(); |
Dianne Hackborn | af17baa | 2013-05-09 15:27:47 -0700 | [diff] [blame] | 5399 | if (N > MAX_WAKELOCKS_PER_UID) { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 5400 | name = BATCHED_WAKELOCK_NAME; |
| 5401 | wl = mWakelockStats.get(name); |
| 5402 | } |
| 5403 | if (wl == null) { |
| 5404 | wl = new Wakelock(); |
| 5405 | mWakelockStats.put(name, wl); |
| 5406 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5407 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5408 | StopwatchTimer t = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5409 | switch (type) { |
| 5410 | case WAKE_TYPE_PARTIAL: |
| 5411 | t = wl.mTimerPartial; |
| 5412 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5413 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5414 | mPartialTimers, mOnBatteryScreenOffTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5415 | wl.mTimerPartial = t; |
| 5416 | } |
| 5417 | return t; |
| 5418 | case WAKE_TYPE_FULL: |
| 5419 | t = wl.mTimerFull; |
| 5420 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5421 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5422 | mFullTimers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5423 | wl.mTimerFull = t; |
| 5424 | } |
| 5425 | return t; |
| 5426 | case WAKE_TYPE_WINDOW: |
| 5427 | t = wl.mTimerWindow; |
| 5428 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5429 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5430 | mWindowTimers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | wl.mTimerWindow = t; |
| 5432 | } |
| 5433 | return t; |
| 5434 | default: |
| 5435 | throw new IllegalArgumentException("type=" + type); |
| 5436 | } |
| 5437 | } |
| 5438 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5439 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | Sensor se = mSensorStats.get(sensor); |
| 5441 | if (se == null) { |
| 5442 | if (!create) { |
| 5443 | return null; |
| 5444 | } |
| 5445 | se = new Sensor(sensor); |
| 5446 | mSensorStats.put(sensor, se); |
| 5447 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5448 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5449 | if (t != null) { |
| 5450 | return t; |
| 5451 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5452 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5453 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5454 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5455 | mSensorTimers.put(sensor, timers); |
| 5456 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5457 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5458 | se.mTimer = t; |
| 5459 | return t; |
| 5460 | } |
| 5461 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5462 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5463 | StopwatchTimer t = getWakeTimerLocked(name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5464 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5465 | t.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 5467 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5468 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5469 | if (p.mWakeNesting++ == 0) { |
| 5470 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 5471 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5472 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5473 | } |
| 5474 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5475 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5476 | StopwatchTimer t = getWakeTimerLocked(name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5478 | t.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5479 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 5480 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5481 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5482 | if (p != null && p.mWakeNesting > 0) { |
| 5483 | if (p.mWakeNesting-- == 1) { |
| 5484 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 5485 | p.mWakeStartMs = 0; |
| 5486 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5487 | } |
| 5488 | } |
| 5489 | } |
| 5490 | |
| 5491 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 5492 | Proc p = getProcessStatsLocked(proc); |
| 5493 | if (p != null) { |
| 5494 | p.addExcessiveWake(overTime, usedTime); |
| 5495 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5497 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5498 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 5499 | Proc p = getProcessStatsLocked(proc); |
| 5500 | if (p != null) { |
| 5501 | p.addExcessiveCpu(overTime, usedTime); |
| 5502 | } |
| 5503 | } |
| 5504 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5505 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5506 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5508 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | } |
| 5511 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5512 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5514 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5516 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5518 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5519 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5520 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5521 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5523 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5524 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5525 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5526 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5527 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5528 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5530 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5531 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | public BatteryStatsImpl getBatteryStats() { |
| 5535 | return BatteryStatsImpl.this; |
| 5536 | } |
| 5537 | } |
| 5538 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 5539 | public BatteryStatsImpl(String filename, Handler handler) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5540 | mFile = new JournaledFile(new File(filename), new File(filename + ".tmp")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 5541 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5542 | mStartCount++; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5543 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5544 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5545 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5546 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 5547 | mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5548 | mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase); |
| 5549 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5550 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5551 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, |
| 5552 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5553 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5554 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5555 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5556 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, |
| 5557 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5558 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5559 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5560 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5561 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5562 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5563 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); |
| 5564 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5565 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5566 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5567 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5568 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase); |
| 5569 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5570 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5571 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5572 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5573 | mBluetoothOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5574 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5575 | mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5576 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5577 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
| 5578 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5580 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 5581 | long realtime = SystemClock.elapsedRealtime() * 1000; |
| 5582 | initTimes(uptime, realtime); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5583 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5584 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5585 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5586 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5587 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5588 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5589 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5593 | mFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5594 | mHandler = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5595 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5596 | readFromParcel(p); |
| 5597 | } |
| 5598 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5599 | public void setCallback(BatteryCallback cb) { |
| 5600 | mCallback = cb; |
| 5601 | } |
| 5602 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5603 | public void setNumSpeedSteps(int steps) { |
| 5604 | if (sNumSpeedSteps == 0) sNumSpeedSteps = steps; |
| 5605 | } |
| 5606 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5607 | public void setRadioScanningTimeout(long timeout) { |
| 5608 | if (mPhoneSignalScanningTimer != null) { |
| 5609 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 5610 | } |
| 5611 | } |
| 5612 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5613 | @Override |
| 5614 | public boolean startIteratingOldHistoryLocked() { |
| 5615 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 5616 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5617 | if ((mHistoryIterator = mHistory) == null) { |
| 5618 | return false; |
| 5619 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5620 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 5621 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5622 | mReadOverflow = false; |
| 5623 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5624 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5625 | } |
| 5626 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5627 | @Override |
| 5628 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 5629 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 5630 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5631 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 5632 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5633 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5634 | HistoryItem cur = mHistoryIterator; |
| 5635 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5636 | if (!mReadOverflow && !end) { |
| 5637 | Slog.w(TAG, "Old history ends before new history!"); |
| 5638 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5639 | return false; |
| 5640 | } |
| 5641 | out.setTo(cur); |
| 5642 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5643 | if (!mReadOverflow) { |
| 5644 | if (end) { |
| 5645 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 5646 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 5647 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5648 | pw.println("Histories differ!"); |
| 5649 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5650 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5651 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5652 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 5653 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 5654 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5655 | } |
| 5656 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5657 | return true; |
| 5658 | } |
| 5659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5661 | public void finishIteratingOldHistoryLocked() { |
| 5662 | mIteratingHistory = false; |
| 5663 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5664 | mHistoryIterator = null; |
| 5665 | } |
| 5666 | |
| 5667 | public int getHistoryTotalSize() { |
| 5668 | return MAX_HISTORY_BUFFER; |
| 5669 | } |
| 5670 | |
| 5671 | public int getHistoryUsedSize() { |
| 5672 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5673 | } |
| 5674 | |
| 5675 | @Override |
| 5676 | public boolean startIteratingHistoryLocked() { |
| 5677 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 5678 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 5679 | if (mHistoryBuffer.dataSize() <= 0) { |
| 5680 | return false; |
| 5681 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5682 | mHistoryBuffer.setDataPosition(0); |
| 5683 | mReadOverflow = false; |
| 5684 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5685 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 5686 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 5687 | mReadHistoryChars = 0; |
| 5688 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 5689 | final HistoryTag tag = ent.getKey(); |
| 5690 | final int idx = ent.getValue(); |
| 5691 | mReadHistoryStrings[idx] = tag.string; |
| 5692 | mReadHistoryUids[idx] = tag.uid; |
| 5693 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5694 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 5695 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5699 | public int getHistoryStringPoolSize() { |
| 5700 | return mReadHistoryStrings.length; |
| 5701 | } |
| 5702 | |
| 5703 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5704 | public int getHistoryStringPoolBytes() { |
| 5705 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 5706 | // Each string character is 2 bytes. |
| 5707 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 5708 | } |
| 5709 | |
| 5710 | @Override |
| 5711 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5712 | return mReadHistoryStrings[index]; |
| 5713 | } |
| 5714 | |
| 5715 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5716 | public int getHistoryTagPoolUid(int index) { |
| 5717 | return mReadHistoryUids[index]; |
| 5718 | } |
| 5719 | |
| 5720 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5721 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 5722 | final int pos = mHistoryBuffer.dataPosition(); |
| 5723 | if (pos == 0) { |
| 5724 | out.clear(); |
| 5725 | } |
| 5726 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5727 | if (end) { |
| 5728 | return false; |
| 5729 | } |
| 5730 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5731 | final long lastRealtime = out.time; |
| 5732 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5733 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5734 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 5735 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5736 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 5737 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5738 | return true; |
| 5739 | } |
| 5740 | |
| 5741 | @Override |
| 5742 | public void finishIteratingHistoryLocked() { |
| 5743 | mIteratingHistory = false; |
| 5744 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5745 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5746 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5747 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5748 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5749 | public long getHistoryBaseTime() { |
| 5750 | return mHistoryBaseTime; |
| 5751 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5752 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5753 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5754 | public int getStartCount() { |
| 5755 | return mStartCount; |
| 5756 | } |
| 5757 | |
| 5758 | public boolean isOnBattery() { |
| 5759 | return mOnBattery; |
| 5760 | } |
| 5761 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5762 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5763 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5766 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5767 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5768 | mOnBatteryTimeBase.init(uptime, realtime); |
| 5769 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5770 | mRealtime = 0; |
| 5771 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5772 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 5773 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5774 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5775 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5776 | void initDischarge() { |
| 5777 | mLowDischargeAmountSinceCharge = 0; |
| 5778 | mHighDischargeAmountSinceCharge = 0; |
| 5779 | mDischargeAmountScreenOn = 0; |
| 5780 | mDischargeAmountScreenOnSinceCharge = 0; |
| 5781 | mDischargeAmountScreenOff = 0; |
| 5782 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 5783 | mLastDischargeStepTime = -1; |
| 5784 | mNumDischargeStepDurations = 0; |
| 5785 | mLastChargeStepTime = -1; |
| 5786 | mNumChargeStepDurations = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5787 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 5788 | |
| 5789 | public void resetAllStatsCmdLocked() { |
| 5790 | resetAllStatsLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5791 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 5792 | long uptime = mSecUptime * 1000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 5793 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 5794 | long realtime = mSecRealtime * 1000; |
| 5795 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 5796 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5797 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5798 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 5799 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5800 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 5801 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 5802 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5803 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 5804 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 5805 | mDischargeScreenOffUnplugLevel = 0; |
| 5806 | } else { |
| 5807 | mDischargeScreenOnUnplugLevel = 0; |
| 5808 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 5809 | } |
| 5810 | mDischargeAmountScreenOn = 0; |
| 5811 | mDischargeAmountScreenOff = 0; |
| 5812 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5813 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5817 | mStartCount = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5818 | initTimes(SystemClock.uptimeMillis() * 1000, SystemClock.elapsedRealtime() * 1000); |
| 5819 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5820 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5821 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5822 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5823 | mInteractiveTimer.reset(false); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5824 | mLowPowerModeEnabledTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5825 | mPhoneOnTimer.reset(false); |
| 5826 | mAudioOnTimer.reset(false); |
| 5827 | mVideoOnTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5828 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5829 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5830 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5831 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5832 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5833 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5834 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5835 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5836 | mNetworkByteActivityCounters[i].reset(false); |
| 5837 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5838 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5839 | mMobileRadioActiveTimer.reset(false); |
| 5840 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5841 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5842 | mMobileRadioActiveUnknownTime.reset(false); |
| 5843 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5844 | mWifiOnTimer.reset(false); |
| 5845 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5846 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5847 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5848 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5849 | mBluetoothOnTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5850 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5851 | mBluetoothStateTimer[i].reset(false); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5852 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5853 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5854 | for (int i=0; i<mUidStats.size(); i++) { |
| 5855 | if (mUidStats.valueAt(i).reset()) { |
| 5856 | mUidStats.remove(mUidStats.keyAt(i)); |
| 5857 | i--; |
| 5858 | } |
| 5859 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5860 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5861 | if (mKernelWakelockStats.size() > 0) { |
| 5862 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5863 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5864 | } |
| 5865 | mKernelWakelockStats.clear(); |
| 5866 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5867 | |
| 5868 | if (mWakeupReasonStats.size() > 0) { |
| 5869 | for (LongSamplingCounter timer : mWakeupReasonStats.values()) { |
| 5870 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 5871 | } |
| 5872 | mWakeupReasonStats.clear(); |
| 5873 | } |
| 5874 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5875 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5876 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5877 | clearHistoryLocked(); |
| 5878 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5879 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5880 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5881 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5882 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5883 | if (active == null) { |
| 5884 | continue; |
| 5885 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5886 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 5887 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5888 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5889 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 5890 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | } |
| 5894 | } |
| 5895 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5896 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5897 | if (oldScreenOn) { |
| 5898 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 5899 | if (diff > 0) { |
| 5900 | mDischargeAmountScreenOn += diff; |
| 5901 | mDischargeAmountScreenOnSinceCharge += diff; |
| 5902 | } |
| 5903 | } else { |
| 5904 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 5905 | if (diff > 0) { |
| 5906 | mDischargeAmountScreenOff += diff; |
| 5907 | mDischargeAmountScreenOffSinceCharge += diff; |
| 5908 | } |
| 5909 | } |
| 5910 | if (newScreenOn) { |
| 5911 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 5912 | mDischargeScreenOffUnplugLevel = 0; |
| 5913 | } else { |
| 5914 | mDischargeScreenOnUnplugLevel = 0; |
| 5915 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 5916 | } |
| 5917 | } |
| 5918 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5919 | public void pullPendingStateUpdatesLocked() { |
| 5920 | updateKernelWakelocksLocked(); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5921 | updateNetworkActivityLocked(NET_UPDATE_ALL, SystemClock.elapsedRealtime()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5922 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5923 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 5924 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5925 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5926 | } |
| 5927 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5928 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 5929 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5930 | boolean doWrite = false; |
| 5931 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 5932 | m.arg1 = onBattery ? 1 : 0; |
| 5933 | mHandler.sendMessage(m); |
| 5934 | mOnBattery = mOnBatteryInternal = onBattery; |
| 5935 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5936 | final long uptime = mSecUptime * 1000; |
| 5937 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5938 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5939 | if (onBattery) { |
| 5940 | // We will reset our status if we are unplugging after the |
| 5941 | // battery was last full, or the level is at 100, or |
| 5942 | // we have gone through a significant charge (from a very low |
| 5943 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5944 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 5945 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5946 | || level >= 90 |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 5947 | || (mDischargeCurrentLevel < 20 && level >= 80))) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5948 | doWrite = true; |
| 5949 | resetAllStatsLocked(); |
| 5950 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5951 | reset = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 5952 | mNumDischargeStepDurations = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5953 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 5954 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 5955 | mMinDischargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 5956 | mLastDischargeStepTime = -1; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5957 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5958 | mHistoryCur.batteryLevel = (byte)level; |
| 5959 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 5960 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 5961 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5962 | if (reset) { |
| 5963 | mRecordingHistory = true; |
| 5964 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 5965 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5966 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5967 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5968 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5969 | mDischargeScreenOnUnplugLevel = level; |
| 5970 | mDischargeScreenOffUnplugLevel = 0; |
| 5971 | } else { |
| 5972 | mDischargeScreenOnUnplugLevel = 0; |
| 5973 | mDischargeScreenOffUnplugLevel = level; |
| 5974 | } |
| 5975 | mDischargeAmountScreenOn = 0; |
| 5976 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5977 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5978 | } else { |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 5979 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5980 | mHistoryCur.batteryLevel = (byte)level; |
| 5981 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 5982 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 5983 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5984 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5985 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5986 | if (level < mDischargeUnplugLevel) { |
| 5987 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 5988 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 5989 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5990 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 5991 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 5992 | mNumChargeStepDurations = 0; |
| 5993 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 5994 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 5995 | mLastChargeStepTime = -1; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 5996 | } |
| 5997 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 5998 | if (mFile != null) { |
| 5999 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | } |
| 6001 | } |
| 6002 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6003 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6004 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 6005 | boolean reset) { |
| 6006 | mRecordingHistory = true; |
| 6007 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6008 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 6009 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6010 | mHistoryCur); |
| 6011 | mHistoryCur.currentTime = 0; |
| 6012 | if (reset) { |
| 6013 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 6014 | } |
| 6015 | } |
| 6016 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6017 | // This should probably be exposed in the API, though it's not critical |
| 6018 | private static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6019 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6020 | private static int addLevelSteps(long[] steps, int stepCount, long lastStepTime, |
| 6021 | int numStepLevels, long elapsedRealtime) { |
| 6022 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 6023 | long duration = elapsedRealtime - lastStepTime; |
| 6024 | for (int i=0; i<numStepLevels; i++) { |
| 6025 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 6026 | long thisDuration = duration / (numStepLevels-i); |
| 6027 | duration -= thisDuration; |
| 6028 | steps[0] = thisDuration; |
| 6029 | } |
| 6030 | stepCount += numStepLevels; |
| 6031 | if (stepCount > steps.length) { |
| 6032 | stepCount = steps.length; |
| 6033 | } |
| 6034 | } |
| 6035 | return stepCount; |
| 6036 | } |
| 6037 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6038 | public void setBatteryState(int status, int health, int plugType, int level, |
| 6039 | int temp, int volt) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6040 | synchronized(this) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6041 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 6042 | final long uptime = SystemClock.uptimeMillis(); |
| 6043 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6044 | int oldStatus = mHistoryCur.batteryStatus; |
| 6045 | if (!mHaveBatteryLevel) { |
| 6046 | mHaveBatteryLevel = true; |
| 6047 | // We start out assuming that the device is plugged in (not |
| 6048 | // on battery). If our first report is now that we are indeed |
| 6049 | // plugged in, then twiddle our state to correctly reflect that |
| 6050 | // since we won't be going through the full setOnBattery(). |
| 6051 | if (onBattery == mOnBattery) { |
| 6052 | if (onBattery) { |
| 6053 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 6054 | } else { |
| 6055 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 6056 | } |
| 6057 | } |
| 6058 | oldStatus = status; |
| 6059 | } |
| 6060 | if (onBattery) { |
| 6061 | mDischargeCurrentLevel = level; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6062 | if (!mRecordingHistory) { |
| 6063 | mRecordingHistory = true; |
| 6064 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 6065 | } |
| 6066 | } else if (level < 96) { |
| 6067 | if (!mRecordingHistory) { |
| 6068 | mRecordingHistory = true; |
| 6069 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 6070 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6071 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6072 | mCurrentBatteryLevel = level; |
| 6073 | if (mDischargePlugLevel < 0) { |
| 6074 | mDischargePlugLevel = level; |
| 6075 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6076 | if (onBattery != mOnBattery) { |
| 6077 | mHistoryCur.batteryLevel = (byte)level; |
| 6078 | mHistoryCur.batteryStatus = (byte)status; |
| 6079 | mHistoryCur.batteryHealth = (byte)health; |
| 6080 | mHistoryCur.batteryPlugType = (byte)plugType; |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 6081 | mHistoryCur.batteryTemperature = (short)temp; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6082 | mHistoryCur.batteryVoltage = (char)volt; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6083 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6084 | } else { |
| 6085 | boolean changed = false; |
| 6086 | if (mHistoryCur.batteryLevel != level) { |
| 6087 | mHistoryCur.batteryLevel = (byte)level; |
| 6088 | changed = true; |
| 6089 | } |
| 6090 | if (mHistoryCur.batteryStatus != status) { |
| 6091 | mHistoryCur.batteryStatus = (byte)status; |
| 6092 | changed = true; |
| 6093 | } |
| 6094 | if (mHistoryCur.batteryHealth != health) { |
| 6095 | mHistoryCur.batteryHealth = (byte)health; |
| 6096 | changed = true; |
| 6097 | } |
| 6098 | if (mHistoryCur.batteryPlugType != plugType) { |
| 6099 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 6100 | changed = true; |
| 6101 | } |
| 6102 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 6103 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 6104 | mHistoryCur.batteryTemperature = (short)temp; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6105 | changed = true; |
| 6106 | } |
| 6107 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 6108 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 6109 | mHistoryCur.batteryVoltage = (char)volt; |
| 6110 | changed = true; |
| 6111 | } |
| 6112 | if (changed) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6113 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6114 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6115 | if (onBattery) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6116 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6117 | mNumDischargeStepDurations = addLevelSteps(mDischargeStepDurations, |
| 6118 | mNumDischargeStepDurations, mLastDischargeStepTime, |
| 6119 | mLastDischargeStepLevel - level, elapsedRealtime); |
| 6120 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6121 | mMinDischargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6122 | mLastDischargeStepTime = elapsedRealtime; |
| 6123 | } |
| 6124 | } else { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6125 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6126 | mNumChargeStepDurations = addLevelSteps(mChargeStepDurations, |
| 6127 | mNumChargeStepDurations, mLastChargeStepTime, |
| 6128 | level - mLastChargeStepLevel, elapsedRealtime); |
| 6129 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 6130 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6131 | mLastChargeStepTime = elapsedRealtime; |
| 6132 | } |
| 6133 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6134 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 6135 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 6136 | // We don't record history while we are plugged in and fully charged. |
| 6137 | // The next time we are unplugged, history will be cleared. |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 6138 | mRecordingHistory = DEBUG; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6139 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6140 | } |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6141 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6142 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6143 | public void updateKernelWakelocksLocked() { |
| 6144 | Map<String, KernelWakelockStats> m = readKernelWakelockStats(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6145 | |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 6146 | if (m == null) { |
| 6147 | // Not crashing might make board bringup easier. |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6148 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 6149 | return; |
| 6150 | } |
| 6151 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6152 | for (Map.Entry<String, KernelWakelockStats> ent : m.entrySet()) { |
| 6153 | String name = ent.getKey(); |
| 6154 | KernelWakelockStats kws = ent.getValue(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6155 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6156 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 6157 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6158 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, |
| 6159 | true /* track reported val */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6160 | mKernelWakelockStats.put(name, kwlt); |
| 6161 | } |
| 6162 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 6163 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 6164 | kwlt.setUpdateVersion(sKernelWakelockUpdateVersion); |
| 6165 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6166 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6167 | if (m.size() != mKernelWakelockStats.size()) { |
| 6168 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 6169 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 6170 | SamplingTimer st = ent.getValue(); |
| 6171 | if (st.getUpdateVersion() != sKernelWakelockUpdateVersion) { |
| 6172 | st.setStale(); |
| 6173 | } |
| 6174 | } |
| 6175 | } |
| 6176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6177 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6178 | static final int NET_UPDATE_MOBILE = 1<<0; |
| 6179 | static final int NET_UPDATE_WIFI = 1<<1; |
| 6180 | static final int NET_UPDATE_ALL = 0xffff; |
| 6181 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6182 | private void updateNetworkActivityLocked(int which, long elapsedRealtimeMs) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6183 | if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) return; |
| 6184 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6185 | if ((which&NET_UPDATE_MOBILE) != 0 && mMobileIfaces.length > 0) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6186 | final NetworkStats snapshot; |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6187 | final NetworkStats last = mCurMobileSnapshot; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6188 | try { |
| 6189 | snapshot = mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL, |
| 6190 | mMobileIfaces, NetworkStats.TAG_NONE, mLastMobileSnapshot); |
| 6191 | } catch (IOException e) { |
| 6192 | Log.wtf(TAG, "Failed to read mobile network stats", e); |
| 6193 | return; |
| 6194 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6195 | |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6196 | mCurMobileSnapshot = snapshot; |
| 6197 | mLastMobileSnapshot = last; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6198 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6199 | if (mOnBatteryInternal) { |
| 6200 | final NetworkStats delta = NetworkStats.subtract(snapshot, last, |
| 6201 | null, null, mTmpNetworkStats); |
| 6202 | mTmpNetworkStats = delta; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6203 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6204 | long radioTime = mMobileRadioActivePerAppTimer.checkpointRunningLocked( |
| 6205 | elapsedRealtimeMs); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6206 | long totalPackets = delta.getTotalPackets(); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6207 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6208 | final int size = delta.size(); |
| 6209 | for (int i = 0; i < size; i++) { |
| 6210 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6211 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6212 | if (entry.rxBytes == 0 || entry.txBytes == 0) continue; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6213 | |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6214 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6215 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 6216 | entry.rxPackets); |
| 6217 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 6218 | entry.txPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6219 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6220 | if (radioTime > 0) { |
| 6221 | // Distribute total radio active time in to this app. |
| 6222 | long appPackets = entry.rxPackets + entry.txPackets; |
| 6223 | long appRadioTime = (radioTime*appPackets)/totalPackets; |
| 6224 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 6225 | // Remove this app from the totals, so that we don't lose any time |
| 6226 | // due to rounding. |
| 6227 | radioTime -= appRadioTime; |
| 6228 | totalPackets -= appPackets; |
| 6229 | } |
| 6230 | |
| 6231 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 6232 | entry.rxBytes); |
| 6233 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 6234 | entry.txBytes); |
| 6235 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 6236 | entry.rxPackets); |
| 6237 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 6238 | entry.txPackets); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6239 | } |
| 6240 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6241 | if (radioTime > 0) { |
| 6242 | // Whoops, there is some radio time we can't blame on an app! |
| 6243 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 6244 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 6245 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6246 | } |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6247 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6248 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6249 | if ((which&NET_UPDATE_WIFI) != 0 && mWifiIfaces.length > 0) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6250 | final NetworkStats snapshot; |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6251 | final NetworkStats last = mCurWifiSnapshot; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6252 | try { |
| 6253 | snapshot = mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL, |
| 6254 | mWifiIfaces, NetworkStats.TAG_NONE, mLastWifiSnapshot); |
| 6255 | } catch (IOException e) { |
| 6256 | Log.wtf(TAG, "Failed to read wifi network stats", e); |
| 6257 | return; |
| 6258 | } |
| 6259 | |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6260 | mCurWifiSnapshot = snapshot; |
| 6261 | mLastWifiSnapshot = last; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6262 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6263 | if (mOnBatteryInternal) { |
| 6264 | final NetworkStats delta = NetworkStats.subtract(snapshot, last, |
| 6265 | null, null, mTmpNetworkStats); |
| 6266 | mTmpNetworkStats = delta; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6267 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6268 | final int size = delta.size(); |
| 6269 | for (int i = 0; i < size; i++) { |
| 6270 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6271 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6272 | if (DEBUG) { |
| 6273 | final NetworkStats.Entry cur = snapshot.getValues(i, null); |
| 6274 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 6275 | + " tx=" + entry.txBytes + ", cur rx=" + cur.rxBytes |
| 6276 | + " tx=" + cur.txBytes); |
| 6277 | } |
| 6278 | |
| 6279 | if (entry.rxBytes == 0 || entry.txBytes == 0) continue; |
| 6280 | |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6281 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6282 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 6283 | entry.rxPackets); |
| 6284 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 6285 | entry.txPackets); |
| 6286 | |
| 6287 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 6288 | entry.rxBytes); |
| 6289 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 6290 | entry.txBytes); |
| 6291 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 6292 | entry.rxPackets); |
| 6293 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 6294 | entry.txPackets); |
Dianne Hackborn | fb7b50a | 2014-02-24 17:06:14 -0800 | [diff] [blame] | 6295 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | } |
| 6299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6300 | public long getAwakeTimeBattery() { |
| 6301 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 6302 | } |
| 6303 | |
| 6304 | public long getAwakeTimePlugged() { |
| 6305 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 6306 | } |
| 6307 | |
| 6308 | @Override |
| 6309 | public long computeUptime(long curTime, int which) { |
| 6310 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6311 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6312 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6313 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | } |
| 6315 | return 0; |
| 6316 | } |
| 6317 | |
| 6318 | @Override |
| 6319 | public long computeRealtime(long curTime, int which) { |
| 6320 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6321 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6322 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6323 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | } |
| 6325 | return 0; |
| 6326 | } |
| 6327 | |
| 6328 | @Override |
| 6329 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6330 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | @Override |
| 6334 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6335 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | } |
| 6337 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6338 | @Override |
| 6339 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 6340 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 6341 | } |
| 6342 | |
| 6343 | @Override |
| 6344 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 6345 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6346 | } |
| 6347 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6348 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 6349 | // For now we'll do a simple average across all steps. |
| 6350 | if (numSteps <= 0) { |
| 6351 | return -1; |
| 6352 | } |
| 6353 | long total = 0; |
| 6354 | for (int i=0; i<numSteps; i++) { |
| 6355 | total += steps[i]; |
| 6356 | } |
| 6357 | return total / numSteps; |
| 6358 | /* |
| 6359 | long[] buckets = new long[numSteps]; |
| 6360 | int numBuckets = 0; |
| 6361 | int numToAverage = 4; |
| 6362 | int i = 0; |
| 6363 | while (i < numSteps) { |
| 6364 | long totalTime = 0; |
| 6365 | int num = 0; |
| 6366 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 6367 | totalTime += steps[i+j]; |
| 6368 | num++; |
| 6369 | } |
| 6370 | buckets[numBuckets] = totalTime / num; |
| 6371 | numBuckets++; |
| 6372 | numToAverage *= 2; |
| 6373 | i += num; |
| 6374 | } |
| 6375 | if (numBuckets < 1) { |
| 6376 | return -1; |
| 6377 | } |
| 6378 | long averageTime = buckets[numBuckets-1]; |
| 6379 | for (i=numBuckets-2; i>=0; i--) { |
| 6380 | averageTime = (averageTime + buckets[i]) / 2; |
| 6381 | } |
| 6382 | return averageTime; |
| 6383 | */ |
| 6384 | } |
| 6385 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6386 | @Override |
| 6387 | public long computeBatteryTimeRemaining(long curTime) { |
| 6388 | if (!mOnBattery) { |
| 6389 | return -1; |
| 6390 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6391 | /* Simple implementation just looks at the average discharge per level across the |
| 6392 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6393 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 6394 | if (discharge < 2) { |
| 6395 | return -1; |
| 6396 | } |
| 6397 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 6398 | if (duration < 1000*1000) { |
| 6399 | return -1; |
| 6400 | } |
| 6401 | long usPerLevel = duration/discharge; |
| 6402 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6403 | */ |
| 6404 | if (mNumDischargeStepDurations < 1) { |
| 6405 | return -1; |
| 6406 | } |
| 6407 | long msPerLevel = computeTimePerLevel(mDischargeStepDurations, mNumDischargeStepDurations); |
| 6408 | if (msPerLevel <= 0) { |
| 6409 | return -1; |
| 6410 | } |
| 6411 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6412 | } |
| 6413 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6414 | public int getNumDischargeStepDurations() { |
| 6415 | return mNumDischargeStepDurations; |
| 6416 | } |
| 6417 | |
| 6418 | public long[] getDischargeStepDurationsArray() { |
| 6419 | return mDischargeStepDurations; |
| 6420 | } |
| 6421 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6422 | @Override |
| 6423 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6424 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6425 | // Not yet working. |
| 6426 | return -1; |
| 6427 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6428 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6429 | int curLevel = mCurrentBatteryLevel; |
| 6430 | int plugLevel = mDischargePlugLevel; |
| 6431 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 6432 | return -1; |
| 6433 | } |
| 6434 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 6435 | if (duration < 1000*1000) { |
| 6436 | return -1; |
| 6437 | } |
| 6438 | long usPerLevel = duration/(curLevel-plugLevel); |
| 6439 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6440 | */ |
| 6441 | if (mNumChargeStepDurations < 1) { |
| 6442 | return -1; |
| 6443 | } |
| 6444 | long msPerLevel = computeTimePerLevel(mChargeStepDurations, mNumChargeStepDurations); |
| 6445 | if (msPerLevel <= 0) { |
| 6446 | return -1; |
| 6447 | } |
| 6448 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6449 | } |
| 6450 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6451 | public int getNumChargeStepDurations() { |
| 6452 | return mNumChargeStepDurations; |
| 6453 | } |
| 6454 | |
| 6455 | public long[] getChargeStepDurationsArray() { |
| 6456 | return mChargeStepDurations; |
| 6457 | } |
| 6458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6459 | long getBatteryUptimeLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6460 | return mOnBatteryTimeBase.getUptime(SystemClock.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6461 | } |
| 6462 | |
| 6463 | @Override |
| 6464 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6465 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | } |
| 6467 | |
| 6468 | @Override |
| 6469 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6470 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6471 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 6472 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6473 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6474 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6475 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6476 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6477 | } |
| 6478 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6479 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6480 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6481 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6482 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6483 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6484 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6485 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6486 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6487 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6488 | } |
| 6489 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6490 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6491 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6492 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6495 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6496 | public int getLowDischargeAmountSinceCharge() { |
| 6497 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6498 | int val = mLowDischargeAmountSinceCharge; |
| 6499 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 6500 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 6501 | } |
| 6502 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6503 | } |
| 6504 | } |
| 6505 | |
| 6506 | @Override |
| 6507 | public int getHighDischargeAmountSinceCharge() { |
| 6508 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6509 | int val = mHighDischargeAmountSinceCharge; |
| 6510 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 6511 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 6512 | } |
| 6513 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6514 | } |
| 6515 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6516 | |
| 6517 | @Override |
| 6518 | public int getDischargeAmount(int which) { |
| 6519 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 6520 | ? getHighDischargeAmountSinceCharge() |
| 6521 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 6522 | if (dischargeAmount < 0) { |
| 6523 | dischargeAmount = 0; |
| 6524 | } |
| 6525 | return dischargeAmount; |
| 6526 | } |
| 6527 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6528 | public int getDischargeAmountScreenOn() { |
| 6529 | synchronized(this) { |
| 6530 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6531 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6532 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 6533 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 6534 | } |
| 6535 | return val; |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | public int getDischargeAmountScreenOnSinceCharge() { |
| 6540 | synchronized(this) { |
| 6541 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6542 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6543 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 6544 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 6545 | } |
| 6546 | return val; |
| 6547 | } |
| 6548 | } |
| 6549 | |
| 6550 | public int getDischargeAmountScreenOff() { |
| 6551 | synchronized(this) { |
| 6552 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6553 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6554 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 6555 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 6556 | } |
| 6557 | return val; |
| 6558 | } |
| 6559 | } |
| 6560 | |
| 6561 | public int getDischargeAmountScreenOffSinceCharge() { |
| 6562 | synchronized(this) { |
| 6563 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6564 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6565 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 6566 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 6567 | } |
| 6568 | return val; |
| 6569 | } |
| 6570 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6571 | |
| 6572 | @Override |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6573 | public int getCpuSpeedSteps() { |
| 6574 | return sNumSpeedSteps; |
| 6575 | } |
| 6576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | /** |
| 6578 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 6579 | */ |
| 6580 | public Uid getUidStatsLocked(int uid) { |
| 6581 | Uid u = mUidStats.get(uid); |
| 6582 | if (u == null) { |
| 6583 | u = new Uid(uid); |
| 6584 | mUidStats.put(uid, u); |
| 6585 | } |
| 6586 | return u; |
| 6587 | } |
| 6588 | |
| 6589 | /** |
| 6590 | * Remove the statistics object for a particular uid. |
| 6591 | */ |
| 6592 | public void removeUidStatsLocked(int uid) { |
| 6593 | mUidStats.remove(uid); |
| 6594 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 6595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6596 | /** |
| 6597 | * Retrieve the statistics object for a particular process, creating |
| 6598 | * if needed. |
| 6599 | */ |
| 6600 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6601 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6602 | Uid u = getUidStatsLocked(uid); |
| 6603 | return u.getProcessStatsLocked(name); |
| 6604 | } |
| 6605 | |
| 6606 | /** |
| 6607 | * Retrieve the statistics object for a particular process, creating |
| 6608 | * if needed. |
| 6609 | */ |
| 6610 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6611 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | Uid u = getUidStatsLocked(uid); |
| 6613 | return u.getPackageStatsLocked(pkg); |
| 6614 | } |
| 6615 | |
| 6616 | /** |
| 6617 | * Retrieve the statistics object for a particular service, creating |
| 6618 | * if needed. |
| 6619 | */ |
| 6620 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 6621 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6622 | Uid u = getUidStatsLocked(uid); |
| 6623 | return u.getServiceStatsLocked(pkg, name); |
| 6624 | } |
| 6625 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6626 | /** |
| 6627 | * Massage data to distribute any reasonable work down to more specific |
| 6628 | * owners. Must only be called on a dead BatteryStats object! |
| 6629 | */ |
| 6630 | public void distributeWorkLocked(int which) { |
| 6631 | // Aggregate all CPU time associated with WIFI. |
| 6632 | Uid wifiUid = mUidStats.get(Process.WIFI_UID); |
| 6633 | if (wifiUid != null) { |
| 6634 | long uSecTime = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which); |
| 6635 | for (Uid.Proc proc : wifiUid.mProcessStats.values()) { |
| 6636 | long totalRunningTime = getGlobalWifiRunningTime(uSecTime, which); |
| 6637 | for (int i=0; i<mUidStats.size(); i++) { |
| 6638 | Uid uid = mUidStats.valueAt(i); |
| 6639 | if (uid.mUid != Process.WIFI_UID) { |
| 6640 | long uidRunningTime = uid.getWifiRunningTime(uSecTime, which); |
| 6641 | if (uidRunningTime > 0) { |
| 6642 | Uid.Proc uidProc = uid.getProcessStatsLocked("*wifi*"); |
| 6643 | long time = proc.getUserTime(which); |
| 6644 | time = (time*uidRunningTime)/totalRunningTime; |
| 6645 | uidProc.mUserTime += time; |
| 6646 | proc.mUserTime -= time; |
| 6647 | time = proc.getSystemTime(which); |
| 6648 | time = (time*uidRunningTime)/totalRunningTime; |
| 6649 | uidProc.mSystemTime += time; |
| 6650 | proc.mSystemTime -= time; |
| 6651 | time = proc.getForegroundTime(which); |
| 6652 | time = (time*uidRunningTime)/totalRunningTime; |
| 6653 | uidProc.mForegroundTime += time; |
| 6654 | proc.mForegroundTime -= time; |
| 6655 | for (int sb=0; sb<proc.mSpeedBins.length; sb++) { |
| 6656 | SamplingCounter sc = proc.mSpeedBins[sb]; |
| 6657 | if (sc != null) { |
| 6658 | time = sc.getCountLocked(which); |
| 6659 | time = (time*uidRunningTime)/totalRunningTime; |
| 6660 | SamplingCounter uidSc = uidProc.mSpeedBins[sb]; |
| 6661 | if (uidSc == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6662 | uidSc = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6663 | uidProc.mSpeedBins[sb] = uidSc; |
| 6664 | } |
| 6665 | uidSc.mCount.addAndGet((int)time); |
| 6666 | sc.mCount.addAndGet((int)-time); |
| 6667 | } |
| 6668 | } |
| 6669 | totalRunningTime -= uidRunningTime; |
| 6670 | } |
| 6671 | } |
| 6672 | } |
| 6673 | } |
| 6674 | } |
| 6675 | } |
| 6676 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6677 | public void shutdownLocked() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6678 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6679 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6680 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6681 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6682 | Parcel mPendingWrite = null; |
| 6683 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 6684 | |
| 6685 | public void writeAsyncLocked() { |
| 6686 | writeLocked(false); |
| 6687 | } |
| 6688 | |
| 6689 | public void writeSyncLocked() { |
| 6690 | writeLocked(true); |
| 6691 | } |
| 6692 | |
| 6693 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6694 | if (mFile == null) { |
| 6695 | 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] | 6696 | return; |
| 6697 | } |
| 6698 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6699 | if (mShuttingDown) { |
| 6700 | return; |
| 6701 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6702 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6703 | Parcel out = Parcel.obtain(); |
| 6704 | writeSummaryToParcel(out); |
| 6705 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 6706 | |
| 6707 | if (mPendingWrite != null) { |
| 6708 | mPendingWrite.recycle(); |
| 6709 | } |
| 6710 | mPendingWrite = out; |
| 6711 | |
| 6712 | if (sync) { |
| 6713 | commitPendingDataToDisk(); |
| 6714 | } else { |
| 6715 | Thread thr = new Thread("BatteryStats-Write") { |
| 6716 | @Override |
| 6717 | public void run() { |
| 6718 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 6719 | commitPendingDataToDisk(); |
| 6720 | } |
| 6721 | }; |
| 6722 | thr.start(); |
| 6723 | } |
| 6724 | } |
| 6725 | |
| 6726 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 6727 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6728 | synchronized (this) { |
| 6729 | next = mPendingWrite; |
| 6730 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 6731 | if (next == null) { |
| 6732 | return; |
| 6733 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6734 | |
| 6735 | mWriteLock.lock(); |
| 6736 | } |
| 6737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6738 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6739 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6740 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 6742 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6743 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6744 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6745 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6746 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6747 | mFile.rollback(); |
| 6748 | } finally { |
| 6749 | next.recycle(); |
| 6750 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 6751 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6752 | } |
| 6753 | |
| 6754 | static byte[] readFully(FileInputStream stream) throws java.io.IOException { |
| 6755 | int pos = 0; |
| 6756 | int avail = stream.available(); |
| 6757 | byte[] data = new byte[avail]; |
| 6758 | while (true) { |
| 6759 | int amt = stream.read(data, pos, data.length-pos); |
| 6760 | //Log.i("foo", "Read " + amt + " bytes at " + pos |
| 6761 | // + " of avail " + data.length); |
| 6762 | if (amt <= 0) { |
| 6763 | //Log.i("foo", "**** FINISHED READING: pos=" + pos |
| 6764 | // + " len=" + data.length); |
| 6765 | return data; |
| 6766 | } |
| 6767 | pos += amt; |
| 6768 | avail = stream.available(); |
| 6769 | if (avail > data.length-pos) { |
| 6770 | byte[] newData = new byte[pos+avail]; |
| 6771 | System.arraycopy(data, 0, newData, 0, pos); |
| 6772 | data = newData; |
| 6773 | } |
| 6774 | } |
| 6775 | } |
| 6776 | |
| 6777 | public void readLocked() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6778 | if (mFile == null) { |
| 6779 | 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] | 6780 | return; |
| 6781 | } |
| 6782 | |
| 6783 | mUidStats.clear(); |
| 6784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6785 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6786 | File file = mFile.chooseForRead(); |
| 6787 | if (!file.exists()) { |
| 6788 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6789 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6790 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | |
| 6792 | byte[] raw = readFully(stream); |
| 6793 | Parcel in = Parcel.obtain(); |
| 6794 | in.unmarshall(raw, 0, raw.length); |
| 6795 | in.setDataPosition(0); |
| 6796 | stream.close(); |
| 6797 | |
| 6798 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 6799 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6800 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6802 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6803 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6804 | mRecordingHistory = true; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6805 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 6806 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6807 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6808 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6809 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6810 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 6811 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 6812 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | public int describeContents() { |
| 6816 | return 0; |
| 6817 | } |
| 6818 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6819 | void readHistory(Parcel in, boolean andOldHistory) { |
| 6820 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6821 | |
| 6822 | mHistoryBuffer.setDataSize(0); |
| 6823 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6824 | mHistoryTagPool.clear(); |
| 6825 | mNextHistoryTagIdx = 0; |
| 6826 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6827 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6828 | int numTags = in.readInt(); |
| 6829 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6830 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6831 | String str = in.readString(); |
| 6832 | int uid = in.readInt(); |
| 6833 | HistoryTag tag = new HistoryTag(); |
| 6834 | tag.string = str; |
| 6835 | tag.uid = uid; |
| 6836 | tag.poolIdx = idx; |
| 6837 | mHistoryTagPool.put(tag, idx); |
| 6838 | if (idx >= mNextHistoryTagIdx) { |
| 6839 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6840 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6841 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6842 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6843 | |
| 6844 | int bufSize = in.readInt(); |
| 6845 | int curPos = in.dataPosition(); |
| 6846 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
| 6847 | Slog.w(TAG, "File corrupt: history data buffer too large " + bufSize); |
| 6848 | } else if ((bufSize&~3) != bufSize) { |
| 6849 | Slog.w(TAG, "File corrupt: history data buffer not aligned " + bufSize); |
| 6850 | } else { |
| 6851 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 6852 | + " bytes at " + curPos); |
| 6853 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 6854 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6855 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6856 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6857 | if (andOldHistory) { |
| 6858 | readOldHistory(in); |
| 6859 | } |
| 6860 | |
| 6861 | if (DEBUG_HISTORY) { |
| 6862 | StringBuilder sb = new StringBuilder(128); |
| 6863 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 6864 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 6865 | Slog.i(TAG, sb.toString()); |
| 6866 | } |
| 6867 | mHistoryBaseTime = historyBaseTime; |
| 6868 | if (DEBUG_HISTORY) { |
| 6869 | StringBuilder sb = new StringBuilder(128); |
| 6870 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 6871 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 6872 | Slog.i(TAG, sb.toString()); |
| 6873 | } |
| 6874 | |
| 6875 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 6876 | // the last run until samples in this run. |
| 6877 | if (mHistoryBaseTime > 0) { |
| 6878 | long oldnow = SystemClock.elapsedRealtime(); |
| 6879 | mHistoryBaseTime = (mHistoryBaseTime - oldnow) + 60*1000; |
| 6880 | if (DEBUG_HISTORY) { |
| 6881 | StringBuilder sb = new StringBuilder(128); |
| 6882 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 6883 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 6884 | Slog.i(TAG, sb.toString()); |
| 6885 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 6886 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6887 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6888 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6889 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 6890 | if (!USE_OLD_HISTORY) { |
| 6891 | return; |
| 6892 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6893 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 6894 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 6895 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6896 | HistoryItem rec = new HistoryItem(time, in); |
| 6897 | addHistoryRecordLocked(rec); |
| 6898 | } |
| 6899 | } |
| 6900 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6901 | void writeHistory(Parcel out, boolean andOldHistory) { |
| 6902 | if (DEBUG_HISTORY) { |
| 6903 | StringBuilder sb = new StringBuilder(128); |
| 6904 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 6905 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6906 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 6907 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6908 | Slog.i(TAG, sb.toString()); |
| 6909 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6910 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6911 | out.writeInt(mHistoryTagPool.size()); |
| 6912 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 6913 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6914 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6915 | out.writeString(tag.string); |
| 6916 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6917 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6918 | out.writeInt(mHistoryBuffer.dataSize()); |
| 6919 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 6920 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 6921 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6922 | |
| 6923 | if (andOldHistory) { |
| 6924 | writeOldHistory(out); |
| 6925 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 6929 | if (!USE_OLD_HISTORY) { |
| 6930 | return; |
| 6931 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6932 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6933 | while (rec != null) { |
| 6934 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 6935 | rec = rec.next; |
| 6936 | } |
| 6937 | out.writeLong(-1); |
| 6938 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | private void readSummaryFromParcel(Parcel in) { |
| 6941 | final int version = in.readInt(); |
| 6942 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6943 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6944 | + ", expected " + VERSION + "; erasing old stats"); |
| 6945 | return; |
| 6946 | } |
| 6947 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6948 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6953 | mStartClockTime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6954 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 6955 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6956 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6957 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6958 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6959 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6960 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 6961 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6962 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 6963 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 6964 | mNumDischargeStepDurations = in.readInt(); |
| 6965 | in.readLongArray(mDischargeStepDurations); |
| 6966 | mNumChargeStepDurations = in.readInt(); |
| 6967 | in.readLongArray(mChargeStepDurations); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6970 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6971 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6973 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 6974 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 6975 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6976 | mInteractive = false; |
| 6977 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | mPhoneOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6979 | mLowPowerModeEnabledTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6980 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6981 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6982 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 6983 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6984 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6985 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 6986 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 6987 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6988 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6989 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 6990 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6991 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6992 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6993 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6994 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6995 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6996 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 6997 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6998 | mWifiOn = false; |
| 6999 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7000 | mGlobalWifiRunning = false; |
| 7001 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7002 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 7003 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 7004 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7005 | mBluetoothOn = false; |
| 7006 | mBluetoothOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7007 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 7008 | mBluetoothStateTimer[i].readSummaryFromParcelLocked(in); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7010 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7011 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7012 | if (NKW > 10000) { |
| 7013 | Slog.w(TAG, "File corrupt: too many kernel wake locks " + NKW); |
| 7014 | return; |
| 7015 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7016 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 7017 | if (in.readInt() != 0) { |
| 7018 | String kwltName = in.readString(); |
| 7019 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 7020 | } |
| 7021 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7022 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7023 | int NWR = in.readInt(); |
| 7024 | if (NWR > 10000) { |
| 7025 | Slog.w(TAG, "File corrupt: too many wakeup reasons " + NWR); |
| 7026 | return; |
| 7027 | } |
| 7028 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 7029 | if (in.readInt() != 0) { |
| 7030 | String reasonName = in.readString(); |
| 7031 | getWakeupReasonCounterLocked(reasonName).readSummaryFromParcelLocked(in); |
| 7032 | } |
| 7033 | } |
| 7034 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7035 | sNumSpeedSteps = in.readInt(); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 7036 | if (sNumSpeedSteps < 0 || sNumSpeedSteps > 100) { |
| 7037 | throw new BadParcelableException("Bad speed steps in data: " + sNumSpeedSteps); |
| 7038 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7040 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7041 | if (NU > 10000) { |
| 7042 | Slog.w(TAG, "File corrupt: too many uids " + NU); |
| 7043 | return; |
| 7044 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | for (int iu = 0; iu < NU; iu++) { |
| 7046 | int uid = in.readInt(); |
| 7047 | Uid u = new Uid(uid); |
| 7048 | mUidStats.put(uid, u); |
| 7049 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7050 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7051 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7052 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7053 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7054 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7055 | if (in.readInt() != 0) { |
| 7056 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 7057 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7058 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7059 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7060 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7061 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7062 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 7063 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7064 | if (in.readInt() != 0) { |
| 7065 | u.makeWifiBatchedScanBin(i, null); |
| 7066 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 7067 | } |
| 7068 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7069 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7070 | if (in.readInt() != 0) { |
| 7071 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 7072 | } |
| 7073 | u.mAudioTurnedOn = false; |
| 7074 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7075 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7076 | } |
| 7077 | u.mVideoTurnedOn = false; |
| 7078 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7079 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 7080 | } |
| 7081 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7082 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 7083 | } |
| 7084 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7085 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7086 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7087 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7088 | if (in.readInt() != 0) { |
| 7089 | if (u.mUserActivityCounters == null) { |
| 7090 | u.initUserActivityLocked(); |
| 7091 | } |
| 7092 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 7093 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 7094 | } |
| 7095 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7096 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7097 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7098 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7099 | u.initNetworkActivityLocked(); |
| 7100 | } |
| 7101 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7102 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 7103 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7104 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7105 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 7106 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7107 | } |
| 7108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7109 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7110 | if (NW > 100) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7111 | Slog.w(TAG, "File corrupt: too many wake locks " + NW); |
| 7112 | return; |
| 7113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | for (int iw = 0; iw < NW; iw++) { |
| 7115 | String wlName = in.readString(); |
| 7116 | if (in.readInt() != 0) { |
| 7117 | u.getWakeTimerLocked(wlName, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
| 7118 | } |
| 7119 | if (in.readInt() != 0) { |
| 7120 | u.getWakeTimerLocked(wlName, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7121 | } |
| 7122 | if (in.readInt() != 0) { |
| 7123 | u.getWakeTimerLocked(wlName, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7128 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7129 | Slog.w(TAG, "File corrupt: too many sensors " + NP); |
| 7130 | return; |
| 7131 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7132 | for (int is = 0; is < NP; is++) { |
| 7133 | int seNumber = in.readInt(); |
| 7134 | if (in.readInt() != 0) { |
| 7135 | u.getSensorTimerLocked(seNumber, true) |
| 7136 | .readSummaryFromParcelLocked(in); |
| 7137 | } |
| 7138 | } |
| 7139 | |
| 7140 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7141 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7142 | Slog.w(TAG, "File corrupt: too many processes " + NP); |
| 7143 | return; |
| 7144 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | for (int ip = 0; ip < NP; ip++) { |
| 7146 | String procName = in.readString(); |
| 7147 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 7148 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7150 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7151 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7152 | int NSB = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7153 | if (NSB > 100) { |
| 7154 | Slog.w(TAG, "File corrupt: too many speed bins " + NSB); |
| 7155 | return; |
| 7156 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7157 | p.mSpeedBins = new SamplingCounter[NSB]; |
| 7158 | for (int i=0; i<NSB; i++) { |
| 7159 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7160 | p.mSpeedBins[i] = new SamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7161 | p.mSpeedBins[i].readSummaryFromParcelLocked(in); |
| 7162 | } |
| 7163 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7164 | if (!p.readExcessivePowerFromParcelLocked(in)) { |
| 7165 | return; |
| 7166 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7170 | if (NP > 10000) { |
| 7171 | Slog.w(TAG, "File corrupt: too many packages " + NP); |
| 7172 | return; |
| 7173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7174 | for (int ip = 0; ip < NP; ip++) { |
| 7175 | String pkgName = in.readString(); |
| 7176 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
| 7177 | p.mWakeups = p.mLoadedWakeups = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7178 | final int NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7179 | if (NS > 1000) { |
| 7180 | Slog.w(TAG, "File corrupt: too many services " + NS); |
| 7181 | return; |
| 7182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7183 | for (int is = 0; is < NS; is++) { |
| 7184 | String servName = in.readString(); |
| 7185 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 7186 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7187 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7188 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7189 | } |
| 7190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | } |
| 7192 | } |
| 7193 | |
| 7194 | /** |
| 7195 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 7196 | * disk. This format does not allow a lossless round-trip. |
| 7197 | * |
| 7198 | * @param out the Parcel to be written to. |
| 7199 | */ |
| 7200 | public void writeSummaryToParcel(Parcel out) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7201 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 7204 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | |
| 7206 | out.writeInt(VERSION); |
| 7207 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7208 | writeHistory(out, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7211 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7212 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7213 | out.writeLong(mStartClockTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7214 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 7215 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7216 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7217 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7218 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7219 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 7220 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 7221 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7222 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 7223 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7224 | out.writeInt(mNumDischargeStepDurations); |
| 7225 | out.writeLongArray(mDischargeStepDurations); |
| 7226 | out.writeInt(mNumChargeStepDurations); |
| 7227 | out.writeLongArray(mChargeStepDurations); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7228 | |
| 7229 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7230 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7231 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7232 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7233 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7234 | mLowPowerModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7235 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7236 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7237 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7238 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7239 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7240 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7241 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7242 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7243 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7244 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 7245 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7246 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7247 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7248 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7249 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7250 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 7251 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7252 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7253 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7254 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7255 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7256 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7257 | mBluetoothOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7258 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7259 | mBluetoothStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7261 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7262 | out.writeInt(mKernelWakelockStats.size()); |
| 7263 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 7264 | Timer kwlt = ent.getValue(); |
| 7265 | if (kwlt != null) { |
| 7266 | out.writeInt(1); |
| 7267 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7268 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 7269 | } else { |
| 7270 | out.writeInt(0); |
| 7271 | } |
| 7272 | } |
| 7273 | |
| 7274 | out.writeInt(mWakeupReasonStats.size()); |
| 7275 | for (Map.Entry<String, LongSamplingCounter> ent : mWakeupReasonStats.entrySet()) { |
| 7276 | LongSamplingCounter counter = ent.getValue(); |
| 7277 | if (counter != null) { |
| 7278 | out.writeInt(1); |
| 7279 | out.writeString(ent.getKey()); |
| 7280 | counter.writeSummaryFromParcelLocked(out); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7281 | } else { |
| 7282 | out.writeInt(0); |
| 7283 | } |
| 7284 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7285 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7286 | out.writeInt(sNumSpeedSteps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7287 | final int NU = mUidStats.size(); |
| 7288 | out.writeInt(NU); |
| 7289 | for (int iu = 0; iu < NU; iu++) { |
| 7290 | out.writeInt(mUidStats.keyAt(iu)); |
| 7291 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7292 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7293 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7294 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7295 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7296 | } else { |
| 7297 | out.writeInt(0); |
| 7298 | } |
| 7299 | if (u.mFullWifiLockTimer != null) { |
| 7300 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7301 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7302 | } else { |
| 7303 | out.writeInt(0); |
| 7304 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7305 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7306 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7307 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7308 | } else { |
| 7309 | out.writeInt(0); |
| 7310 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7311 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7312 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 7313 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7314 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7315 | } else { |
| 7316 | out.writeInt(0); |
| 7317 | } |
| 7318 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7319 | if (u.mWifiMulticastTimer != null) { |
| 7320 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7321 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7322 | } else { |
| 7323 | out.writeInt(0); |
| 7324 | } |
| 7325 | if (u.mAudioTurnedOnTimer != null) { |
| 7326 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7327 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7328 | } else { |
| 7329 | out.writeInt(0); |
| 7330 | } |
| 7331 | if (u.mVideoTurnedOnTimer != null) { |
| 7332 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7333 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7334 | } else { |
| 7335 | out.writeInt(0); |
| 7336 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7337 | if (u.mForegroundActivityTimer != null) { |
| 7338 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7339 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7340 | } else { |
| 7341 | out.writeInt(0); |
| 7342 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7343 | if (u.mVibratorOnTimer != null) { |
| 7344 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7345 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7346 | } else { |
| 7347 | out.writeInt(0); |
| 7348 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7349 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7350 | if (u.mUserActivityCounters == null) { |
| 7351 | out.writeInt(0); |
| 7352 | } else { |
| 7353 | out.writeInt(1); |
| 7354 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 7355 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 7356 | } |
| 7357 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7358 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7359 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7360 | out.writeInt(0); |
| 7361 | } else { |
| 7362 | out.writeInt(1); |
| 7363 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7364 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 7365 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7366 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7367 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 7368 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7369 | } |
| 7370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | int NW = u.mWakelockStats.size(); |
| 7372 | out.writeInt(NW); |
| 7373 | if (NW > 0) { |
| 7374 | for (Map.Entry<String, BatteryStatsImpl.Uid.Wakelock> ent |
| 7375 | : u.mWakelockStats.entrySet()) { |
| 7376 | out.writeString(ent.getKey()); |
| 7377 | Uid.Wakelock wl = ent.getValue(); |
| 7378 | if (wl.mTimerFull != null) { |
| 7379 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7380 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | } else { |
| 7382 | out.writeInt(0); |
| 7383 | } |
| 7384 | if (wl.mTimerPartial != null) { |
| 7385 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7386 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | } else { |
| 7388 | out.writeInt(0); |
| 7389 | } |
| 7390 | if (wl.mTimerWindow != null) { |
| 7391 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7392 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | } else { |
| 7394 | out.writeInt(0); |
| 7395 | } |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | int NSE = u.mSensorStats.size(); |
| 7400 | out.writeInt(NSE); |
| 7401 | if (NSE > 0) { |
| 7402 | for (Map.Entry<Integer, BatteryStatsImpl.Uid.Sensor> ent |
| 7403 | : u.mSensorStats.entrySet()) { |
| 7404 | out.writeInt(ent.getKey()); |
| 7405 | Uid.Sensor se = ent.getValue(); |
| 7406 | if (se.mTimer != null) { |
| 7407 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7408 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | } else { |
| 7410 | out.writeInt(0); |
| 7411 | } |
| 7412 | } |
| 7413 | } |
| 7414 | |
| 7415 | int NP = u.mProcessStats.size(); |
| 7416 | out.writeInt(NP); |
| 7417 | if (NP > 0) { |
| 7418 | for (Map.Entry<String, BatteryStatsImpl.Uid.Proc> ent |
| 7419 | : u.mProcessStats.entrySet()) { |
| 7420 | out.writeString(ent.getKey()); |
| 7421 | Uid.Proc ps = ent.getValue(); |
| 7422 | out.writeLong(ps.mUserTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7423 | out.writeLong(ps.mSystemTime); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7424 | out.writeLong(ps.mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7426 | final int N = ps.mSpeedBins.length; |
| 7427 | out.writeInt(N); |
| 7428 | for (int i=0; i<N; i++) { |
| 7429 | if (ps.mSpeedBins[i] != null) { |
| 7430 | out.writeInt(1); |
| 7431 | ps.mSpeedBins[i].writeSummaryFromParcelLocked(out); |
| 7432 | } else { |
| 7433 | out.writeInt(0); |
| 7434 | } |
| 7435 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7436 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7437 | } |
| 7438 | } |
| 7439 | |
| 7440 | NP = u.mPackageStats.size(); |
| 7441 | out.writeInt(NP); |
| 7442 | if (NP > 0) { |
| 7443 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 7444 | : u.mPackageStats.entrySet()) { |
| 7445 | out.writeString(ent.getKey()); |
| 7446 | Uid.Pkg ps = ent.getValue(); |
| 7447 | out.writeInt(ps.mWakeups); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | final int NS = ps.mServiceStats.size(); |
| 7449 | out.writeInt(NS); |
| 7450 | if (NS > 0) { |
| 7451 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg.Serv> sent |
| 7452 | : ps.mServiceStats.entrySet()) { |
| 7453 | out.writeString(sent.getKey()); |
| 7454 | BatteryStatsImpl.Uid.Pkg.Serv ss = sent.getValue(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7455 | long time = ss.getStartTimeToNowLocked( |
| 7456 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | out.writeLong(time); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7458 | out.writeInt(ss.mStarts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7460 | } |
| 7461 | } |
| 7462 | } |
| 7463 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | } |
| 7465 | } |
| 7466 | |
| 7467 | public void readFromParcel(Parcel in) { |
| 7468 | readFromParcelLocked(in); |
| 7469 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7471 | void readFromParcelLocked(Parcel in) { |
| 7472 | int magic = in.readInt(); |
| 7473 | if (magic != MAGIC) { |
| 7474 | throw new ParcelFormatException("Bad magic number"); |
| 7475 | } |
| 7476 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7477 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7479 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7480 | mStartClockTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | mUptime = in.readLong(); |
| 7482 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | mRealtime = in.readLong(); |
| 7484 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | mOnBattery = in.readInt() != 0; |
| 7486 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7487 | mOnBatteryTimeBase.readFromParcel(in); |
| 7488 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 7489 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7490 | mScreenState = Display.STATE_UNKNOWN; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7491 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in); |
| 7492 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 7493 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, |
| 7494 | in); |
| 7495 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 7496 | mInteractive = false; |
| 7497 | mInteractiveTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7498 | mPhoneOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7499 | mLowPowerModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in); |
| 7500 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7501 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 7502 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 7503 | null, mOnBatteryTimeBase, in); |
| 7504 | } |
| 7505 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase, in); |
| 7506 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 7507 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 7508 | null, mOnBatteryTimeBase, in); |
| 7509 | } |
| 7510 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 7511 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 7512 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 7513 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7514 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7515 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); |
| 7516 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, |
| 7517 | in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7518 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7519 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 7520 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 7521 | mWifiOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7522 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7523 | mGlobalWifiRunning = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7524 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7525 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 7526 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, |
| 7527 | null, mOnBatteryTimeBase, in); |
| 7528 | } |
| 7529 | mBluetoothOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7530 | mBluetoothOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7531 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 7532 | mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, |
| 7533 | null, mOnBatteryTimeBase, in); |
| 7534 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7535 | mAudioOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7536 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7537 | mVideoOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7538 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7539 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7540 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7541 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7542 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7543 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 7544 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7545 | mDischargeAmountScreenOn = in.readInt(); |
| 7546 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 7547 | mDischargeAmountScreenOff = in.readInt(); |
| 7548 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7549 | mNumDischargeStepDurations = in.readInt(); |
| 7550 | in.readLongArray(mDischargeStepDurations); |
| 7551 | mNumChargeStepDurations = in.readInt(); |
| 7552 | in.readLongArray(mChargeStepDurations); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | mLastWriteTime = in.readLong(); |
| 7554 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 7555 | mBluetoothPingCount = in.readInt(); |
| 7556 | mBluetoothPingStart = -1; |
| 7557 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7558 | mKernelWakelockStats.clear(); |
| 7559 | int NKW = in.readInt(); |
| 7560 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 7561 | if (in.readInt() != 0) { |
| 7562 | String wakelockName = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7563 | SamplingTimer kwlt = new SamplingTimer(mOnBatteryTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7564 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 7565 | } |
| 7566 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7567 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7568 | mWakeupReasonStats.clear(); |
| 7569 | int NWR = in.readInt(); |
| 7570 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 7571 | if (in.readInt() != 0) { |
| 7572 | String reasonName = in.readString(); |
| 7573 | LongSamplingCounter counter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, |
| 7574 | in); |
| 7575 | mWakeupReasonStats.put(reasonName, counter); |
| 7576 | } |
| 7577 | } |
| 7578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7579 | mPartialTimers.clear(); |
| 7580 | mFullTimers.clear(); |
| 7581 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7582 | mWifiRunningTimers.clear(); |
| 7583 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7584 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7585 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7586 | mWifiMulticastTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7587 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7588 | sNumSpeedSteps = in.readInt(); |
| 7589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7590 | int numUids = in.readInt(); |
| 7591 | mUidStats.clear(); |
| 7592 | for (int i = 0; i < numUids; i++) { |
| 7593 | int uid = in.readInt(); |
| 7594 | Uid u = new Uid(uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7595 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7596 | mUidStats.append(uid, u); |
| 7597 | } |
| 7598 | } |
| 7599 | |
| 7600 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7601 | writeToParcelLocked(out, true, flags); |
| 7602 | } |
| 7603 | |
| 7604 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 7605 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7607 | |
| 7608 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7609 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7610 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7611 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 7614 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7615 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 7616 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7618 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7619 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 7620 | writeHistory(out, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | out.writeInt(mStartCount); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7623 | out.writeLong(mStartClockTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7624 | out.writeLong(mUptime); |
| 7625 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | out.writeLong(mRealtime); |
| 7627 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7628 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7629 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 7630 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 7631 | |
| 7632 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 7633 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 7634 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 7635 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7636 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7637 | mLowPowerModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7638 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 7639 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 7640 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 7641 | } |
| 7642 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 7643 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 7644 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 7645 | } |
| 7646 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 7647 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 7648 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 7649 | } |
| 7650 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 7651 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7652 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7653 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 7654 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 7655 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 7656 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 7657 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 7658 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 7659 | } |
| 7660 | mBluetoothOnTimer.writeToParcel(out, uSecRealtime); |
| 7661 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
| 7662 | mBluetoothStateTimer[i].writeToParcel(out, uSecRealtime); |
| 7663 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7664 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7665 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7666 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7667 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7668 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 7669 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7670 | out.writeInt(mDischargeAmountScreenOn); |
| 7671 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 7672 | out.writeInt(mDischargeAmountScreenOff); |
| 7673 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 7674 | out.writeInt(mNumDischargeStepDurations); |
| 7675 | out.writeLongArray(mDischargeStepDurations); |
| 7676 | out.writeInt(mNumChargeStepDurations); |
| 7677 | out.writeLongArray(mChargeStepDurations); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7678 | out.writeLong(mLastWriteTime); |
| 7679 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 7680 | out.writeInt(getBluetoothPingCount()); |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 7681 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7682 | if (inclUids) { |
| 7683 | out.writeInt(mKernelWakelockStats.size()); |
| 7684 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 7685 | SamplingTimer kwlt = ent.getValue(); |
| 7686 | if (kwlt != null) { |
| 7687 | out.writeInt(1); |
| 7688 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7689 | kwlt.writeToParcel(out, uSecRealtime); |
| 7690 | } else { |
| 7691 | out.writeInt(0); |
| 7692 | } |
| 7693 | } |
| 7694 | out.writeInt(mWakeupReasonStats.size()); |
| 7695 | for (Map.Entry<String, LongSamplingCounter> ent : mWakeupReasonStats.entrySet()) { |
| 7696 | LongSamplingCounter counter = ent.getValue(); |
| 7697 | if (counter != null) { |
| 7698 | out.writeInt(1); |
| 7699 | out.writeString(ent.getKey()); |
| 7700 | counter.writeToParcel(out); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7701 | } else { |
| 7702 | out.writeInt(0); |
| 7703 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7704 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7705 | } else { |
| 7706 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7707 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7708 | |
| 7709 | out.writeInt(sNumSpeedSteps); |
| 7710 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7711 | if (inclUids) { |
| 7712 | int size = mUidStats.size(); |
| 7713 | out.writeInt(size); |
| 7714 | for (int i = 0; i < size; i++) { |
| 7715 | out.writeInt(mUidStats.keyAt(i)); |
| 7716 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7717 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7718 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7719 | } |
| 7720 | } else { |
| 7721 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7722 | } |
| 7723 | } |
| 7724 | |
| 7725 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 7726 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 7727 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 7728 | return new BatteryStatsImpl(in); |
| 7729 | } |
| 7730 | |
| 7731 | public BatteryStatsImpl[] newArray(int size) { |
| 7732 | return new BatteryStatsImpl[size]; |
| 7733 | } |
| 7734 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7735 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7736 | public void prepareForDumpLocked() { |
| 7737 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7738 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7739 | } |
| 7740 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 7741 | 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] | 7742 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7743 | pw.println("mOnBatteryTimeBase:"); |
| 7744 | mOnBatteryTimeBase.dump(pw, " "); |
| 7745 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 7746 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7747 | Printer pr = new PrintWriterPrinter(pw); |
| 7748 | pr.println("*** Screen timer:"); |
| 7749 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7750 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7751 | pr.println("*** Screen brightness #" + i + ":"); |
| 7752 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7753 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7754 | pr.println("*** Interactive timer:"); |
| 7755 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 7756 | pr.println("*** Low power mode timer:"); |
| 7757 | mLowPowerModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7758 | pr.println("*** Phone timer:"); |
| 7759 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7760 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7761 | pr.println("*** Signal strength #" + i + ":"); |
| 7762 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7763 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7764 | pr.println("*** Signal scanning :"); |
| 7765 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7766 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7767 | pr.println("*** Data connection type #" + i + ":"); |
| 7768 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7769 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7770 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7771 | pr.println("*** Mobile network active timer:"); |
| 7772 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7773 | pr.println("*** Mobile network active adjusted timer:"); |
| 7774 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7775 | pr.println("*** Wifi timer:"); |
| 7776 | mWifiOnTimer.logState(pr, " "); |
| 7777 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7778 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7779 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 7780 | pr.println("*** Wifi state #" + i + ":"); |
| 7781 | mWifiStateTimer[i].logState(pr, " "); |
| 7782 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7783 | pr.println("*** Bluetooth timer:"); |
| 7784 | mBluetoothOnTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7785 | for (int i=0; i< NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7786 | pr.println("*** Bluetooth active type #" + i + ":"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7787 | mBluetoothStateTimer[i].logState(pr, " "); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 7788 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7789 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 7790 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | } |