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 | |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 19 | import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 20 | |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothDevice; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothHeadset; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 23 | import android.net.ConnectivityManager; |
| 24 | import android.net.NetworkStats; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 25 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.os.BatteryStats; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 27 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 28 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 29 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 30 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.Parcel; |
| 32 | import android.os.ParcelFormatException; |
| 33 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 34 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 36 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 37 | import android.os.WorkSource; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 38 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 39 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 40 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 42 | import android.util.LogWriter; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 43 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 45 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.util.SparseArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 47 | import android.util.TimeUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 49 | import com.android.internal.annotations.GuardedBy; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 50 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 51 | import com.android.internal.util.FastPrintWriter; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 52 | import com.android.internal.util.JournaledFile; |
| 53 | import com.google.android.collect.Sets; |
| 54 | |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 55 | import java.io.BufferedReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import java.io.File; |
| 57 | import java.io.FileInputStream; |
| 58 | import java.io.FileOutputStream; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 59 | import java.io.FileReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 61 | import java.io.PrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import java.util.ArrayList; |
| 63 | import java.util.HashMap; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 64 | import java.util.HashSet; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 65 | import java.util.Iterator; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 66 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 68 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 69 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * All information we are collecting about things that can happen that impact |
| 73 | * battery life. All times are represented in microseconds except where indicated |
| 74 | * otherwise. |
| 75 | */ |
| 76 | public final class BatteryStatsImpl extends BatteryStats { |
| 77 | private static final String TAG = "BatteryStatsImpl"; |
| 78 | private static final boolean DEBUG = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 79 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 80 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 81 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 82 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 83 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | // 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] | 85 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
| 87 | // Current on-disk Parcel version |
Jeff Brown | 81b7caf | 2013-10-29 18:28:57 -0700 | [diff] [blame] | 88 | private static final int VERSION = 67 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 89 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 90 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 91 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 92 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 93 | // No, really, THIS is the maximum number of items we will record in the history. |
| 94 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 95 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 96 | // The maximum number of names wakelocks we will keep track of |
| 97 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 98 | // in to one common name. |
Dianne Hackborn | af17baa | 2013-05-09 15:27:47 -0700 | [diff] [blame] | 99 | private static final int MAX_WAKELOCKS_PER_UID = 50; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 100 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 101 | private static final String BATCHED_WAKELOCK_NAME = "*overflow*"; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 102 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 103 | private static int sNumSpeedSteps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 105 | private final JournaledFile mFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 107 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 108 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 109 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 110 | |
| 111 | public interface BatteryCallback { |
| 112 | public void batteryNeedsCpuUpdate(); |
| 113 | public void batteryPowerChanged(boolean onBattery); |
| 114 | } |
| 115 | |
| 116 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 117 | public MyHandler(Looper looper) { |
| 118 | super(looper, null, true); |
| 119 | } |
| 120 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 121 | @Override |
| 122 | public void handleMessage(Message msg) { |
| 123 | BatteryCallback cb = mCallback; |
| 124 | switch (msg.what) { |
| 125 | case MSG_UPDATE_WAKELOCKS: |
| 126 | if (cb != null) { |
| 127 | cb.batteryNeedsCpuUpdate(); |
| 128 | } |
| 129 | break; |
| 130 | case MSG_REPORT_POWER_CHANGE: |
| 131 | if (cb != null) { |
| 132 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 133 | } |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | private final MyHandler mHandler; |
| 140 | |
| 141 | private BatteryCallback mCallback; |
| 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | /** |
| 144 | * The statistics we have collected organized by uids. |
| 145 | */ |
| 146 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 147 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 148 | |
| 149 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 150 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 151 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 152 | // changes. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 153 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<StopwatchTimer>(); |
| 154 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<StopwatchTimer>(); |
| 155 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<StopwatchTimer>(); |
| 156 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers |
| 157 | = new SparseArray<ArrayList<StopwatchTimer>>(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 158 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<StopwatchTimer>(); |
| 159 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<StopwatchTimer>(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 160 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<StopwatchTimer>(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 161 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 162 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = |
| 163 | new SparseArray<ArrayList<StopwatchTimer>>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 165 | // Last partial timers we use for distributing CPU usage. |
| 166 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); |
| 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | // These are the objects that will want to do something when the device |
| 169 | // is unplugged from power. |
| 170 | final ArrayList<Unpluggable> mUnpluggables = new ArrayList<Unpluggable>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 171 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 172 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 173 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 174 | long mHistoryBaseTime; |
| 175 | boolean mHaveBatteryLevel = false; |
| 176 | boolean mRecordingHistory = true; |
| 177 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 178 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 179 | static final int MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 180 | static final int MAX_MAX_HISTORY_BUFFER = 144*1024; // 144KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 181 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 182 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 183 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 184 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 185 | int mHistoryBufferLastPos = -1; |
| 186 | boolean mHistoryOverflow = false; |
| 187 | long mLastHistoryTime = 0; |
| 188 | |
| 189 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 190 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 191 | HistoryItem mHistory; |
| 192 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 193 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 194 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 195 | |
| 196 | private HistoryItem mHistoryIterator; |
| 197 | private boolean mReadOverflow; |
| 198 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | int mStartCount; |
| 201 | |
| 202 | long mBatteryUptime; |
| 203 | long mBatteryLastUptime; |
| 204 | long mBatteryRealtime; |
| 205 | long mBatteryLastRealtime; |
| 206 | |
| 207 | long mUptime; |
| 208 | long mUptimeStart; |
| 209 | long mLastUptime; |
| 210 | long mRealtime; |
| 211 | long mRealtimeStart; |
| 212 | long mLastRealtime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | boolean mScreenOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 215 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 216 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 217 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 218 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 219 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 220 | Counter mInputEventCounter; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 223 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 224 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 225 | boolean mAudioOn; |
| 226 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 227 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 228 | boolean mVideoOn; |
| 229 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 230 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 231 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 232 | int mPhoneSignalStrengthBinRaw = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 233 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 234 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 235 | |
| 236 | StopwatchTimer mPhoneSignalScanningTimer; |
| 237 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 238 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 239 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 240 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 241 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 242 | final LongSamplingCounter[] mNetworkActivityCounters = |
| 243 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 244 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 245 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 246 | StopwatchTimer mWifiOnTimer; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 247 | int mWifiOnUid = -1; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 248 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 249 | boolean mGlobalWifiRunning; |
| 250 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 251 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 252 | boolean mBluetoothOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 253 | StopwatchTimer mBluetoothOnTimer; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 254 | |
| 255 | /** Bluetooth headset object */ |
| 256 | BluetoothHeadset mBtHeadset; |
| 257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | /** |
| 259 | * These provide time bases that discount the time the device is plugged |
| 260 | * in to power. |
| 261 | */ |
| 262 | boolean mOnBattery; |
| 263 | boolean mOnBatteryInternal; |
| 264 | long mTrackBatteryPastUptime; |
| 265 | long mTrackBatteryUptimeStart; |
| 266 | long mTrackBatteryPastRealtime; |
| 267 | long mTrackBatteryRealtimeStart; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | long mUnpluggedBatteryUptime; |
| 270 | long mUnpluggedBatteryRealtime; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 272 | /* |
| 273 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 274 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 275 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 276 | int mDischargeUnplugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 277 | int mDischargeCurrentLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 278 | int mLowDischargeAmountSinceCharge; |
| 279 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 280 | int mDischargeScreenOnUnplugLevel; |
| 281 | int mDischargeScreenOffUnplugLevel; |
| 282 | int mDischargeAmountScreenOn; |
| 283 | int mDischargeAmountScreenOnSinceCharge; |
| 284 | int mDischargeAmountScreenOff; |
| 285 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 288 | |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 289 | private long mRadioDataUptime; |
| 290 | private long mRadioDataStart; |
| 291 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 292 | private int mBluetoothPingCount; |
| 293 | private int mBluetoothPingStart = -1; |
| 294 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 295 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 296 | private int mPhoneServiceStateRaw = -1; |
| 297 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 298 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 299 | /* |
| 300 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 301 | */ |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 302 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 303 | new HashMap<String, SamplingTimer>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 304 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 305 | public Map<String, ? extends SamplingTimer> getKernelWakelockStats() { |
| 306 | return mKernelWakelockStats; |
| 307 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 308 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 309 | private static int sKernelWakelockUpdateVersion = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 310 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 311 | private static final int[] PROC_WAKELOCKS_FORMAT = new int[] { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 312 | Process.PROC_TAB_TERM|Process.PROC_OUT_STRING| // 0: name |
| 313 | Process.PROC_QUOTES, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 314 | Process.PROC_TAB_TERM|Process.PROC_OUT_LONG, // 1: count |
| 315 | Process.PROC_TAB_TERM, |
| 316 | Process.PROC_TAB_TERM, |
| 317 | Process.PROC_TAB_TERM, |
| 318 | Process.PROC_TAB_TERM|Process.PROC_OUT_LONG, // 5: totalTime |
| 319 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 320 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 321 | private static final int[] WAKEUP_SOURCES_FORMAT = new int[] { |
| 322 | Process.PROC_TAB_TERM|Process.PROC_OUT_STRING, // 0: name |
| 323 | Process.PROC_TAB_TERM|Process.PROC_COMBINE| |
| 324 | Process.PROC_OUT_LONG, // 1: count |
| 325 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 326 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 327 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 328 | Process.PROC_TAB_TERM|Process.PROC_COMBINE, |
| 329 | Process.PROC_TAB_TERM|Process.PROC_COMBINE |
| 330 | |Process.PROC_OUT_LONG, // 6: totalTime |
| 331 | }; |
| 332 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 333 | private final String[] mProcWakelocksName = new String[3]; |
| 334 | private final long[] mProcWakelocksData = new long[3]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 335 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 336 | /* |
| 337 | * Used as a buffer for reading in data from /proc/wakelocks before it is processed and added |
| 338 | * to mKernelWakelockStats. |
| 339 | */ |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 340 | private final Map<String, KernelWakelockStats> mProcWakelockFileStats = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 341 | new HashMap<String, KernelWakelockStats>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 343 | private HashMap<String, Integer> mUidCache = new HashMap<String, Integer>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 344 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 345 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 346 | private NetworkStats mLastSnapshot; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 347 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 348 | @GuardedBy("this") |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 349 | private HashSet<String> mMobileIfaces = Sets.newHashSet(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 350 | @GuardedBy("this") |
| 351 | private HashSet<String> mWifiIfaces = Sets.newHashSet(); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | // For debugging |
| 354 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 355 | mFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 356 | mHandler = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | public static interface Unpluggable { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 360 | void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime); |
| 361 | void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 365 | * State for keeping track of counting information. |
| 366 | */ |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 367 | public static class Counter extends BatteryStats.Counter implements Unpluggable { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 368 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 369 | final ArrayList<Unpluggable> mUnpluggables; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 370 | int mLoadedCount; |
| 371 | int mLastCount; |
| 372 | int mUnpluggedCount; |
| 373 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 374 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 375 | Counter(ArrayList<Unpluggable> unpluggables, Parcel in) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 376 | mUnpluggables = unpluggables; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 377 | mPluggedCount = in.readInt(); |
| 378 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 379 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 380 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 381 | mUnpluggedCount = in.readInt(); |
| 382 | unpluggables.add(this); |
| 383 | } |
| 384 | |
| 385 | Counter(ArrayList<Unpluggable> unpluggables) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 386 | mUnpluggables = unpluggables; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 387 | unpluggables.add(this); |
| 388 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 389 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 390 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 391 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 392 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 393 | out.writeInt(mUnpluggedCount); |
| 394 | } |
| 395 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 396 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 397 | mUnpluggedCount = mPluggedCount; |
| 398 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 401 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 402 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 403 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 404 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 405 | /** |
| 406 | * Writes a possibly null Counter to a Parcel. |
| 407 | * |
| 408 | * @param out the Parcel to be written to. |
| 409 | * @param counter a Counter, or null. |
| 410 | */ |
| 411 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 412 | if (counter == null) { |
| 413 | out.writeInt(0); // indicates null |
| 414 | return; |
| 415 | } |
| 416 | out.writeInt(1); // indicates non-null |
| 417 | |
| 418 | counter.writeToParcel(out); |
| 419 | } |
| 420 | |
| 421 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 422 | public int getCountLocked(int which) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 423 | int val; |
| 424 | if (which == STATS_LAST) { |
| 425 | val = mLastCount; |
| 426 | } else { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 427 | val = mCount.get(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 428 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 429 | val -= mUnpluggedCount; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 430 | } else if (which != STATS_SINCE_CHARGED) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 431 | val -= mLoadedCount; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | return val; |
| 436 | } |
| 437 | |
| 438 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 439 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 440 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 441 | + " mUnpluggedCount=" + mUnpluggedCount |
| 442 | + " mPluggedCount=" + mPluggedCount); |
| 443 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 444 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 445 | void stepAtomic() { |
| 446 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 449 | /** |
| 450 | * Clear state of this counter. |
| 451 | */ |
| 452 | void reset(boolean detachIfReset) { |
| 453 | mCount.set(0); |
| 454 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 455 | if (detachIfReset) { |
| 456 | detach(); |
| 457 | } |
| 458 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 459 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 460 | void detach() { |
| 461 | mUnpluggables.remove(this); |
| 462 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 463 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 464 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 465 | int count = mCount.get(); |
| 466 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 470 | mLoadedCount = in.readInt(); |
| 471 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 472 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 473 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 476 | |
| 477 | public static class SamplingCounter extends Counter { |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 478 | SamplingCounter(ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 479 | super(unpluggables, in); |
| 480 | } |
| 481 | |
| 482 | SamplingCounter(ArrayList<Unpluggable> unpluggables) { |
| 483 | super(unpluggables); |
| 484 | } |
| 485 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 486 | public void addCountAtomic(long count) { |
| 487 | mCount.addAndGet((int)count); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 491 | public static class LongSamplingCounter implements Unpluggable { |
| 492 | final ArrayList<Unpluggable> mUnpluggables; |
| 493 | long mCount; |
| 494 | long mLoadedCount; |
| 495 | long mLastCount; |
| 496 | long mUnpluggedCount; |
| 497 | long mPluggedCount; |
| 498 | |
| 499 | LongSamplingCounter(ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 500 | mUnpluggables = unpluggables; |
| 501 | mPluggedCount = in.readLong(); |
| 502 | mCount = mPluggedCount; |
| 503 | mLoadedCount = in.readLong(); |
| 504 | mLastCount = 0; |
| 505 | mUnpluggedCount = in.readLong(); |
| 506 | unpluggables.add(this); |
| 507 | } |
| 508 | |
| 509 | LongSamplingCounter(ArrayList<Unpluggable> unpluggables) { |
| 510 | mUnpluggables = unpluggables; |
| 511 | unpluggables.add(this); |
| 512 | } |
| 513 | |
| 514 | public void writeToParcel(Parcel out) { |
| 515 | out.writeLong(mCount); |
| 516 | out.writeLong(mLoadedCount); |
| 517 | out.writeLong(mUnpluggedCount); |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
| 522 | mUnpluggedCount = mPluggedCount; |
| 523 | mCount = mPluggedCount; |
| 524 | } |
| 525 | |
| 526 | @Override |
| 527 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
| 528 | mPluggedCount = mCount; |
| 529 | } |
| 530 | |
| 531 | public long getCountLocked(int which) { |
| 532 | long val; |
| 533 | if (which == STATS_LAST) { |
| 534 | val = mLastCount; |
| 535 | } else { |
| 536 | val = mCount; |
| 537 | if (which == STATS_SINCE_UNPLUGGED) { |
| 538 | val -= mUnpluggedCount; |
| 539 | } else if (which != STATS_SINCE_CHARGED) { |
| 540 | val -= mLoadedCount; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | return val; |
| 545 | } |
| 546 | |
| 547 | void addCountLocked(long count) { |
| 548 | mCount += count; |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Clear state of this counter. |
| 553 | */ |
| 554 | void reset(boolean detachIfReset) { |
| 555 | mCount = 0; |
| 556 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 557 | if (detachIfReset) { |
| 558 | detach(); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | void detach() { |
| 563 | mUnpluggables.remove(this); |
| 564 | } |
| 565 | |
| 566 | void writeSummaryFromParcelLocked(Parcel out) { |
| 567 | out.writeLong(mCount); |
| 568 | } |
| 569 | |
| 570 | void readSummaryFromParcelLocked(Parcel in) { |
| 571 | mLoadedCount = in.readLong(); |
| 572 | mCount = mLoadedCount; |
| 573 | mLastCount = 0; |
| 574 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 575 | } |
| 576 | } |
| 577 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 578 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | * State for keeping track of timing information. |
| 580 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 581 | public static abstract class Timer extends BatteryStats.Timer implements Unpluggable { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | final int mType; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 583 | final ArrayList<Unpluggable> mUnpluggables; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | int mCount; |
| 586 | int mLoadedCount; |
| 587 | int mLastCount; |
| 588 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | // Times are in microseconds for better accuracy when dividing by the |
| 591 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | /** |
| 594 | * The total time we have accumulated since the start of the original |
| 595 | * boot, to the last time something interesting happened in the |
| 596 | * current run. |
| 597 | */ |
| 598 | long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | /** |
| 601 | * The total time we loaded for the previous runs. Subtract this from |
| 602 | * mTotalTime to find the time for the current run of the system. |
| 603 | */ |
| 604 | long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | /** |
| 607 | * The run time of the last run of the system, as loaded from the |
| 608 | * saved data. |
| 609 | */ |
| 610 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | /** |
| 613 | * The value of mTotalTime when unplug() was last called. Subtract |
| 614 | * this from mTotalTime to find the time since the last unplug from |
| 615 | * power. |
| 616 | */ |
| 617 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 618 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 619 | /** |
| 620 | * Constructs from a parcel. |
| 621 | * @param type |
| 622 | * @param unpluggables |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 623 | * @param in |
| 624 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 625 | Timer(int type, ArrayList<Unpluggable> unpluggables, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | mType = type; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 627 | mUnpluggables = unpluggables; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | mCount = in.readInt(); |
| 630 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 631 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | mUnpluggedCount = in.readInt(); |
| 633 | mTotalTime = in.readLong(); |
| 634 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 635 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | mUnpluggedTime = in.readLong(); |
| 637 | unpluggables.add(this); |
| 638 | } |
| 639 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 640 | Timer(int type, ArrayList<Unpluggable> unpluggables) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | mType = type; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 642 | mUnpluggables = unpluggables; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | unpluggables.add(this); |
| 644 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 645 | |
| 646 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 647 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 648 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 649 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 650 | /** |
| 651 | * Clear state of this timer. Returns true if the timer is inactive |
| 652 | * so can be completely dropped. |
| 653 | */ |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 654 | boolean reset(BatteryStatsImpl stats, boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 655 | mTotalTime = mLoadedTime = mLastTime = 0; |
| 656 | mCount = mLoadedCount = mLastCount = 0; |
| 657 | if (detachIfReset) { |
| 658 | detach(); |
| 659 | } |
| 660 | return true; |
| 661 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 662 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 663 | void detach() { |
| 664 | mUnpluggables.remove(this); |
| 665 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | public void writeToParcel(Parcel out, long batteryRealtime) { |
| 668 | out.writeInt(mCount); |
| 669 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | out.writeInt(mUnpluggedCount); |
| 671 | out.writeLong(computeRunTimeLocked(batteryRealtime)); |
| 672 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | out.writeLong(mUnpluggedTime); |
| 674 | } |
| 675 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 676 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | if (DEBUG && mType < 0) { |
| 678 | Log.v(TAG, "unplug #" + mType + ": realtime=" + batteryRealtime |
| 679 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 680 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 681 | } |
| 682 | mUnpluggedTime = computeRunTimeLocked(batteryRealtime); |
| 683 | mUnpluggedCount = mCount; |
| 684 | if (DEBUG && mType < 0) { |
| 685 | Log.v(TAG, "unplug #" + mType |
| 686 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 687 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 688 | } |
| 689 | } |
| 690 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 691 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 692 | if (DEBUG && mType < 0) { |
| 693 | Log.v(TAG, "plug #" + mType + ": realtime=" + batteryRealtime |
| 694 | + " old mTotalTime=" + mTotalTime); |
| 695 | } |
| 696 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 697 | mCount = computeCurrentCountLocked(); |
| 698 | if (DEBUG && mType < 0) { |
| 699 | Log.v(TAG, "plug #" + mType |
| 700 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
| 702 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | /** |
| 705 | * Writes a possibly null Timer to a Parcel. |
| 706 | * |
| 707 | * @param out the Parcel to be written to. |
| 708 | * @param timer a Timer, or null. |
| 709 | */ |
| 710 | public static void writeTimerToParcel(Parcel out, Timer timer, |
| 711 | long batteryRealtime) { |
| 712 | if (timer == null) { |
| 713 | out.writeInt(0); // indicates null |
| 714 | return; |
| 715 | } |
| 716 | out.writeInt(1); // indicates non-null |
| 717 | |
| 718 | timer.writeToParcel(out, batteryRealtime); |
| 719 | } |
| 720 | |
| 721 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 722 | public long getTotalTimeLocked(long batteryRealtime, int which) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | long val; |
| 724 | if (which == STATS_LAST) { |
| 725 | val = mLastTime; |
| 726 | } else { |
| 727 | val = computeRunTimeLocked(batteryRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 728 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | val -= mUnpluggedTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 730 | } else if (which != STATS_SINCE_CHARGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | val -= mLoadedTime; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | return val; |
| 736 | } |
| 737 | |
| 738 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 739 | public int getCountLocked(int which) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | int val; |
| 741 | if (which == STATS_LAST) { |
| 742 | val = mLastCount; |
| 743 | } else { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 744 | val = computeCurrentCountLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 745 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | val -= mUnpluggedCount; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 747 | } else if (which != STATS_SINCE_CHARGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | val -= mLoadedCount; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return val; |
| 753 | } |
| 754 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 755 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 756 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 758 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 759 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 761 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 763 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 764 | |
| 765 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 766 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 767 | long runTime = computeRunTimeLocked(batteryRealtime); |
| 768 | // Divide by 1000 for backwards compatibility |
| 769 | out.writeLong((runTime + 500) / 1000); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 770 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | void readSummaryFromParcelLocked(Parcel in) { |
| 774 | // Multiply by 1000 for backwards compatibility |
| 775 | mTotalTime = mLoadedTime = in.readLong() * 1000; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 776 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 777 | mUnpluggedTime = mTotalTime; |
| 778 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 779 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 780 | mUnpluggedCount = mCount; |
| 781 | } |
| 782 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 783 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 784 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 785 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 786 | /** |
| 787 | * The most recent reported count from /proc/wakelocks. |
| 788 | */ |
| 789 | int mCurrentReportedCount; |
| 790 | |
| 791 | /** |
| 792 | * The reported count from /proc/wakelocks when unplug() was last |
| 793 | * called. |
| 794 | */ |
| 795 | int mUnpluggedReportedCount; |
| 796 | |
| 797 | /** |
| 798 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 799 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 800 | long mCurrentReportedTotalTime; |
| 801 | |
| 802 | |
| 803 | /** |
| 804 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 805 | * called. |
| 806 | */ |
| 807 | long mUnpluggedReportedTotalTime; |
| 808 | |
| 809 | /** |
| 810 | * Whether we are currently in a discharge cycle. |
| 811 | */ |
| 812 | boolean mInDischarge; |
| 813 | |
| 814 | /** |
| 815 | * Whether we are currently recording reported values. |
| 816 | */ |
| 817 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 818 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 819 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 820 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 821 | */ |
| 822 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 823 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 824 | SamplingTimer(ArrayList<Unpluggable> unpluggables, boolean inDischarge, Parcel in) { |
| 825 | super(0, unpluggables, in); |
| 826 | mCurrentReportedCount = in.readInt(); |
| 827 | mUnpluggedReportedCount = in.readInt(); |
| 828 | mCurrentReportedTotalTime = in.readLong(); |
| 829 | mUnpluggedReportedTotalTime = in.readLong(); |
| 830 | mTrackingReportedValues = in.readInt() == 1; |
| 831 | mInDischarge = inDischarge; |
| 832 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 833 | |
| 834 | SamplingTimer(ArrayList<Unpluggable> unpluggables, boolean inDischarge, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 835 | boolean trackReportedValues) { |
| 836 | super(0, unpluggables); |
| 837 | mTrackingReportedValues = trackReportedValues; |
| 838 | mInDischarge = inDischarge; |
| 839 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 840 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 841 | public void setStale() { |
| 842 | mTrackingReportedValues = false; |
| 843 | mUnpluggedReportedTotalTime = 0; |
| 844 | mUnpluggedReportedCount = 0; |
| 845 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 846 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 847 | public void setUpdateVersion(int version) { |
| 848 | mUpdateVersion = version; |
| 849 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 850 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 851 | public int getUpdateVersion() { |
| 852 | return mUpdateVersion; |
| 853 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 854 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 855 | public void updateCurrentReportedCount(int count) { |
| 856 | if (mInDischarge && mUnpluggedReportedCount == 0) { |
| 857 | // Updating the reported value for the first time. |
| 858 | mUnpluggedReportedCount = count; |
| 859 | // If we are receiving an update update mTrackingReportedValues; |
| 860 | mTrackingReportedValues = true; |
| 861 | } |
| 862 | mCurrentReportedCount = count; |
| 863 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 864 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 865 | public void updateCurrentReportedTotalTime(long totalTime) { |
| 866 | if (mInDischarge && mUnpluggedReportedTotalTime == 0) { |
| 867 | // Updating the reported value for the first time. |
| 868 | mUnpluggedReportedTotalTime = totalTime; |
| 869 | // If we are receiving an update update mTrackingReportedValues; |
| 870 | mTrackingReportedValues = true; |
| 871 | } |
| 872 | mCurrentReportedTotalTime = totalTime; |
| 873 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 874 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 875 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
| 876 | super.unplug(elapsedRealtime, batteryUptime, batteryRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 877 | if (mTrackingReportedValues) { |
| 878 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 879 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 880 | } |
| 881 | mInDischarge = true; |
| 882 | } |
| 883 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 884 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
| 885 | super.plug(elapsedRealtime, batteryUptime, batteryRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 886 | mInDischarge = false; |
| 887 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 888 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 889 | public void logState(Printer pw, String prefix) { |
| 890 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 891 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 892 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 893 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 894 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 895 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 896 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 897 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 898 | return mTotalTime + (mInDischarge && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 899 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 900 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 901 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 902 | protected int computeCurrentCountLocked() { |
| 903 | return mCount + (mInDischarge && mTrackingReportedValues |
| 904 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 905 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 906 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 907 | public void writeToParcel(Parcel out, long batteryRealtime) { |
| 908 | super.writeToParcel(out, batteryRealtime); |
| 909 | out.writeInt(mCurrentReportedCount); |
| 910 | out.writeInt(mUnpluggedReportedCount); |
| 911 | out.writeLong(mCurrentReportedTotalTime); |
| 912 | out.writeLong(mUnpluggedReportedTotalTime); |
| 913 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 914 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 915 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 916 | boolean reset(BatteryStatsImpl stats, boolean detachIfReset) { |
| 917 | super.reset(stats, detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 918 | setStale(); |
| 919 | return true; |
| 920 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 921 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 922 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 923 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 924 | out.writeLong(mCurrentReportedTotalTime); |
| 925 | out.writeInt(mCurrentReportedCount); |
| 926 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 927 | } |
| 928 | |
| 929 | void readSummaryFromParcelLocked(Parcel in) { |
| 930 | super.readSummaryFromParcelLocked(in); |
| 931 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 932 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 933 | mTrackingReportedValues = in.readInt() == 1; |
| 934 | } |
| 935 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 936 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 937 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 938 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 939 | * for a pre-determined amount. |
| 940 | */ |
| 941 | public static final class BatchTimer extends Timer { |
| 942 | final Uid mUid; |
| 943 | |
| 944 | /** |
| 945 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 946 | */ |
| 947 | long mLastAddedTime; |
| 948 | |
| 949 | /** |
| 950 | * The last duration that we added to the timer. This is in microseconds. |
| 951 | */ |
| 952 | long mLastAddedDuration; |
| 953 | |
| 954 | /** |
| 955 | * Whether we are currently in a discharge cycle. |
| 956 | */ |
| 957 | boolean mInDischarge; |
| 958 | |
| 959 | BatchTimer(Uid uid, int type, ArrayList<Unpluggable> unpluggables, |
| 960 | boolean inDischarge, Parcel in) { |
| 961 | super(type, unpluggables, in); |
| 962 | mUid = uid; |
| 963 | mLastAddedTime = in.readLong(); |
| 964 | mLastAddedDuration = in.readLong(); |
| 965 | mInDischarge = inDischarge; |
| 966 | } |
| 967 | |
| 968 | BatchTimer(Uid uid, int type, ArrayList<Unpluggable> unpluggables, |
| 969 | boolean inDischarge) { |
| 970 | super(type, unpluggables); |
| 971 | mUid = uid; |
| 972 | mInDischarge = inDischarge; |
| 973 | } |
| 974 | |
| 975 | @Override |
| 976 | public void writeToParcel(Parcel out, long batteryRealtime) { |
| 977 | super.writeToParcel(out, batteryRealtime); |
| 978 | out.writeLong(mLastAddedTime); |
| 979 | out.writeLong(mLastAddedDuration); |
| 980 | } |
| 981 | |
| 982 | @Override |
| 983 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
| 984 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 985 | mInDischarge = false; |
| 986 | super.plug(elapsedRealtime, batteryUptime, batteryRealtime); |
| 987 | } |
| 988 | |
| 989 | @Override |
| 990 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
| 991 | recomputeLastDuration(elapsedRealtime, false); |
| 992 | mInDischarge = true; |
| 993 | // If we are still within the last added duration, then re-added whatever remains. |
| 994 | if (mLastAddedTime == elapsedRealtime) { |
| 995 | mTotalTime += mLastAddedDuration; |
| 996 | } |
| 997 | super.unplug(elapsedRealtime, batteryUptime, batteryRealtime); |
| 998 | } |
| 999 | |
| 1000 | @Override |
| 1001 | public void logState(Printer pw, String prefix) { |
| 1002 | super.logState(pw, prefix); |
| 1003 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1004 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1005 | } |
| 1006 | |
| 1007 | private long computeOverage(long curTime) { |
| 1008 | if (mLastAddedTime > 0) { |
| 1009 | return mLastTime + mLastAddedDuration - curTime; |
| 1010 | } |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1015 | final long overage = computeOverage(curTime); |
| 1016 | if (overage > 0) { |
| 1017 | // Aborting before the duration ran out -- roll back the remaining |
| 1018 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1019 | // actually add the time. |
| 1020 | if (mInDischarge) { |
| 1021 | mTotalTime -= overage; |
| 1022 | } |
| 1023 | if (abort) { |
| 1024 | mLastAddedTime = 0; |
| 1025 | } else { |
| 1026 | mLastAddedTime = curTime; |
| 1027 | mLastAddedDuration -= overage; |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1033 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1034 | recomputeLastDuration(now, true); |
| 1035 | mLastAddedTime = now; |
| 1036 | mLastAddedDuration = durationMillis * 1000; |
| 1037 | if (mInDischarge) { |
| 1038 | mTotalTime += mLastAddedDuration; |
| 1039 | mCount++; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1044 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1045 | recomputeLastDuration(now, true); |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | protected int computeCurrentCountLocked() { |
| 1050 | return mCount; |
| 1051 | } |
| 1052 | |
| 1053 | @Override |
| 1054 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1055 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1056 | if (overage > 0) { |
| 1057 | return mTotalTime = overage; |
| 1058 | } |
| 1059 | return mTotalTime; |
| 1060 | } |
| 1061 | |
| 1062 | @Override |
| 1063 | boolean reset(BatteryStatsImpl stats, boolean detachIfReset) { |
| 1064 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1065 | recomputeLastDuration(now, true); |
| 1066 | boolean stillActive = mLastAddedTime == now; |
| 1067 | super.reset(stats, !stillActive && detachIfReset); |
| 1068 | return !stillActive; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1073 | * State for keeping track of timing information. |
| 1074 | */ |
| 1075 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1076 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1077 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1078 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1079 | int mNesting; |
| 1080 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1081 | /** |
| 1082 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1083 | * subtract this from the current battery time to find the amount of |
| 1084 | * time we have been running since we last computed an update. |
| 1085 | */ |
| 1086 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1087 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1088 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1089 | * 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] | 1090 | * was actually held for an interesting duration. |
| 1091 | */ |
| 1092 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1093 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1094 | long mTimeout; |
| 1095 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1096 | /** |
| 1097 | * For partial wake locks, keep track of whether we are in the list |
| 1098 | * to consume CPU cycles. |
| 1099 | */ |
| 1100 | boolean mInList; |
| 1101 | |
| 1102 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1103 | ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 1104 | super(type, unpluggables, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1105 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1106 | mTimerPool = timerPool; |
| 1107 | mUpdateTime = in.readLong(); |
| 1108 | } |
| 1109 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1110 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1111 | ArrayList<Unpluggable> unpluggables) { |
| 1112 | super(type, unpluggables); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1113 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1114 | mTimerPool = timerPool; |
| 1115 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1116 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1117 | void setTimeout(long timeout) { |
| 1118 | mTimeout = timeout; |
| 1119 | } |
| 1120 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1121 | public void writeToParcel(Parcel out, long batteryRealtime) { |
| 1122 | super.writeToParcel(out, batteryRealtime); |
| 1123 | out.writeLong(mUpdateTime); |
| 1124 | } |
| 1125 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1126 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1127 | if (mNesting > 0) { |
| 1128 | if (DEBUG && mType < 0) { |
| 1129 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1130 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1131 | super.plug(elapsedRealtime, batteryUptime, batteryRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1132 | mUpdateTime = batteryRealtime; |
| 1133 | if (DEBUG && mType < 0) { |
| 1134 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | public void logState(Printer pw, String prefix) { |
| 1140 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1141 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | + " mAcquireTime=" + mAcquireTime); |
| 1143 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | void startRunningLocked(BatteryStatsImpl stats) { |
| 1146 | if (mNesting++ == 0) { |
| 1147 | mUpdateTime = stats.getBatteryRealtimeLocked( |
| 1148 | SystemClock.elapsedRealtime() * 1000); |
| 1149 | if (mTimerPool != null) { |
| 1150 | // Accumulate time to all currently active timers before adding |
| 1151 | // this new one to the pool. |
| 1152 | refreshTimersLocked(stats, mTimerPool); |
| 1153 | // Add this timer to the active pool |
| 1154 | mTimerPool.add(this); |
| 1155 | } |
| 1156 | // Increment the count |
| 1157 | mCount++; |
| 1158 | mAcquireTime = mTotalTime; |
| 1159 | if (DEBUG && mType < 0) { |
| 1160 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1161 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1162 | + " mAcquireTime=" + mAcquireTime); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1167 | boolean isRunningLocked() { |
| 1168 | return mNesting > 0; |
| 1169 | } |
| 1170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | void stopRunningLocked(BatteryStatsImpl stats) { |
| 1172 | // Ignore attempt to stop a timer that isn't running |
| 1173 | if (mNesting == 0) { |
| 1174 | return; |
| 1175 | } |
| 1176 | if (--mNesting == 0) { |
| 1177 | if (mTimerPool != null) { |
| 1178 | // Accumulate time to all active counters, scaled by the total |
| 1179 | // active in the pool, before taking this one out of the pool. |
| 1180 | refreshTimersLocked(stats, mTimerPool); |
| 1181 | // Remove this timer from the active pool |
| 1182 | mTimerPool.remove(this); |
| 1183 | } else { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1184 | final long realtime = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | final long batteryRealtime = stats.getBatteryRealtimeLocked(realtime); |
| 1186 | mNesting = 1; |
| 1187 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1188 | mNesting = 0; |
| 1189 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | if (DEBUG && mType < 0) { |
| 1192 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1193 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1194 | + " mAcquireTime=" + mAcquireTime); |
| 1195 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | if (mTotalTime == mAcquireTime) { |
| 1198 | // If there was no change in the time, then discard this |
| 1199 | // count. A somewhat cheezy strategy, but hey. |
| 1200 | mCount--; |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | // Update the total time for all other running Timers with the same type as this Timer |
| 1206 | // due to a change in timer count |
| 1207 | private static void refreshTimersLocked(final BatteryStatsImpl stats, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1208 | final ArrayList<StopwatchTimer> pool) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1209 | final long realtime = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | final long batteryRealtime = stats.getBatteryRealtimeLocked(realtime); |
| 1211 | final int N = pool.size(); |
| 1212 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1213 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1215 | if (heldTime > 0) { |
| 1216 | t.mTotalTime += heldTime / N; |
| 1217 | } |
| 1218 | t.mUpdateTime = batteryRealtime; |
| 1219 | } |
| 1220 | } |
| 1221 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1222 | @Override |
| 1223 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1224 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1225 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | return mTotalTime + (mNesting > 0 |
| 1228 | ? (curBatteryRealtime - mUpdateTime) |
| 1229 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1230 | : 0); |
| 1231 | } |
| 1232 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1233 | @Override |
| 1234 | protected int computeCurrentCountLocked() { |
| 1235 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1238 | boolean reset(BatteryStatsImpl stats, boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1239 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1240 | super.reset(stats, canDetach && detachIfReset); |
| 1241 | if (mNesting > 0) { |
| 1242 | mUpdateTime = stats.getBatteryRealtimeLocked( |
| 1243 | SystemClock.elapsedRealtime() * 1000); |
| 1244 | } |
| 1245 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1246 | return canDetach; |
| 1247 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1248 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1249 | void detach() { |
| 1250 | super.detach(); |
| 1251 | if (mTimerPool != null) { |
| 1252 | mTimerPool.remove(this); |
| 1253 | } |
| 1254 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1257 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | mNesting = 0; |
| 1259 | } |
| 1260 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1261 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1262 | private final Map<String, KernelWakelockStats> readKernelWakelockStats() { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1263 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1264 | FileInputStream is; |
Johannes Carlsson | 3372f2e | 2010-06-30 08:45:55 +0200 | [diff] [blame] | 1265 | byte[] buffer = new byte[8192]; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1266 | int len; |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1267 | boolean wakeup_sources = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1268 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1269 | try { |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1270 | try { |
| 1271 | is = new FileInputStream("/proc/wakelocks"); |
| 1272 | } catch (java.io.FileNotFoundException e) { |
| 1273 | try { |
| 1274 | is = new FileInputStream("/d/wakeup_sources"); |
| 1275 | wakeup_sources = true; |
| 1276 | } catch (java.io.FileNotFoundException e2) { |
| 1277 | return null; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1278 | } |
| 1279 | } |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1280 | |
| 1281 | len = is.read(buffer); |
| 1282 | is.close(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1283 | } catch (java.io.IOException e) { |
| 1284 | return null; |
| 1285 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1286 | |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1287 | if (len > 0) { |
| 1288 | int i; |
| 1289 | for (i=0; i<len; i++) { |
| 1290 | if (buffer[i] == '\0') { |
| 1291 | len = i; |
| 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | return parseProcWakelocks(buffer, len, wakeup_sources); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1298 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1299 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1300 | private final Map<String, KernelWakelockStats> parseProcWakelocks( |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1301 | byte[] wlBuffer, int len, boolean wakeup_sources) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1302 | String name; |
| 1303 | int count; |
| 1304 | long totalTime; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 1305 | int startIndex; |
| 1306 | int endIndex; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1307 | int numUpdatedWlNames = 0; |
| 1308 | |
| 1309 | // Advance past the first line. |
| 1310 | int i; |
| 1311 | for (i = 0; i < len && wlBuffer[i] != '\n' && wlBuffer[i] != '\0'; i++); |
| 1312 | startIndex = endIndex = i + 1; |
| 1313 | |
| 1314 | synchronized(this) { |
| 1315 | Map<String, KernelWakelockStats> m = mProcWakelockFileStats; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1316 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1317 | sKernelWakelockUpdateVersion++; |
| 1318 | while (endIndex < len) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1319 | for (endIndex=startIndex; |
| 1320 | endIndex < len && wlBuffer[endIndex] != '\n' && wlBuffer[endIndex] != '\0'; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1321 | endIndex++); |
Johannes Carlsson | 3372f2e | 2010-06-30 08:45:55 +0200 | [diff] [blame] | 1322 | endIndex++; // endIndex is an exclusive upper bound. |
| 1323 | // Don't go over the end of the buffer, Process.parseProcLine might |
| 1324 | // write to wlBuffer[endIndex] |
| 1325 | if (endIndex >= (len - 1) ) { |
| 1326 | return m; |
Amith Yamasani | e579561 | 2010-04-05 12:43:44 -0700 | [diff] [blame] | 1327 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1328 | |
| 1329 | String[] nameStringArray = mProcWakelocksName; |
| 1330 | long[] wlData = mProcWakelocksData; |
Amith Yamasani | 2098ead | 2010-04-02 13:46:49 -0700 | [diff] [blame] | 1331 | // Stomp out any bad characters since this is from a circular buffer |
| 1332 | // A corruption is seen sometimes that results in the vm crashing |
| 1333 | // This should prevent crashes and the line will probably fail to parse |
| 1334 | for (int j = startIndex; j < endIndex; j++) { |
| 1335 | if ((wlBuffer[j] & 0x80) != 0) wlBuffer[j] = (byte) '?'; |
| 1336 | } |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1337 | boolean parsed = Process.parseProcLine(wlBuffer, startIndex, endIndex, |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1338 | wakeup_sources ? WAKEUP_SOURCES_FORMAT : |
| 1339 | PROC_WAKELOCKS_FORMAT, |
| 1340 | nameStringArray, wlData, null); |
Amith Yamasani | 2098ead | 2010-04-02 13:46:49 -0700 | [diff] [blame] | 1341 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1342 | name = nameStringArray[0]; |
| 1343 | count = (int) wlData[1]; |
Todd Poynor | 73f534a | 2012-06-19 11:07:26 -0700 | [diff] [blame] | 1344 | |
| 1345 | if (wakeup_sources) { |
| 1346 | // convert milliseconds to microseconds |
| 1347 | totalTime = wlData[2] * 1000; |
| 1348 | } else { |
| 1349 | // convert nanoseconds to microseconds with rounding. |
| 1350 | totalTime = (wlData[2] + 500) / 1000; |
| 1351 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1352 | |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1353 | if (parsed && name.length() > 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1354 | if (!m.containsKey(name)) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1355 | m.put(name, new KernelWakelockStats(count, totalTime, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1356 | sKernelWakelockUpdateVersion)); |
| 1357 | numUpdatedWlNames++; |
| 1358 | } else { |
| 1359 | KernelWakelockStats kwlStats = m.get(name); |
| 1360 | if (kwlStats.mVersion == sKernelWakelockUpdateVersion) { |
| 1361 | kwlStats.mCount += count; |
| 1362 | kwlStats.mTotalTime += totalTime; |
| 1363 | } else { |
| 1364 | kwlStats.mCount = count; |
| 1365 | kwlStats.mTotalTime = totalTime; |
| 1366 | kwlStats.mVersion = sKernelWakelockUpdateVersion; |
| 1367 | numUpdatedWlNames++; |
| 1368 | } |
| 1369 | } |
Amith Yamasani | 53b707b | 2009-09-30 11:05:30 -0700 | [diff] [blame] | 1370 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1371 | startIndex = endIndex; |
| 1372 | } |
| 1373 | |
| 1374 | if (m.size() != numUpdatedWlNames) { |
| 1375 | // Don't report old data. |
| 1376 | Iterator<KernelWakelockStats> itr = m.values().iterator(); |
| 1377 | while (itr.hasNext()) { |
| 1378 | if (itr.next().mVersion != sKernelWakelockUpdateVersion) { |
| 1379 | itr.remove(); |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | return m; |
| 1384 | } |
| 1385 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1386 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1387 | private class KernelWakelockStats { |
| 1388 | public int mCount; |
| 1389 | public long mTotalTime; |
| 1390 | public int mVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1391 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1392 | KernelWakelockStats(int count, long totalTime, int version) { |
| 1393 | mCount = count; |
| 1394 | mTotalTime = totalTime; |
| 1395 | mVersion = version; |
| 1396 | } |
| 1397 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1398 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1399 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1400 | * 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] | 1401 | * doesn't already exist. |
| 1402 | */ |
| 1403 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1404 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1405 | if (kwlt == null) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1406 | kwlt = new SamplingTimer(mUnpluggables, mOnBatteryInternal, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1407 | true /* track reported values */); |
| 1408 | mKernelWakelockStats.put(name, kwlt); |
| 1409 | } |
| 1410 | return kwlt; |
| 1411 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1412 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1413 | /** |
| 1414 | * Radio uptime in microseconds when transferring data. This value is very approximate. |
| 1415 | * @return |
| 1416 | */ |
| 1417 | private long getCurrentRadioDataUptime() { |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1418 | try { |
| 1419 | File awakeTimeFile = new File("/sys/devices/virtual/net/rmnet0/awake_time_ms"); |
| 1420 | if (!awakeTimeFile.exists()) return 0; |
| 1421 | BufferedReader br = new BufferedReader(new FileReader(awakeTimeFile)); |
| 1422 | String line = br.readLine(); |
| 1423 | br.close(); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1424 | return Long.parseLong(line) * 1000; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1425 | } catch (NumberFormatException nfe) { |
| 1426 | // Nothing |
| 1427 | } catch (IOException ioe) { |
| 1428 | // Nothing |
| 1429 | } |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1433 | /** |
| 1434 | * @deprecated use getRadioDataUptime |
| 1435 | */ |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1436 | public long getRadioDataUptimeMs() { |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1437 | return getRadioDataUptime() / 1000; |
| 1438 | } |
| 1439 | |
| 1440 | /** |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1441 | * Returns the duration that the cell radio was up for data transfers. |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1442 | */ |
| 1443 | public long getRadioDataUptime() { |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1444 | if (mRadioDataStart == -1) { |
| 1445 | return mRadioDataUptime; |
| 1446 | } else { |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1447 | return getCurrentRadioDataUptime() - mRadioDataStart; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1451 | private int getCurrentBluetoothPingCount() { |
| 1452 | if (mBtHeadset != null) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1453 | List<BluetoothDevice> deviceList = mBtHeadset.getConnectedDevices(); |
| 1454 | if (deviceList.size() > 0) { |
| 1455 | return mBtHeadset.getBatteryUsageHint(deviceList.get(0)); |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 1456 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1457 | } |
| 1458 | return -1; |
| 1459 | } |
| 1460 | |
| 1461 | public int getBluetoothPingCount() { |
| 1462 | if (mBluetoothPingStart == -1) { |
| 1463 | return mBluetoothPingCount; |
| 1464 | } else if (mBtHeadset != null) { |
| 1465 | return getCurrentBluetoothPingCount() - mBluetoothPingStart; |
| 1466 | } |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1467 | return 0; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | public void setBtHeadset(BluetoothHeadset headset) { |
Amith Yamasani | 82cb029 | 2009-08-18 11:29:28 -0700 | [diff] [blame] | 1471 | if (headset != null && mBtHeadset == null && isOnBattery() && mBluetoothPingStart == -1) { |
| 1472 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 1473 | } |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1474 | mBtHeadset = headset; |
| 1475 | } |
| 1476 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1477 | int mChangedBufferStates = 0; |
| 1478 | |
| 1479 | void addHistoryBufferLocked(long curTime) { |
| 1480 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 1481 | return; |
| 1482 | } |
| 1483 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1484 | final long timeDiff = (mHistoryBaseTime+curTime) - mHistoryLastWritten.time; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1485 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1486 | && timeDiff < 2000 |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1487 | && ((mHistoryLastWritten.states^mHistoryCur.states)&mChangedBufferStates) == 0) { |
| 1488 | // If the current is the same as the one before, then we no |
| 1489 | // longer need the entry. |
| 1490 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 1491 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 1492 | mHistoryBufferLastPos = -1; |
| 1493 | if (mHistoryLastLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1494 | && timeDiff < 500 && mHistoryLastLastWritten.same(mHistoryCur)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1495 | // If this results in us returning to the state written |
| 1496 | // prior to the last one, then we can just delete the last |
| 1497 | // written one and drop the new one. Nothing more to do. |
| 1498 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
| 1499 | mHistoryLastLastWritten.cmd = HistoryItem.CMD_NULL; |
| 1500 | return; |
| 1501 | } |
| 1502 | mChangedBufferStates |= mHistoryLastWritten.states^mHistoryCur.states; |
| 1503 | curTime = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1504 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1505 | } else { |
| 1506 | mChangedBufferStates = 0; |
| 1507 | } |
| 1508 | |
| 1509 | final int dataSize = mHistoryBuffer.dataSize(); |
| 1510 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 1511 | if (!mHistoryOverflow) { |
| 1512 | mHistoryOverflow = true; |
| 1513 | addHistoryBufferLocked(curTime, HistoryItem.CMD_OVERFLOW); |
| 1514 | } |
| 1515 | |
| 1516 | // Once we've reached the maximum number of items, we only |
| 1517 | // record changes to the battery level and the most interesting states. |
| 1518 | // Once we've reached the maximum maximum number of items, we only |
| 1519 | // record changes to the battery level. |
| 1520 | if (mHistoryLastWritten.batteryLevel == mHistoryCur.batteryLevel && |
| 1521 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Amith Yamasani | 45f0646 | 2011-11-21 16:08:34 -0800 | [diff] [blame] | 1522 | || ((mHistoryLastWritten.states^mHistoryCur.states) |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1523 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
| 1524 | return; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | addHistoryBufferLocked(curTime, HistoryItem.CMD_UPDATE); |
| 1529 | } |
| 1530 | |
| 1531 | void addHistoryBufferLocked(long curTime, byte cmd) { |
| 1532 | int origPos = 0; |
| 1533 | if (mIteratingHistory) { |
| 1534 | origPos = mHistoryBuffer.dataPosition(); |
| 1535 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
| 1536 | } |
| 1537 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 1538 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
| 1539 | mHistoryLastWritten.setTo(mHistoryBaseTime + curTime, cmd, mHistoryCur); |
| 1540 | mHistoryLastWritten.writeDelta(mHistoryBuffer, mHistoryLastLastWritten); |
| 1541 | mLastHistoryTime = curTime; |
| 1542 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 1543 | + " now " + mHistoryBuffer.dataPosition() |
| 1544 | + " size is now " + mHistoryBuffer.dataSize()); |
| 1545 | if (mIteratingHistory) { |
| 1546 | mHistoryBuffer.setDataPosition(origPos); |
| 1547 | } |
| 1548 | } |
| 1549 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1550 | int mChangedStates = 0; |
| 1551 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1552 | void addHistoryRecordLocked(long curTime) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1553 | addHistoryBufferLocked(curTime); |
| 1554 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 1555 | if (!USE_OLD_HISTORY) { |
| 1556 | return; |
| 1557 | } |
| 1558 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1559 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 1560 | return; |
| 1561 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1562 | |
| 1563 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1564 | // and no states have since the last recorded entry changed and |
| 1565 | // are now resetting back to their original value, then just collapse |
| 1566 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1567 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1568 | && (mHistoryBaseTime+curTime) < (mHistoryEnd.time+2000) |
| 1569 | && ((mHistoryEnd.states^mHistoryCur.states)&mChangedStates) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1570 | // If the current is the same as the one before, then we no |
| 1571 | // longer need the entry. |
| 1572 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1573 | && (mHistoryBaseTime+curTime) < (mHistoryEnd.time+500) |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1574 | && mHistoryLastEnd.same(mHistoryCur)) { |
| 1575 | mHistoryLastEnd.next = null; |
| 1576 | mHistoryEnd.next = mHistoryCache; |
| 1577 | mHistoryCache = mHistoryEnd; |
| 1578 | mHistoryEnd = mHistoryLastEnd; |
| 1579 | mHistoryLastEnd = null; |
| 1580 | } else { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1581 | mChangedStates |= mHistoryEnd.states^mHistoryCur.states; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1582 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, mHistoryCur); |
| 1583 | } |
| 1584 | return; |
| 1585 | } |
| 1586 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1587 | mChangedStates = 0; |
| 1588 | |
| 1589 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 1590 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1591 | addHistoryRecordLocked(curTime, HistoryItem.CMD_OVERFLOW); |
| 1592 | } |
| 1593 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1594 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 1595 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1596 | // record changes to the battery level and the most interesting states. |
| 1597 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1598 | // record changes to the battery level. |
| 1599 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1600 | == mHistoryCur.batteryLevel && |
| 1601 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
| 1602 | || ((mHistoryEnd.states^mHistoryCur.states) |
| 1603 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1604 | return; |
| 1605 | } |
| 1606 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1607 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1608 | addHistoryRecordLocked(curTime, HistoryItem.CMD_UPDATE); |
| 1609 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1610 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1611 | void addHistoryRecordLocked(long curTime, byte cmd) { |
| 1612 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1613 | if (rec != null) { |
| 1614 | mHistoryCache = rec.next; |
| 1615 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1616 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1617 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1618 | rec.setTo(mHistoryBaseTime + curTime, cmd, mHistoryCur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1619 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1620 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1621 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1622 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1623 | void addHistoryRecordLocked(HistoryItem rec) { |
| 1624 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1625 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1626 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1627 | if (mHistoryEnd != null) { |
| 1628 | mHistoryEnd.next = rec; |
| 1629 | mHistoryEnd = rec; |
| 1630 | } else { |
| 1631 | mHistory = mHistoryEnd = rec; |
| 1632 | } |
| 1633 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1634 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1635 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1636 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 1637 | if (USE_OLD_HISTORY) { |
| 1638 | if (mHistory != null) { |
| 1639 | mHistoryEnd.next = mHistoryCache; |
| 1640 | mHistoryCache = mHistory; |
| 1641 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 1642 | } |
| 1643 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1644 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 1645 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1646 | mHistoryBaseTime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1647 | mLastHistoryTime = 0; |
| 1648 | |
| 1649 | mHistoryBuffer.setDataSize(0); |
| 1650 | mHistoryBuffer.setDataPosition(0); |
| 1651 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER/2); |
| 1652 | mHistoryLastLastWritten.cmd = HistoryItem.CMD_NULL; |
| 1653 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 1654 | mHistoryBufferLastPos = -1; |
| 1655 | mHistoryOverflow = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1656 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1657 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1658 | public void doUnplugLocked(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | for (int i = mUnpluggables.size() - 1; i >= 0; i--) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1660 | mUnpluggables.get(i).unplug(elapsedRealtime, batteryUptime, batteryRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 1662 | |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1663 | // Track radio awake time |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1664 | mRadioDataStart = getCurrentRadioDataUptime(); |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1665 | mRadioDataUptime = 0; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 1666 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1667 | // Track bt headset ping count |
| 1668 | mBluetoothPingStart = getCurrentBluetoothPingCount(); |
| 1669 | mBluetoothPingCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1671 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1672 | public void doPlugLocked(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | for (int i = mUnpluggables.size() - 1; i >= 0; i--) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1674 | mUnpluggables.get(i).plug(elapsedRealtime, batteryUptime, batteryRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 1676 | |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1677 | // Track radio awake time |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1678 | mRadioDataUptime = getRadioDataUptime(); |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1679 | mRadioDataStart = -1; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 1680 | |
| 1681 | // Track bt headset ping count |
| 1682 | mBluetoothPingCount = getBluetoothPingCount(); |
| 1683 | mBluetoothPingStart = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1685 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1686 | int mWakeLockNesting; |
| 1687 | |
| 1688 | public void noteStartWakeLocked(int uid, int pid, String name, int type) { |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 1689 | if (type == WAKE_TYPE_PARTIAL) { |
| 1690 | // Only care about partial wake locks, since full wake locks |
| 1691 | // will be canceled when the user puts the screen to sleep. |
| 1692 | if (mWakeLockNesting == 0) { |
| 1693 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 1694 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 1695 | + Integer.toHexString(mHistoryCur.states)); |
| 1696 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
| 1697 | } |
| 1698 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1699 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1700 | if (uid >= 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1701 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 1702 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 1703 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 1704 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1705 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | public void noteStopWakeLocked(int uid, int pid, String name, int type) { |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 1710 | if (type == WAKE_TYPE_PARTIAL) { |
| 1711 | mWakeLockNesting--; |
| 1712 | if (mWakeLockNesting == 0) { |
| 1713 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 1714 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 1715 | + Integer.toHexString(mHistoryCur.states)); |
| 1716 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
| 1717 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1718 | } |
| 1719 | if (uid >= 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1720 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 1721 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 1722 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 1723 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1724 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type); |
| 1725 | } |
| 1726 | } |
| 1727 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1728 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, int type) { |
| 1729 | int N = ws.size(); |
| 1730 | for (int i=0; i<N; i++) { |
| 1731 | noteStartWakeLocked(ws.get(i), pid, name, type); |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, int type) { |
| 1736 | int N = ws.size(); |
| 1737 | for (int i=0; i<N; i++) { |
| 1738 | noteStopWakeLocked(ws.get(i), pid, name, type); |
| 1739 | } |
| 1740 | } |
| 1741 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1742 | public int startAddingCpuLocked() { |
| 1743 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 1744 | |
| 1745 | if (mScreenOn) { |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | final int N = mPartialTimers.size(); |
| 1750 | if (N == 0) { |
| 1751 | mLastPartialTimers.clear(); |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | // How many timers should consume CPU? Only want to include ones |
| 1756 | // that have already been in the list. |
| 1757 | for (int i=0; i<N; i++) { |
| 1758 | StopwatchTimer st = mPartialTimers.get(i); |
| 1759 | if (st.mInList) { |
| 1760 | Uid uid = st.mUid; |
| 1761 | // We don't include the system UID, because it so often |
| 1762 | // holds wake locks at one request or another of an app. |
| 1763 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 1764 | return 50; |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
| 1772 | public void finishAddingCpuLocked(int perc, int utime, int stime, long[] cpuSpeedTimes) { |
| 1773 | final int N = mPartialTimers.size(); |
| 1774 | if (perc != 0) { |
| 1775 | int num = 0; |
| 1776 | for (int i=0; i<N; i++) { |
| 1777 | StopwatchTimer st = mPartialTimers.get(i); |
| 1778 | if (st.mInList) { |
| 1779 | Uid uid = st.mUid; |
| 1780 | // We don't include the system UID, because it so often |
| 1781 | // holds wake locks at one request or another of an app. |
| 1782 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 1783 | num++; |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | if (num != 0) { |
| 1788 | for (int i=0; i<N; i++) { |
| 1789 | StopwatchTimer st = mPartialTimers.get(i); |
| 1790 | if (st.mInList) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1791 | Uid uid = st.mUid; |
| 1792 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
Dianne Hackborn | 618b8c1 | 2010-09-09 23:10:38 -0700 | [diff] [blame] | 1793 | int myUTime = utime/num; |
| 1794 | int mySTime = stime/num; |
| 1795 | utime -= myUTime; |
| 1796 | stime -= mySTime; |
| 1797 | num--; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1798 | Uid.Proc proc = uid.getProcessStatsLocked("*wakelock*"); |
| 1799 | proc.addCpuTimeLocked(myUTime, mySTime); |
| 1800 | proc.addSpeedStepTimes(cpuSpeedTimes); |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | // Just in case, collect any lost CPU time. |
| 1807 | if (utime != 0 || stime != 0) { |
| 1808 | Uid uid = getUidStatsLocked(Process.SYSTEM_UID); |
| 1809 | if (uid != null) { |
| 1810 | Uid.Proc proc = uid.getProcessStatsLocked("*lost*"); |
| 1811 | proc.addCpuTimeLocked(utime, stime); |
| 1812 | proc.addSpeedStepTimes(cpuSpeedTimes); |
| 1813 | } |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | final int NL = mLastPartialTimers.size(); |
| 1818 | boolean diff = N != NL; |
| 1819 | for (int i=0; i<NL && !diff; i++) { |
| 1820 | diff |= mPartialTimers.get(i) != mLastPartialTimers.get(i); |
| 1821 | } |
| 1822 | if (!diff) { |
| 1823 | for (int i=0; i<NL; i++) { |
| 1824 | mPartialTimers.get(i).mInList = true; |
| 1825 | } |
| 1826 | return; |
| 1827 | } |
| 1828 | |
| 1829 | for (int i=0; i<NL; i++) { |
| 1830 | mLastPartialTimers.get(i).mInList = false; |
| 1831 | } |
| 1832 | mLastPartialTimers.clear(); |
| 1833 | for (int i=0; i<N; i++) { |
| 1834 | StopwatchTimer st = mPartialTimers.get(i); |
| 1835 | st.mInList = true; |
| 1836 | mLastPartialTimers.add(st); |
| 1837 | } |
| 1838 | } |
| 1839 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1840 | public void noteProcessDiedLocked(int uid, int pid) { |
| 1841 | Uid u = mUidStats.get(uid); |
| 1842 | if (u != null) { |
| 1843 | u.mPids.remove(pid); |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
| 1848 | Uid u = mUidStats.get(uid); |
| 1849 | if (u != null) { |
| 1850 | Uid.Pid p = u.mPids.get(pid); |
| 1851 | if (p != null) { |
| 1852 | return p.mWakeSum + (p.mWakeStart != 0 ? (realtime - p.mWakeStart) : 0); |
| 1853 | } |
| 1854 | } |
| 1855 | return 0; |
| 1856 | } |
| 1857 | |
| 1858 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
| 1859 | Uid u = mUidStats.get(uid); |
| 1860 | if (u != null) { |
| 1861 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 1862 | } |
| 1863 | } |
| 1864 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1865 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
| 1866 | Uid u = mUidStats.get(uid); |
| 1867 | if (u != null) { |
| 1868 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 1869 | } |
| 1870 | } |
| 1871 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1872 | int mSensorNesting; |
| 1873 | |
| 1874 | public void noteStartSensorLocked(int uid, int sensor) { |
| 1875 | if (mSensorNesting == 0) { |
| 1876 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 1877 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 1878 | + Integer.toHexString(mHistoryCur.states)); |
| 1879 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
| 1880 | } |
| 1881 | mSensorNesting++; |
| 1882 | getUidStatsLocked(uid).noteStartSensor(sensor); |
| 1883 | } |
| 1884 | |
| 1885 | public void noteStopSensorLocked(int uid, int sensor) { |
| 1886 | mSensorNesting--; |
| 1887 | if (mSensorNesting == 0) { |
| 1888 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 1889 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 1890 | + Integer.toHexString(mHistoryCur.states)); |
| 1891 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
| 1892 | } |
| 1893 | getUidStatsLocked(uid).noteStopSensor(sensor); |
| 1894 | } |
| 1895 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1896 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1897 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1898 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1899 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1900 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1901 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 1902 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1903 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1904 | } |
| 1905 | mGpsNesting++; |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 1906 | getUidStatsLocked(uid).noteStartGps(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1908 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1909 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1910 | mGpsNesting--; |
| 1911 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1912 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1913 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 1914 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1915 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1916 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 1917 | getUidStatsLocked(uid).noteStopGps(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | public void noteScreenOnLocked() { |
| 1921 | if (!mScreenOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1922 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1923 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 1924 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1925 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | mScreenOn = true; |
| 1927 | mScreenOnTimer.startRunningLocked(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1928 | if (mScreenBrightnessBin >= 0) { |
| 1929 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(this); |
| 1930 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1931 | |
| 1932 | // Fake a wake lock, so we consider the device waked as long |
| 1933 | // as the screen is on. |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 1934 | noteStartWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1935 | |
| 1936 | // Update discharge amounts. |
| 1937 | if (mOnBatteryInternal) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 1938 | updateDischargeScreenLevelsLocked(false, true); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | } |
| 1941 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | public void noteScreenOffLocked() { |
| 1944 | if (mScreenOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1945 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1946 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 1947 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1948 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | mScreenOn = false; |
| 1950 | mScreenOnTimer.stopRunningLocked(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1951 | if (mScreenBrightnessBin >= 0) { |
| 1952 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this); |
| 1953 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1954 | |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 1955 | noteStopWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1956 | |
| 1957 | // Update discharge amounts. |
| 1958 | if (mOnBatteryInternal) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 1959 | updateDischargeScreenLevelsLocked(true, false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1960 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1961 | } |
| 1962 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1963 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1964 | public void noteScreenBrightnessLocked(int brightness) { |
| 1965 | // Bin the brightness. |
| 1966 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 1967 | if (bin < 0) bin = 0; |
| 1968 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 1969 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1970 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 1971 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1972 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 1973 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1974 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1975 | if (mScreenOn) { |
| 1976 | if (mScreenBrightnessBin >= 0) { |
| 1977 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this); |
| 1978 | } |
| 1979 | mScreenBrightnessTimer[bin].startRunningLocked(this); |
| 1980 | } |
| 1981 | mScreenBrightnessBin = bin; |
| 1982 | } |
| 1983 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1984 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1985 | public void noteInputEventAtomic() { |
| 1986 | mInputEventCounter.stepAtomic(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1987 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1988 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1989 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 1990 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1991 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | public void notePhoneOnLocked() { |
| 1994 | if (!mPhoneOn) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1995 | mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1996 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 1997 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1998 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | mPhoneOn = true; |
| 2000 | mPhoneOnTimer.startRunningLocked(this); |
| 2001 | } |
| 2002 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | public void notePhoneOffLocked() { |
| 2005 | if (mPhoneOn) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2006 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2007 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 2008 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2009 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | mPhoneOn = false; |
| 2011 | mPhoneOnTimer.stopRunningLocked(this); |
| 2012 | } |
| 2013 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2014 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2015 | void stopAllSignalStrengthTimersLocked(int except) { |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2016 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2017 | if (i == except) { |
| 2018 | continue; |
| 2019 | } |
| 2020 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
| 2021 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(this); |
| 2022 | } |
| 2023 | } |
| 2024 | } |
| 2025 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2026 | private int fixPhoneServiceState(int state, int signalBin) { |
| 2027 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 2028 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 2029 | // to infer that we are scanning from other data. |
| 2030 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2031 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2032 | state = ServiceState.STATE_IN_SERVICE; |
| 2033 | } |
| 2034 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2035 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2036 | return state; |
| 2037 | } |
| 2038 | |
| 2039 | private void updateAllPhoneStateLocked(int state, int simState, int bin) { |
| 2040 | boolean scanning = false; |
| 2041 | boolean newHistory = false; |
| 2042 | |
| 2043 | mPhoneServiceStateRaw = state; |
| 2044 | mPhoneSimStateRaw = simState; |
| 2045 | mPhoneSignalStrengthBinRaw = bin; |
| 2046 | |
| 2047 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 2048 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 2049 | // to infer that we are scanning from other data. |
| 2050 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2051 | && bin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2052 | state = ServiceState.STATE_IN_SERVICE; |
| 2053 | } |
| 2054 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2055 | |
| 2056 | // If the phone is powered off, stop all timers. |
| 2057 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2058 | bin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2059 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2060 | // If we are in service, make sure the correct signal string timer is running. |
| 2061 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 2062 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2063 | |
| 2064 | // If we're out of service, we are in the lowest signal strength |
| 2065 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2066 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2067 | scanning = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2068 | bin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2069 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2070 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2071 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2072 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 2073 | + Integer.toHexString(mHistoryCur.states)); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2074 | mPhoneSignalScanningTimer.startRunningLocked(this); |
| 2075 | } |
| 2076 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2077 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2078 | if (!scanning) { |
| 2079 | // If we are no longer scanning, then stop the scanning timer. |
| 2080 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 2081 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 2082 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 2083 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2084 | newHistory = true; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2085 | mPhoneSignalScanningTimer.stopRunningLocked(this); |
| 2086 | } |
| 2087 | } |
| 2088 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2089 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2090 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 2091 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2092 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2093 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2094 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2095 | mPhoneServiceState = state; |
| 2096 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2097 | |
| 2098 | if (mPhoneSignalStrengthBin != bin) { |
| 2099 | if (mPhoneSignalStrengthBin >= 0) { |
| 2100 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked(this); |
| 2101 | } |
| 2102 | if (bin >= 0) { |
| 2103 | if (!mPhoneSignalStrengthsTimer[bin].isRunningLocked()) { |
| 2104 | mPhoneSignalStrengthsTimer[bin].startRunningLocked(this); |
| 2105 | } |
| 2106 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_SIGNAL_STRENGTH_MASK) |
| 2107 | | (bin << HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT); |
| 2108 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + bin + " to: " |
| 2109 | + Integer.toHexString(mHistoryCur.states)); |
| 2110 | newHistory = true; |
| 2111 | } else { |
| 2112 | stopAllSignalStrengthTimersLocked(-1); |
| 2113 | } |
| 2114 | mPhoneSignalStrengthBin = bin; |
| 2115 | } |
| 2116 | |
| 2117 | if (newHistory) { |
| 2118 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | /** |
| 2123 | * Telephony stack updates the phone state. |
| 2124 | * @param state phone state from ServiceState.getState() |
| 2125 | */ |
| 2126 | public void notePhoneStateLocked(int state, int simState) { |
| 2127 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2130 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2131 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2132 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2133 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2134 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2135 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2136 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 2137 | int bin = DATA_CONNECTION_NONE; |
| 2138 | if (hasData) { |
| 2139 | switch (dataType) { |
| 2140 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 2141 | bin = DATA_CONNECTION_EDGE; |
| 2142 | break; |
| 2143 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 2144 | bin = DATA_CONNECTION_GPRS; |
| 2145 | break; |
| 2146 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 2147 | bin = DATA_CONNECTION_UMTS; |
| 2148 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2149 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 2150 | bin = DATA_CONNECTION_CDMA; |
| 2151 | break; |
| 2152 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 2153 | bin = DATA_CONNECTION_EVDO_0; |
| 2154 | break; |
| 2155 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 2156 | bin = DATA_CONNECTION_EVDO_A; |
| 2157 | break; |
| 2158 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 2159 | bin = DATA_CONNECTION_1xRTT; |
| 2160 | break; |
| 2161 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 2162 | bin = DATA_CONNECTION_HSDPA; |
| 2163 | break; |
| 2164 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 2165 | bin = DATA_CONNECTION_HSUPA; |
| 2166 | break; |
| 2167 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 2168 | bin = DATA_CONNECTION_HSPA; |
| 2169 | break; |
| 2170 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 2171 | bin = DATA_CONNECTION_IDEN; |
| 2172 | break; |
| 2173 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 2174 | bin = DATA_CONNECTION_EVDO_B; |
| 2175 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2176 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 2177 | bin = DATA_CONNECTION_LTE; |
| 2178 | break; |
| 2179 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 2180 | bin = DATA_CONNECTION_EHRPD; |
| 2181 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2182 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 2183 | bin = DATA_CONNECTION_HSPAP; |
| 2184 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2185 | default: |
| 2186 | bin = DATA_CONNECTION_OTHER; |
| 2187 | break; |
| 2188 | } |
| 2189 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2190 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2191 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2192 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 2193 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2194 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 2195 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2196 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2197 | if (mPhoneDataConnectionType >= 0) { |
| 2198 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked(this); |
| 2199 | } |
| 2200 | mPhoneDataConnectionType = bin; |
| 2201 | mPhoneDataConnectionsTimer[bin].startRunningLocked(this); |
| 2202 | } |
| 2203 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2204 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2205 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2206 | if (!mWifiOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2207 | mHistoryCur.states |= HistoryItem.STATE_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2208 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 2209 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2210 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2211 | mWifiOn = true; |
| 2212 | mWifiOnTimer.startRunningLocked(this); |
| 2213 | } |
| 2214 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2215 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2216 | public void noteWifiOffLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2217 | if (mWifiOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2218 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2219 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 2220 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2221 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2222 | mWifiOn = false; |
| 2223 | mWifiOnTimer.stopRunningLocked(this); |
| 2224 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2225 | if (mWifiOnUid >= 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2226 | getUidStatsLocked(mWifiOnUid).noteWifiStoppedLocked(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2227 | mWifiOnUid = -1; |
| 2228 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2229 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2230 | |
| 2231 | public void noteAudioOnLocked(int uid) { |
| 2232 | if (!mAudioOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2233 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2234 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 2235 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2236 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2237 | mAudioOn = true; |
| 2238 | mAudioOnTimer.startRunningLocked(this); |
| 2239 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2240 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2241 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2242 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2243 | public void noteAudioOffLocked(int uid) { |
| 2244 | if (mAudioOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2245 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2246 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 2247 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2248 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2249 | mAudioOn = false; |
| 2250 | mAudioOnTimer.stopRunningLocked(this); |
| 2251 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2252 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | public void noteVideoOnLocked(int uid) { |
| 2256 | if (!mVideoOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2257 | mHistoryCur.states |= HistoryItem.STATE_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2258 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 2259 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2260 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2261 | mVideoOn = true; |
| 2262 | mVideoOnTimer.startRunningLocked(this); |
| 2263 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2264 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2266 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2267 | public void noteVideoOffLocked(int uid) { |
| 2268 | if (mVideoOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2269 | mHistoryCur.states &= ~HistoryItem.STATE_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2270 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 2271 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2272 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2273 | mVideoOn = false; |
| 2274 | mVideoOnTimer.stopRunningLocked(this); |
| 2275 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2276 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2279 | public void noteActivityResumedLocked(int uid) { |
| 2280 | getUidStatsLocked(uid).noteActivityResumedLocked(); |
| 2281 | } |
| 2282 | |
| 2283 | public void noteActivityPausedLocked(int uid) { |
| 2284 | getUidStatsLocked(uid).noteActivityPausedLocked(); |
| 2285 | } |
| 2286 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2287 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
| 2288 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 2289 | } |
| 2290 | |
| 2291 | public void noteVibratorOffLocked(int uid) { |
| 2292 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 2293 | } |
| 2294 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2295 | public void noteWifiRunningLocked(WorkSource ws) { |
| 2296 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2297 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2298 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 2299 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2300 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2301 | mGlobalWifiRunning = true; |
| 2302 | mGlobalWifiRunningTimer.startRunningLocked(this); |
| 2303 | int N = ws.size(); |
| 2304 | for (int i=0; i<N; i++) { |
| 2305 | getUidStatsLocked(ws.get(i)).noteWifiRunningLocked(); |
| 2306 | } |
| 2307 | } else { |
| 2308 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2309 | } |
| 2310 | } |
| 2311 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2312 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 2313 | if (mGlobalWifiRunning) { |
| 2314 | int N = oldWs.size(); |
| 2315 | for (int i=0; i<N; i++) { |
| 2316 | getUidStatsLocked(oldWs.get(i)).noteWifiStoppedLocked(); |
| 2317 | } |
| 2318 | N = newWs.size(); |
| 2319 | for (int i=0; i<N; i++) { |
| 2320 | getUidStatsLocked(newWs.get(i)).noteWifiRunningLocked(); |
| 2321 | } |
| 2322 | } else { |
| 2323 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 2328 | if (mGlobalWifiRunning) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2329 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2330 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 2331 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2332 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2333 | mGlobalWifiRunning = false; |
| 2334 | mGlobalWifiRunningTimer.stopRunningLocked(this); |
| 2335 | int N = ws.size(); |
| 2336 | for (int i=0; i<N; i++) { |
| 2337 | getUidStatsLocked(ws.get(i)).noteWifiStoppedLocked(); |
| 2338 | } |
| 2339 | } else { |
| 2340 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2341 | } |
| 2342 | } |
| 2343 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2344 | public void noteBluetoothOnLocked() { |
| 2345 | if (!mBluetoothOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2346 | mHistoryCur.states |= HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2347 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth on to: " |
| 2348 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2349 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2350 | mBluetoothOn = true; |
| 2351 | mBluetoothOnTimer.startRunningLocked(this); |
| 2352 | } |
| 2353 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2354 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2355 | public void noteBluetoothOffLocked() { |
| 2356 | if (mBluetoothOn) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2357 | mHistoryCur.states &= ~HistoryItem.STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2358 | if (DEBUG_HISTORY) Slog.v(TAG, "Bluetooth off to: " |
| 2359 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2360 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2361 | mBluetoothOn = false; |
| 2362 | mBluetoothOnTimer.stopRunningLocked(this); |
| 2363 | } |
| 2364 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2365 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2366 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2367 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2368 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2369 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2370 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2371 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 2372 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2373 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2374 | } |
| 2375 | mWifiFullLockNesting++; |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2376 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2380 | mWifiFullLockNesting--; |
| 2381 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2382 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2383 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 2384 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2385 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2386 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2387 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2390 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2391 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2392 | public void noteWifiScanStartedLocked(int uid) { |
| 2393 | if (mWifiScanNesting == 0) { |
| 2394 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 2395 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2396 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2397 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2398 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2399 | mWifiScanNesting++; |
| 2400 | getUidStatsLocked(uid).noteWifiScanStartedLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2403 | public void noteWifiScanStoppedLocked(int uid) { |
| 2404 | mWifiScanNesting--; |
| 2405 | if (mWifiScanNesting == 0) { |
| 2406 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 2407 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2408 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2409 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2410 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2411 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2412 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2413 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2414 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
| 2415 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph); |
| 2416 | } |
| 2417 | |
| 2418 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
| 2419 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(); |
| 2420 | } |
| 2421 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2422 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2423 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2424 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2425 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2426 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2427 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 2428 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2429 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2430 | } |
| 2431 | mWifiMulticastNesting++; |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2432 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2436 | mWifiMulticastNesting--; |
| 2437 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2438 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2439 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 2440 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2441 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2442 | } |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 2443 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2446 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 2447 | int N = ws.size(); |
| 2448 | for (int i=0; i<N; i++) { |
| 2449 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 2454 | int N = ws.size(); |
| 2455 | for (int i=0; i<N; i++) { |
| 2456 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 2457 | } |
| 2458 | } |
| 2459 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2460 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2461 | int N = ws.size(); |
| 2462 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2463 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2467 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2468 | int N = ws.size(); |
| 2469 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2470 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2474 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 2475 | int N = ws.size(); |
| 2476 | for (int i=0; i<N; i++) { |
| 2477 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 2482 | int N = ws.size(); |
| 2483 | for (int i=0; i<N; i++) { |
| 2484 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 2485 | } |
| 2486 | } |
| 2487 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2488 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 2489 | int N = ws.size(); |
| 2490 | for (int i=0; i<N; i++) { |
| 2491 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 2496 | int N = ws.size(); |
| 2497 | for (int i=0; i<N; i++) { |
| 2498 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 2499 | } |
| 2500 | } |
| 2501 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2502 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
| 2503 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 2504 | mMobileIfaces.add(iface); |
| 2505 | } else { |
| 2506 | mMobileIfaces.remove(iface); |
| 2507 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2508 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 2509 | mWifiIfaces.add(iface); |
| 2510 | } else { |
| 2511 | mWifiIfaces.remove(iface); |
| 2512 | } |
| 2513 | } |
| 2514 | |
| 2515 | public void noteNetworkStatsEnabledLocked() { |
| 2516 | // During device boot, qtaguid isn't enabled until after the inital |
| 2517 | // loading of battery stats. Now that they're enabled, take our initial |
| 2518 | // snapshot for future delta calculation. |
| 2519 | updateNetworkActivityLocked(); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | @Override public long getScreenOnTime(long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2523 | return mScreenOnTimer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2525 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2526 | @Override public long getScreenBrightnessTime(int brightnessBin, |
| 2527 | long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2528 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2529 | batteryRealtime, which); |
| 2530 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2531 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2532 | @Override public int getInputEventCount(int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2533 | return mInputEventCounter.getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2534 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | @Override public long getPhoneOnTime(long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2537 | return mPhoneOnTimer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2539 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2540 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
| 2541 | long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2542 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2543 | batteryRealtime, which); |
| 2544 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2545 | |
| 2546 | @Override public long getPhoneSignalScanningTime( |
| 2547 | long batteryRealtime, int which) { |
| 2548 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
| 2549 | batteryRealtime, which); |
| 2550 | } |
| 2551 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 2552 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 2553 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2554 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2555 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2556 | @Override public long getPhoneDataConnectionTime(int dataType, |
| 2557 | long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2558 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2559 | batteryRealtime, which); |
| 2560 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2561 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2562 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2563 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2564 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2565 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2566 | @Override public long getWifiOnTime(long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2567 | return mWifiOnTimer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2568 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2569 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2570 | @Override public long getGlobalWifiRunningTime(long batteryRealtime, int which) { |
| 2571 | return mGlobalWifiRunningTimer.getTotalTimeLocked(batteryRealtime, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2574 | @Override public long getBluetoothOnTime(long batteryRealtime, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2575 | return mBluetoothOnTimer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2576 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2577 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2578 | @Override |
| 2579 | public long getNetworkActivityCount(int type, int which) { |
| 2580 | if (type >= 0 && type < mNetworkActivityCounters.length) { |
| 2581 | return mNetworkActivityCounters[type].getCountLocked(which); |
| 2582 | } else { |
| 2583 | return 0; |
| 2584 | } |
| 2585 | } |
| 2586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | @Override public boolean getIsOnBattery() { |
| 2588 | return mOnBattery; |
| 2589 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 2592 | return mUidStats; |
| 2593 | } |
| 2594 | |
| 2595 | /** |
| 2596 | * The statistics associated with a particular uid. |
| 2597 | */ |
| 2598 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2600 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2601 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2602 | boolean mWifiRunning; |
| 2603 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2604 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2605 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2606 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2607 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2608 | boolean mWifiScanStarted; |
| 2609 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2610 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2611 | private static final int NO_BATCHED_SCAN_STARTED = -1; |
| 2612 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 2613 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 2614 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2615 | boolean mWifiMulticastEnabled; |
| 2616 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2617 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2618 | boolean mAudioTurnedOn; |
| 2619 | StopwatchTimer mAudioTurnedOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2620 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2621 | boolean mVideoTurnedOn; |
| 2622 | StopwatchTimer mVideoTurnedOnTimer; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2623 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2624 | StopwatchTimer mForegroundActivityTimer; |
| 2625 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2626 | BatchTimer mVibratorOnTimer; |
| 2627 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2628 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2629 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2630 | LongSamplingCounter[] mNetworkActivityCounters; |
| 2631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | /** |
| 2633 | * The statistics we have collected for this uid's wake locks. |
| 2634 | */ |
| 2635 | final HashMap<String, Wakelock> mWakelockStats = new HashMap<String, Wakelock>(); |
| 2636 | |
| 2637 | /** |
| 2638 | * The statistics we have collected for this uid's sensor activations. |
| 2639 | */ |
| 2640 | final HashMap<Integer, Sensor> mSensorStats = new HashMap<Integer, Sensor>(); |
| 2641 | |
| 2642 | /** |
| 2643 | * The statistics we have collected for this uid's processes. |
| 2644 | */ |
| 2645 | final HashMap<String, Proc> mProcessStats = new HashMap<String, Proc>(); |
| 2646 | |
| 2647 | /** |
| 2648 | * The statistics we have collected for this uid's processes. |
| 2649 | */ |
| 2650 | final HashMap<String, Pkg> mPackageStats = new HashMap<String, Pkg>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2651 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2652 | /** |
| 2653 | * The transient wake stats we have collected for this uid's pids. |
| 2654 | */ |
| 2655 | final SparseArray<Pid> mPids = new SparseArray<Pid>(); |
| 2656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | public Uid(int uid) { |
| 2658 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2659 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
| 2660 | mWifiRunningTimers, mUnpluggables); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2661 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2662 | mFullWifiLockTimers, mUnpluggables); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2663 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
| 2664 | mWifiScanTimers, mUnpluggables); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2665 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2666 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2667 | mWifiMulticastTimers, mUnpluggables); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | @Override |
| 2671 | public Map<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
| 2672 | return mWakelockStats; |
| 2673 | } |
| 2674 | |
| 2675 | @Override |
| 2676 | public Map<Integer, ? extends BatteryStats.Uid.Sensor> getSensorStats() { |
| 2677 | return mSensorStats; |
| 2678 | } |
| 2679 | |
| 2680 | @Override |
| 2681 | public Map<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
| 2682 | return mProcessStats; |
| 2683 | } |
| 2684 | |
| 2685 | @Override |
| 2686 | public Map<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
| 2687 | return mPackageStats; |
| 2688 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2689 | |
| 2690 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | public int getUid() { |
| 2692 | return mUid; |
| 2693 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2694 | |
| 2695 | @Override |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2696 | public void noteWifiRunningLocked() { |
| 2697 | if (!mWifiRunning) { |
| 2698 | mWifiRunning = true; |
| 2699 | if (mWifiRunningTimer == null) { |
| 2700 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
| 2701 | mWifiRunningTimers, mUnpluggables); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2702 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2703 | mWifiRunningTimer.startRunningLocked(BatteryStatsImpl.this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2704 | } |
| 2705 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2706 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2707 | @Override |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2708 | public void noteWifiStoppedLocked() { |
| 2709 | if (mWifiRunning) { |
| 2710 | mWifiRunning = false; |
| 2711 | mWifiRunningTimer.stopRunningLocked(BatteryStatsImpl.this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2712 | } |
| 2713 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2714 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2715 | @Override |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2716 | public void noteFullWifiLockAcquiredLocked() { |
| 2717 | if (!mFullWifiLockOut) { |
| 2718 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2719 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2720 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2721 | mFullWifiLockTimers, mUnpluggables); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2722 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2723 | mFullWifiLockTimer.startRunningLocked(BatteryStatsImpl.this); |
| 2724 | } |
| 2725 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2726 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2727 | @Override |
| 2728 | public void noteFullWifiLockReleasedLocked() { |
| 2729 | if (mFullWifiLockOut) { |
| 2730 | mFullWifiLockOut = false; |
| 2731 | mFullWifiLockTimer.stopRunningLocked(BatteryStatsImpl.this); |
| 2732 | } |
| 2733 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2734 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2735 | @Override |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2736 | public void noteWifiScanStartedLocked() { |
| 2737 | if (!mWifiScanStarted) { |
| 2738 | mWifiScanStarted = true; |
| 2739 | if (mWifiScanTimer == null) { |
| 2740 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
| 2741 | mWifiScanTimers, mUnpluggables); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2742 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2743 | mWifiScanTimer.startRunningLocked(BatteryStatsImpl.this); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2744 | } |
| 2745 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2746 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2747 | @Override |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2748 | public void noteWifiScanStoppedLocked() { |
| 2749 | if (mWifiScanStarted) { |
| 2750 | mWifiScanStarted = false; |
| 2751 | mWifiScanTimer.stopRunningLocked(BatteryStatsImpl.this); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2752 | } |
| 2753 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2754 | |
| 2755 | @Override |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2756 | public void noteWifiBatchedScanStartedLocked(int csph) { |
| 2757 | int bin = 0; |
| 2758 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS) { |
| 2759 | csph = csph >> 3; |
| 2760 | bin++; |
| 2761 | } |
| 2762 | |
| 2763 | if (mWifiBatchedScanBinStarted == bin) return; |
| 2764 | |
| 2765 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 2766 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
| 2767 | stopRunningLocked(BatteryStatsImpl.this); |
| 2768 | } |
| 2769 | mWifiBatchedScanBinStarted = bin; |
| 2770 | if (mWifiBatchedScanTimer[bin] == null) { |
| 2771 | makeWifiBatchedScanBin(bin, null); |
| 2772 | } |
| 2773 | mWifiBatchedScanTimer[bin].startRunningLocked(BatteryStatsImpl.this); |
| 2774 | } |
| 2775 | |
| 2776 | @Override |
| 2777 | public void noteWifiBatchedScanStoppedLocked() { |
| 2778 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 2779 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
| 2780 | stopRunningLocked(BatteryStatsImpl.this); |
| 2781 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | @Override |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2786 | public void noteWifiMulticastEnabledLocked() { |
| 2787 | if (!mWifiMulticastEnabled) { |
| 2788 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2789 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2790 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2791 | mWifiMulticastTimers, mUnpluggables); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2792 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2793 | mWifiMulticastTimer.startRunningLocked(BatteryStatsImpl.this); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | @Override |
| 2798 | public void noteWifiMulticastDisabledLocked() { |
| 2799 | if (mWifiMulticastEnabled) { |
| 2800 | mWifiMulticastEnabled = false; |
| 2801 | mWifiMulticastTimer.stopRunningLocked(BatteryStatsImpl.this); |
| 2802 | } |
| 2803 | } |
| 2804 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2805 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 2806 | if (mAudioTurnedOnTimer == null) { |
| 2807 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
| 2808 | null, mUnpluggables); |
| 2809 | } |
| 2810 | return mAudioTurnedOnTimer; |
| 2811 | } |
| 2812 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2813 | @Override |
| 2814 | public void noteAudioTurnedOnLocked() { |
| 2815 | if (!mAudioTurnedOn) { |
| 2816 | mAudioTurnedOn = true; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2817 | createAudioTurnedOnTimerLocked().startRunningLocked(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | @Override |
| 2822 | public void noteAudioTurnedOffLocked() { |
| 2823 | if (mAudioTurnedOn) { |
| 2824 | mAudioTurnedOn = false; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2825 | if (mAudioTurnedOnTimer != null) { |
| 2826 | mAudioTurnedOnTimer.stopRunningLocked(BatteryStatsImpl.this); |
| 2827 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2828 | } |
| 2829 | } |
| 2830 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2831 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 2832 | if (mVideoTurnedOnTimer == null) { |
| 2833 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
| 2834 | null, mUnpluggables); |
| 2835 | } |
| 2836 | return mVideoTurnedOnTimer; |
| 2837 | } |
| 2838 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2839 | @Override |
| 2840 | public void noteVideoTurnedOnLocked() { |
| 2841 | if (!mVideoTurnedOn) { |
| 2842 | mVideoTurnedOn = true; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2843 | createVideoTurnedOnTimerLocked().startRunningLocked(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | @Override |
| 2848 | public void noteVideoTurnedOffLocked() { |
| 2849 | if (mVideoTurnedOn) { |
| 2850 | mVideoTurnedOn = false; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2851 | if (mVideoTurnedOnTimer != null) { |
| 2852 | mVideoTurnedOnTimer.stopRunningLocked(BatteryStatsImpl.this); |
| 2853 | } |
| 2854 | } |
| 2855 | } |
| 2856 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2857 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 2858 | if (mForegroundActivityTimer == null) { |
| 2859 | mForegroundActivityTimer = new StopwatchTimer( |
| 2860 | Uid.this, FOREGROUND_ACTIVITY, null, mUnpluggables); |
| 2861 | } |
| 2862 | return mForegroundActivityTimer; |
| 2863 | } |
| 2864 | |
| 2865 | @Override |
| 2866 | public void noteActivityResumedLocked() { |
| 2867 | // We always start, since we want multiple foreground PIDs to nest |
| 2868 | createForegroundActivityTimerLocked().startRunningLocked(BatteryStatsImpl.this); |
| 2869 | } |
| 2870 | |
| 2871 | @Override |
| 2872 | public void noteActivityPausedLocked() { |
| 2873 | if (mForegroundActivityTimer != null) { |
| 2874 | mForegroundActivityTimer.stopRunningLocked(BatteryStatsImpl.this); |
| 2875 | } |
| 2876 | } |
| 2877 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2878 | public BatchTimer createVibratorOnTimerLocked() { |
| 2879 | if (mVibratorOnTimer == null) { |
| 2880 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, |
| 2881 | mUnpluggables, BatteryStatsImpl.this.mOnBatteryInternal); |
| 2882 | } |
| 2883 | return mVibratorOnTimer; |
| 2884 | } |
| 2885 | |
| 2886 | public void noteVibratorOnLocked(long durationMillis) { |
| 2887 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 2888 | } |
| 2889 | |
| 2890 | public void noteVibratorOffLocked() { |
| 2891 | if (mVibratorOnTimer != null) { |
| 2892 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2893 | } |
| 2894 | } |
| 2895 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2896 | @Override |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2897 | public long getWifiRunningTime(long batteryRealtime, int which) { |
| 2898 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2899 | return 0; |
| 2900 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2901 | return mWifiRunningTimer.getTotalTimeLocked(batteryRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2902 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 2903 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2904 | @Override |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2905 | public long getFullWifiLockTime(long batteryRealtime, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2906 | if (mFullWifiLockTimer == null) { |
| 2907 | return 0; |
| 2908 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2909 | return mFullWifiLockTimer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2910 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2911 | |
| 2912 | @Override |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2913 | public long getWifiScanTime(long batteryRealtime, int which) { |
| 2914 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2915 | return 0; |
| 2916 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2917 | return mWifiScanTimer.getTotalTimeLocked(batteryRealtime, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2918 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2919 | |
| 2920 | @Override |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2921 | public long getWifiBatchedScanTime(int csphBin, long batteryRealtime, int which) { |
| 2922 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 2923 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 2924 | return 0; |
| 2925 | } |
| 2926 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(batteryRealtime, which); |
| 2927 | } |
| 2928 | |
| 2929 | @Override |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2930 | public long getWifiMulticastTime(long batteryRealtime, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2931 | if (mWifiMulticastTimer == null) { |
| 2932 | return 0; |
| 2933 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2934 | return mWifiMulticastTimer.getTotalTimeLocked(batteryRealtime, |
| 2935 | which); |
| 2936 | } |
| 2937 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2938 | @Override |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2939 | public long getAudioTurnedOnTime(long batteryRealtime, int which) { |
| 2940 | if (mAudioTurnedOnTimer == null) { |
| 2941 | return 0; |
| 2942 | } |
| 2943 | return mAudioTurnedOnTimer.getTotalTimeLocked(batteryRealtime, which); |
| 2944 | } |
| 2945 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2946 | @Override |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2947 | public long getVideoTurnedOnTime(long batteryRealtime, int which) { |
| 2948 | if (mVideoTurnedOnTimer == null) { |
| 2949 | return 0; |
| 2950 | } |
| 2951 | return mVideoTurnedOnTimer.getTotalTimeLocked(batteryRealtime, which); |
| 2952 | } |
| 2953 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2954 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2955 | public Timer getForegroundActivityTimer() { |
| 2956 | return mForegroundActivityTimer; |
| 2957 | } |
| 2958 | |
| 2959 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2960 | public Timer getVibratorOnTimer() { |
| 2961 | return mVibratorOnTimer; |
| 2962 | } |
| 2963 | |
| 2964 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2965 | public void noteUserActivityLocked(int type) { |
| 2966 | if (mUserActivityCounters == null) { |
| 2967 | initUserActivityLocked(); |
| 2968 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 2969 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 2970 | mUserActivityCounters[type].stepAtomic(); |
| 2971 | } else { |
| 2972 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 2973 | new Throwable()); |
| 2974 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2975 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2976 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2977 | @Override |
| 2978 | public boolean hasUserActivity() { |
| 2979 | return mUserActivityCounters != null; |
| 2980 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2981 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2982 | @Override |
| 2983 | public int getUserActivityCount(int type, int which) { |
| 2984 | if (mUserActivityCounters == null) { |
| 2985 | return 0; |
| 2986 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2987 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2988 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2989 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2990 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 2991 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 2992 | |
| 2993 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 2994 | if (collected == null) { |
| 2995 | collected = new ArrayList<StopwatchTimer>(); |
| 2996 | mWifiBatchedScanTimers.put(i, collected); |
| 2997 | } |
| 2998 | if (in == null) { |
| 2999 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
| 3000 | mUnpluggables); |
| 3001 | } else { |
| 3002 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
| 3003 | mUnpluggables, in); |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3008 | void initUserActivityLocked() { |
| 3009 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 3010 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 3011 | mUserActivityCounters[i] = new Counter(mUnpluggables); |
| 3012 | } |
| 3013 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3014 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3015 | void noteNetworkActivityLocked(int type, long delta) { |
| 3016 | if (mNetworkActivityCounters == null) { |
| 3017 | initNetworkActivityLocked(); |
| 3018 | } |
| 3019 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
| 3020 | mNetworkActivityCounters[type].addCountLocked(delta); |
| 3021 | } else { |
| 3022 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 3023 | new Throwable()); |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | @Override |
| 3028 | public boolean hasNetworkActivity() { |
| 3029 | return mNetworkActivityCounters != null; |
| 3030 | } |
| 3031 | |
| 3032 | @Override |
| 3033 | public long getNetworkActivityCount(int type, int which) { |
| 3034 | if (mNetworkActivityCounters != null && type >= 0 |
| 3035 | && type < mNetworkActivityCounters.length) { |
| 3036 | return mNetworkActivityCounters[type].getCountLocked(which); |
| 3037 | } else { |
| 3038 | return 0; |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | void initNetworkActivityLocked() { |
| 3043 | mNetworkActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 3044 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 3045 | mNetworkActivityCounters[i] = new LongSamplingCounter(mUnpluggables); |
| 3046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3048 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3049 | /** |
| 3050 | * Clear all stats for this uid. Returns true if the uid is completely |
| 3051 | * inactive so can be dropped. |
| 3052 | */ |
| 3053 | boolean reset() { |
| 3054 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3055 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3056 | if (mWifiRunningTimer != null) { |
| 3057 | active |= !mWifiRunningTimer.reset(BatteryStatsImpl.this, false); |
| 3058 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3059 | } |
| 3060 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3061 | active |= !mFullWifiLockTimer.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3062 | active |= mFullWifiLockOut; |
| 3063 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3064 | if (mWifiScanTimer != null) { |
| 3065 | active |= !mWifiScanTimer.reset(BatteryStatsImpl.this, false); |
| 3066 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3067 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3068 | if (mWifiBatchedScanTimer != null) { |
| 3069 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 3070 | if (mWifiBatchedScanTimer[i] != null) { |
| 3071 | active |= !mWifiBatchedScanTimer[i].reset(BatteryStatsImpl.this, false); |
| 3072 | } |
| 3073 | } |
| 3074 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 3075 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3076 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3077 | active |= !mWifiMulticastTimer.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3078 | active |= mWifiMulticastEnabled; |
| 3079 | } |
| 3080 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3081 | active |= !mAudioTurnedOnTimer.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3082 | active |= mAudioTurnedOn; |
| 3083 | } |
| 3084 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3085 | active |= !mVideoTurnedOnTimer.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3086 | active |= mVideoTurnedOn; |
| 3087 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3088 | if (mForegroundActivityTimer != null) { |
| 3089 | active |= !mForegroundActivityTimer.reset(BatteryStatsImpl.this, false); |
| 3090 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3091 | if (mVibratorOnTimer != null) { |
| 3092 | if (mVibratorOnTimer.reset(BatteryStatsImpl.this, false)) { |
| 3093 | mVibratorOnTimer.detach(); |
| 3094 | mVibratorOnTimer = null; |
| 3095 | } else { |
| 3096 | active = true; |
| 3097 | } |
| 3098 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3099 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3100 | if (mUserActivityCounters != null) { |
| 3101 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 3102 | mUserActivityCounters[i].reset(false); |
| 3103 | } |
| 3104 | } |
| 3105 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3106 | if (mNetworkActivityCounters != null) { |
| 3107 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 3108 | mNetworkActivityCounters[i].reset(false); |
| 3109 | } |
| 3110 | } |
| 3111 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3112 | if (mWakelockStats.size() > 0) { |
| 3113 | Iterator<Map.Entry<String, Wakelock>> it = mWakelockStats.entrySet().iterator(); |
| 3114 | while (it.hasNext()) { |
| 3115 | Map.Entry<String, Wakelock> wakelockEntry = it.next(); |
| 3116 | Wakelock wl = wakelockEntry.getValue(); |
| 3117 | if (wl.reset()) { |
| 3118 | it.remove(); |
| 3119 | } else { |
| 3120 | active = true; |
| 3121 | } |
| 3122 | } |
| 3123 | } |
| 3124 | if (mSensorStats.size() > 0) { |
| 3125 | Iterator<Map.Entry<Integer, Sensor>> it = mSensorStats.entrySet().iterator(); |
| 3126 | while (it.hasNext()) { |
| 3127 | Map.Entry<Integer, Sensor> sensorEntry = it.next(); |
| 3128 | Sensor s = sensorEntry.getValue(); |
| 3129 | if (s.reset()) { |
| 3130 | it.remove(); |
| 3131 | } else { |
| 3132 | active = true; |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | if (mProcessStats.size() > 0) { |
| 3137 | Iterator<Map.Entry<String, Proc>> it = mProcessStats.entrySet().iterator(); |
| 3138 | while (it.hasNext()) { |
| 3139 | Map.Entry<String, Proc> procEntry = it.next(); |
| 3140 | procEntry.getValue().detach(); |
| 3141 | } |
| 3142 | mProcessStats.clear(); |
| 3143 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3144 | if (mPids.size() > 0) { |
| 3145 | for (int i=0; !active && i<mPids.size(); i++) { |
| 3146 | Pid pid = mPids.valueAt(i); |
| 3147 | if (pid.mWakeStart != 0) { |
| 3148 | active = true; |
| 3149 | } |
| 3150 | } |
| 3151 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3152 | if (mPackageStats.size() > 0) { |
| 3153 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 3154 | while (it.hasNext()) { |
| 3155 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 3156 | Pkg p = pkgEntry.getValue(); |
| 3157 | p.detach(); |
| 3158 | if (p.mServiceStats.size() > 0) { |
| 3159 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 3160 | = p.mServiceStats.entrySet().iterator(); |
| 3161 | while (it2.hasNext()) { |
| 3162 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 3163 | servEntry.getValue().detach(); |
| 3164 | } |
| 3165 | } |
| 3166 | } |
| 3167 | mPackageStats.clear(); |
| 3168 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3169 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3170 | mPids.clear(); |
| 3171 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3172 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3173 | if (mWifiRunningTimer != null) { |
| 3174 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3175 | } |
| 3176 | if (mFullWifiLockTimer != null) { |
| 3177 | mFullWifiLockTimer.detach(); |
| 3178 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3179 | if (mWifiScanTimer != null) { |
| 3180 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3181 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3182 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 3183 | if (mWifiBatchedScanTimer[i] != null) { |
| 3184 | mWifiBatchedScanTimer[i].detach(); |
| 3185 | } |
| 3186 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3187 | if (mWifiMulticastTimer != null) { |
| 3188 | mWifiMulticastTimer.detach(); |
| 3189 | } |
| 3190 | if (mAudioTurnedOnTimer != null) { |
| 3191 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3192 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3193 | } |
| 3194 | if (mVideoTurnedOnTimer != null) { |
| 3195 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3196 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3197 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3198 | if (mForegroundActivityTimer != null) { |
| 3199 | mForegroundActivityTimer.detach(); |
| 3200 | mForegroundActivityTimer = null; |
| 3201 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3202 | if (mUserActivityCounters != null) { |
| 3203 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 3204 | mUserActivityCounters[i].detach(); |
| 3205 | } |
| 3206 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3207 | if (mNetworkActivityCounters != null) { |
| 3208 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 3209 | mNetworkActivityCounters[i].detach(); |
| 3210 | } |
| 3211 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3212 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3213 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3214 | return !active; |
| 3215 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | void writeToParcelLocked(Parcel out, long batteryRealtime) { |
| 3218 | out.writeInt(mWakelockStats.size()); |
| 3219 | for (Map.Entry<String, Uid.Wakelock> wakelockEntry : mWakelockStats.entrySet()) { |
| 3220 | out.writeString(wakelockEntry.getKey()); |
| 3221 | Uid.Wakelock wakelock = wakelockEntry.getValue(); |
| 3222 | wakelock.writeToParcelLocked(out, batteryRealtime); |
| 3223 | } |
| 3224 | |
| 3225 | out.writeInt(mSensorStats.size()); |
| 3226 | for (Map.Entry<Integer, Uid.Sensor> sensorEntry : mSensorStats.entrySet()) { |
| 3227 | out.writeInt(sensorEntry.getKey()); |
| 3228 | Uid.Sensor sensor = sensorEntry.getValue(); |
| 3229 | sensor.writeToParcelLocked(out, batteryRealtime); |
| 3230 | } |
| 3231 | |
| 3232 | out.writeInt(mProcessStats.size()); |
| 3233 | for (Map.Entry<String, Uid.Proc> procEntry : mProcessStats.entrySet()) { |
| 3234 | out.writeString(procEntry.getKey()); |
| 3235 | Uid.Proc proc = procEntry.getValue(); |
| 3236 | proc.writeToParcelLocked(out); |
| 3237 | } |
| 3238 | |
| 3239 | out.writeInt(mPackageStats.size()); |
| 3240 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 3241 | out.writeString(pkgEntry.getKey()); |
| 3242 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 3243 | pkg.writeToParcelLocked(out); |
| 3244 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3245 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3246 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3247 | out.writeInt(1); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3248 | mWifiRunningTimer.writeToParcel(out, batteryRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3249 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3250 | out.writeInt(0); |
| 3251 | } |
| 3252 | if (mFullWifiLockTimer != null) { |
| 3253 | out.writeInt(1); |
| 3254 | mFullWifiLockTimer.writeToParcel(out, batteryRealtime); |
| 3255 | } else { |
| 3256 | out.writeInt(0); |
| 3257 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3258 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3259 | out.writeInt(1); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3260 | mWifiScanTimer.writeToParcel(out, batteryRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3261 | } else { |
| 3262 | out.writeInt(0); |
| 3263 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3264 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 3265 | if (mWifiBatchedScanTimer[i] != null) { |
| 3266 | out.writeInt(1); |
| 3267 | mWifiBatchedScanTimer[i].writeToParcel(out, batteryRealtime); |
| 3268 | } else { |
| 3269 | out.writeInt(0); |
| 3270 | } |
| 3271 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3272 | if (mWifiMulticastTimer != null) { |
| 3273 | out.writeInt(1); |
| 3274 | mWifiMulticastTimer.writeToParcel(out, batteryRealtime); |
| 3275 | } else { |
| 3276 | out.writeInt(0); |
| 3277 | } |
| 3278 | if (mAudioTurnedOnTimer != null) { |
| 3279 | out.writeInt(1); |
| 3280 | mAudioTurnedOnTimer.writeToParcel(out, batteryRealtime); |
| 3281 | } else { |
| 3282 | out.writeInt(0); |
| 3283 | } |
| 3284 | if (mVideoTurnedOnTimer != null) { |
| 3285 | out.writeInt(1); |
| 3286 | mVideoTurnedOnTimer.writeToParcel(out, batteryRealtime); |
| 3287 | } else { |
| 3288 | out.writeInt(0); |
| 3289 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3290 | if (mForegroundActivityTimer != null) { |
| 3291 | out.writeInt(1); |
| 3292 | mForegroundActivityTimer.writeToParcel(out, batteryRealtime); |
| 3293 | } else { |
| 3294 | out.writeInt(0); |
| 3295 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3296 | if (mVibratorOnTimer != null) { |
| 3297 | out.writeInt(1); |
| 3298 | mVibratorOnTimer.writeToParcel(out, batteryRealtime); |
| 3299 | } else { |
| 3300 | out.writeInt(0); |
| 3301 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3302 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3303 | out.writeInt(1); |
| 3304 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 3305 | mUserActivityCounters[i].writeToParcel(out); |
| 3306 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3307 | } else { |
| 3308 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3309 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3310 | if (mNetworkActivityCounters != null) { |
| 3311 | out.writeInt(1); |
| 3312 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 3313 | mNetworkActivityCounters[i].writeToParcel(out); |
| 3314 | } |
| 3315 | } else { |
| 3316 | out.writeInt(0); |
| 3317 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | void readFromParcelLocked(ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 3321 | int numWakelocks = in.readInt(); |
| 3322 | mWakelockStats.clear(); |
| 3323 | for (int j = 0; j < numWakelocks; j++) { |
| 3324 | String wakelockName = in.readString(); |
| 3325 | Uid.Wakelock wakelock = new Wakelock(); |
| 3326 | wakelock.readFromParcelLocked(unpluggables, in); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3327 | // We will just drop some random set of wakelocks if |
| 3328 | // the previous run of the system was an older version |
| 3329 | // that didn't impose a limit. |
| 3330 | mWakelockStats.put(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | int numSensors = in.readInt(); |
| 3334 | mSensorStats.clear(); |
| 3335 | for (int k = 0; k < numSensors; k++) { |
| 3336 | int sensorNumber = in.readInt(); |
| 3337 | Uid.Sensor sensor = new Sensor(sensorNumber); |
| 3338 | sensor.readFromParcelLocked(mUnpluggables, in); |
| 3339 | mSensorStats.put(sensorNumber, sensor); |
| 3340 | } |
| 3341 | |
| 3342 | int numProcs = in.readInt(); |
| 3343 | mProcessStats.clear(); |
| 3344 | for (int k = 0; k < numProcs; k++) { |
| 3345 | String processName = in.readString(); |
| 3346 | Uid.Proc proc = new Proc(); |
| 3347 | proc.readFromParcelLocked(in); |
| 3348 | mProcessStats.put(processName, proc); |
| 3349 | } |
| 3350 | |
| 3351 | int numPkgs = in.readInt(); |
| 3352 | mPackageStats.clear(); |
| 3353 | for (int l = 0; l < numPkgs; l++) { |
| 3354 | String packageName = in.readString(); |
| 3355 | Uid.Pkg pkg = new Pkg(); |
| 3356 | pkg.readFromParcelLocked(in); |
| 3357 | mPackageStats.put(packageName, pkg); |
| 3358 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3359 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3360 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3361 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3362 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
| 3363 | mWifiRunningTimers, mUnpluggables, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3364 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3365 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3366 | } |
| 3367 | mFullWifiLockOut = false; |
| 3368 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3369 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3370 | mFullWifiLockTimers, mUnpluggables, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3371 | } else { |
| 3372 | mFullWifiLockTimer = null; |
| 3373 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3374 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3375 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3376 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
| 3377 | mWifiScanTimers, mUnpluggables, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3378 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3379 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3380 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3381 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 3382 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 3383 | if (in.readInt() != 0) { |
| 3384 | makeWifiBatchedScanBin(i, in); |
| 3385 | } else { |
| 3386 | mWifiBatchedScanTimer[i] = null; |
| 3387 | } |
| 3388 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3389 | mWifiMulticastEnabled = false; |
| 3390 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3391 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3392 | mWifiMulticastTimers, mUnpluggables, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3393 | } else { |
| 3394 | mWifiMulticastTimer = null; |
| 3395 | } |
| 3396 | mAudioTurnedOn = false; |
| 3397 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3398 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3399 | null, mUnpluggables, in); |
| 3400 | } else { |
| 3401 | mAudioTurnedOnTimer = null; |
| 3402 | } |
| 3403 | mVideoTurnedOn = false; |
| 3404 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3405 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3406 | null, mUnpluggables, in); |
| 3407 | } else { |
| 3408 | mVideoTurnedOnTimer = null; |
| 3409 | } |
| 3410 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3411 | mForegroundActivityTimer = new StopwatchTimer( |
| 3412 | Uid.this, FOREGROUND_ACTIVITY, null, mUnpluggables, in); |
| 3413 | } else { |
| 3414 | mForegroundActivityTimer = null; |
| 3415 | } |
| 3416 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3417 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, |
| 3418 | mUnpluggables, BatteryStatsImpl.this.mOnBatteryInternal, in); |
| 3419 | } else { |
| 3420 | mVibratorOnTimer = null; |
| 3421 | } |
| 3422 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3423 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 3424 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 3425 | mUserActivityCounters[i] = new Counter(mUnpluggables, in); |
| 3426 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3427 | } else { |
| 3428 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3429 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3430 | if (in.readInt() != 0) { |
| 3431 | mNetworkActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 3432 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 3433 | mNetworkActivityCounters[i] = new LongSamplingCounter(mUnpluggables, in); |
| 3434 | } |
| 3435 | } else { |
| 3436 | mNetworkActivityCounters = null; |
| 3437 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | /** |
| 3441 | * The statistics associated with a particular wake lock. |
| 3442 | */ |
| 3443 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 3444 | /** |
| 3445 | * How long (in ms) this uid has been keeping the device partially awake. |
| 3446 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3447 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3448 | |
| 3449 | /** |
| 3450 | * How long (in ms) this uid has been keeping the device fully awake. |
| 3451 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3452 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | |
| 3454 | /** |
| 3455 | * How long (in ms) this uid has had a window keeping the device awake. |
| 3456 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3457 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | |
| 3459 | /** |
| 3460 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 3461 | * proper timer pool from the given BatteryStatsImpl object. |
| 3462 | * |
| 3463 | * @param in the Parcel to be read from. |
| 3464 | * return a new Timer, or null. |
| 3465 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3466 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 3468 | if (in.readInt() == 0) { |
| 3469 | return null; |
| 3470 | } |
| 3471 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3472 | return new StopwatchTimer(Uid.this, type, pool, unpluggables, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | } |
| 3474 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3475 | boolean reset() { |
| 3476 | boolean wlactive = false; |
| 3477 | if (mTimerFull != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3478 | wlactive |= !mTimerFull.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3479 | } |
| 3480 | if (mTimerPartial != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3481 | wlactive |= !mTimerPartial.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3482 | } |
| 3483 | if (mTimerWindow != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3484 | wlactive |= !mTimerWindow.reset(BatteryStatsImpl.this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3485 | } |
| 3486 | if (!wlactive) { |
| 3487 | if (mTimerFull != null) { |
| 3488 | mTimerFull.detach(); |
| 3489 | mTimerFull = null; |
| 3490 | } |
| 3491 | if (mTimerPartial != null) { |
| 3492 | mTimerPartial.detach(); |
| 3493 | mTimerPartial = null; |
| 3494 | } |
| 3495 | if (mTimerWindow != null) { |
| 3496 | mTimerWindow.detach(); |
| 3497 | mTimerWindow = null; |
| 3498 | } |
| 3499 | } |
| 3500 | return !wlactive; |
| 3501 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | void readFromParcelLocked(ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 3504 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 3505 | mPartialTimers, unpluggables, in); |
| 3506 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, |
| 3507 | mFullTimers, unpluggables, in); |
| 3508 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, |
| 3509 | mWindowTimers, unpluggables, in); |
| 3510 | } |
| 3511 | |
| 3512 | void writeToParcelLocked(Parcel out, long batteryRealtime) { |
| 3513 | Timer.writeTimerToParcel(out, mTimerPartial, batteryRealtime); |
| 3514 | Timer.writeTimerToParcel(out, mTimerFull, batteryRealtime); |
| 3515 | Timer.writeTimerToParcel(out, mTimerWindow, batteryRealtime); |
| 3516 | } |
| 3517 | |
| 3518 | @Override |
| 3519 | public Timer getWakeTime(int type) { |
| 3520 | switch (type) { |
| 3521 | case WAKE_TYPE_FULL: return mTimerFull; |
| 3522 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 3523 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
| 3524 | default: throw new IllegalArgumentException("type = " + type); |
| 3525 | } |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 3530 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3531 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | public Sensor(int handle) { |
| 3534 | mHandle = handle; |
| 3535 | } |
| 3536 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3537 | private StopwatchTimer readTimerFromParcel(ArrayList<Unpluggable> unpluggables, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | Parcel in) { |
| 3539 | if (in.readInt() == 0) { |
| 3540 | return null; |
| 3541 | } |
| 3542 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3543 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3544 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3545 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | mSensorTimers.put(mHandle, pool); |
| 3547 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3548 | return new StopwatchTimer(Uid.this, 0, pool, unpluggables, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | } |
| 3550 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3551 | boolean reset() { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3552 | if (mTimer.reset(BatteryStatsImpl.this, true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3553 | mTimer = null; |
| 3554 | return true; |
| 3555 | } |
| 3556 | return false; |
| 3557 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | void readFromParcelLocked(ArrayList<Unpluggable> unpluggables, Parcel in) { |
| 3560 | mTimer = readTimerFromParcel(unpluggables, in); |
| 3561 | } |
| 3562 | |
| 3563 | void writeToParcelLocked(Parcel out, long batteryRealtime) { |
| 3564 | Timer.writeTimerToParcel(out, mTimer, batteryRealtime); |
| 3565 | } |
| 3566 | |
| 3567 | @Override |
| 3568 | public Timer getSensorTime() { |
| 3569 | return mTimer; |
| 3570 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3571 | |
| 3572 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | public int getHandle() { |
| 3574 | return mHandle; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * The statistics associated with a particular process. |
| 3580 | */ |
| 3581 | public final class Proc extends BatteryStats.Uid.Proc implements Unpluggable { |
| 3582 | /** |
| 3583 | * Total time (in 1/100 sec) spent executing in user code. |
| 3584 | */ |
| 3585 | long mUserTime; |
| 3586 | |
| 3587 | /** |
| 3588 | * Total time (in 1/100 sec) spent executing in kernel code. |
| 3589 | */ |
| 3590 | long mSystemTime; |
| 3591 | |
| 3592 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3593 | * Amount of time the process was running in the foreground. |
| 3594 | */ |
| 3595 | long mForegroundTime; |
| 3596 | |
| 3597 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3598 | * Number of times the process has been started. |
| 3599 | */ |
| 3600 | int mStarts; |
| 3601 | |
| 3602 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | * The amount of user time loaded from a previous save. |
| 3604 | */ |
| 3605 | long mLoadedUserTime; |
| 3606 | |
| 3607 | /** |
| 3608 | * The amount of system time loaded from a previous save. |
| 3609 | */ |
| 3610 | long mLoadedSystemTime; |
| 3611 | |
| 3612 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3613 | * The amount of foreground time loaded from a previous save. |
| 3614 | */ |
| 3615 | long mLoadedForegroundTime; |
| 3616 | |
| 3617 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3618 | * The number of times the process has started from a previous save. |
| 3619 | */ |
| 3620 | int mLoadedStarts; |
| 3621 | |
| 3622 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | * The amount of user time loaded from the previous run. |
| 3624 | */ |
| 3625 | long mLastUserTime; |
| 3626 | |
| 3627 | /** |
| 3628 | * The amount of system time loaded from the previous run. |
| 3629 | */ |
| 3630 | long mLastSystemTime; |
| 3631 | |
| 3632 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3633 | * The amount of foreground time loaded from the previous run |
| 3634 | */ |
| 3635 | long mLastForegroundTime; |
| 3636 | |
| 3637 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3638 | * The number of times the process has started from the previous run. |
| 3639 | */ |
| 3640 | int mLastStarts; |
| 3641 | |
| 3642 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | * The amount of user time when last unplugged. |
| 3644 | */ |
| 3645 | long mUnpluggedUserTime; |
| 3646 | |
| 3647 | /** |
| 3648 | * The amount of system time when last unplugged. |
| 3649 | */ |
| 3650 | long mUnpluggedSystemTime; |
| 3651 | |
| 3652 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3653 | * The amount of foreground time since unplugged. |
| 3654 | */ |
| 3655 | long mUnpluggedForegroundTime; |
| 3656 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3657 | /** |
| 3658 | * The number of times the process has started before unplugged. |
| 3659 | */ |
| 3660 | int mUnpluggedStarts; |
| 3661 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3662 | SamplingCounter[] mSpeedBins; |
| 3663 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3664 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3666 | Proc() { |
| 3667 | mUnpluggables.add(this); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3668 | mSpeedBins = new SamplingCounter[getCpuSpeedSteps()]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3670 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3671 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | mUnpluggedUserTime = mUserTime; |
| 3673 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3674 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3675 | mUnpluggedStarts = mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | } |
| 3677 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3678 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3679 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3680 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3681 | void detach() { |
| 3682 | mUnpluggables.remove(this); |
| 3683 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 3684 | SamplingCounter c = mSpeedBins[i]; |
| 3685 | if (c != null) { |
| 3686 | mUnpluggables.remove(c); |
| 3687 | mSpeedBins[i] = null; |
| 3688 | } |
| 3689 | } |
| 3690 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3691 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3692 | public int countExcessivePowers() { |
| 3693 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3694 | } |
| 3695 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3696 | public ExcessivePower getExcessivePower(int i) { |
| 3697 | if (mExcessivePower != null) { |
| 3698 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3699 | } |
| 3700 | return null; |
| 3701 | } |
| 3702 | |
| 3703 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3704 | if (mExcessivePower == null) { |
| 3705 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3706 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3707 | ExcessivePower ew = new ExcessivePower(); |
| 3708 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3709 | ew.overTime = overTime; |
| 3710 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3711 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3712 | } |
| 3713 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3714 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 3715 | if (mExcessivePower == null) { |
| 3716 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 3717 | } |
| 3718 | ExcessivePower ew = new ExcessivePower(); |
| 3719 | ew.type = ExcessivePower.TYPE_CPU; |
| 3720 | ew.overTime = overTime; |
| 3721 | ew.usedTime = usedTime; |
| 3722 | mExcessivePower.add(ew); |
| 3723 | } |
| 3724 | |
| 3725 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 3726 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3727 | out.writeInt(0); |
| 3728 | return; |
| 3729 | } |
| 3730 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3731 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3732 | out.writeInt(N); |
| 3733 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3734 | ExcessivePower ew = mExcessivePower.get(i); |
| 3735 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3736 | out.writeLong(ew.overTime); |
| 3737 | out.writeLong(ew.usedTime); |
| 3738 | } |
| 3739 | } |
| 3740 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 3741 | boolean readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3742 | final int N = in.readInt(); |
| 3743 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3744 | mExcessivePower = null; |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 3745 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 3748 | if (N > 10000) { |
| 3749 | Slog.w(TAG, "File corrupt: too many excessive power entries " + N); |
| 3750 | return false; |
| 3751 | } |
| 3752 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3753 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3754 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3755 | ExcessivePower ew = new ExcessivePower(); |
| 3756 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3757 | ew.overTime = in.readLong(); |
| 3758 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3759 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3760 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 3761 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | void writeToParcelLocked(Parcel out) { |
| 3765 | out.writeLong(mUserTime); |
| 3766 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3767 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3768 | out.writeInt(mStarts); |
| 3769 | out.writeLong(mLoadedUserTime); |
| 3770 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3771 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | out.writeInt(mLoadedStarts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3773 | out.writeLong(mUnpluggedUserTime); |
| 3774 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3775 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | out.writeInt(mUnpluggedStarts); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3777 | |
| 3778 | out.writeInt(mSpeedBins.length); |
| 3779 | for (int i = 0; i < mSpeedBins.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3780 | SamplingCounter c = mSpeedBins[i]; |
| 3781 | if (c != null) { |
| 3782 | out.writeInt(1); |
| 3783 | c.writeToParcel(out); |
| 3784 | } else { |
| 3785 | out.writeInt(0); |
| 3786 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3787 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3788 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3789 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | void readFromParcelLocked(Parcel in) { |
| 3793 | mUserTime = in.readLong(); |
| 3794 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3795 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3796 | mStarts = in.readInt(); |
| 3797 | mLoadedUserTime = in.readLong(); |
| 3798 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3799 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3801 | mLastUserTime = 0; |
| 3802 | mLastSystemTime = 0; |
| 3803 | mLastForegroundTime = 0; |
| 3804 | mLastStarts = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | mUnpluggedUserTime = in.readLong(); |
| 3806 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3807 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3808 | mUnpluggedStarts = in.readInt(); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3809 | |
| 3810 | int bins = in.readInt(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3811 | int steps = getCpuSpeedSteps(); |
| 3812 | mSpeedBins = new SamplingCounter[bins >= steps ? bins : steps]; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3813 | for (int i = 0; i < bins; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3814 | if (in.readInt() != 0) { |
| 3815 | mSpeedBins[i] = new SamplingCounter(mUnpluggables, in); |
| 3816 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3817 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3818 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3819 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | public BatteryStatsImpl getBatteryStats() { |
| 3823 | return BatteryStatsImpl.this; |
| 3824 | } |
| 3825 | |
| 3826 | public void addCpuTimeLocked(int utime, int stime) { |
| 3827 | mUserTime += utime; |
| 3828 | mSystemTime += stime; |
| 3829 | } |
| 3830 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3831 | public void addForegroundTimeLocked(long ttime) { |
| 3832 | mForegroundTime += ttime; |
| 3833 | } |
| 3834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | public void incStartsLocked() { |
| 3836 | mStarts++; |
| 3837 | } |
| 3838 | |
| 3839 | @Override |
| 3840 | public long getUserTime(int which) { |
| 3841 | long val; |
| 3842 | if (which == STATS_LAST) { |
| 3843 | val = mLastUserTime; |
| 3844 | } else { |
| 3845 | val = mUserTime; |
| 3846 | if (which == STATS_CURRENT) { |
| 3847 | val -= mLoadedUserTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3848 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3849 | val -= mUnpluggedUserTime; |
| 3850 | } |
| 3851 | } |
| 3852 | return val; |
| 3853 | } |
| 3854 | |
| 3855 | @Override |
| 3856 | public long getSystemTime(int which) { |
| 3857 | long val; |
| 3858 | if (which == STATS_LAST) { |
| 3859 | val = mLastSystemTime; |
| 3860 | } else { |
| 3861 | val = mSystemTime; |
| 3862 | if (which == STATS_CURRENT) { |
| 3863 | val -= mLoadedSystemTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3864 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | val -= mUnpluggedSystemTime; |
| 3866 | } |
| 3867 | } |
| 3868 | return val; |
| 3869 | } |
| 3870 | |
| 3871 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3872 | public long getForegroundTime(int which) { |
| 3873 | long val; |
| 3874 | if (which == STATS_LAST) { |
| 3875 | val = mLastForegroundTime; |
| 3876 | } else { |
| 3877 | val = mForegroundTime; |
| 3878 | if (which == STATS_CURRENT) { |
| 3879 | val -= mLoadedForegroundTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3880 | } else if (which == STATS_SINCE_UNPLUGGED) { |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 3881 | val -= mUnpluggedForegroundTime; |
| 3882 | } |
| 3883 | } |
| 3884 | return val; |
| 3885 | } |
| 3886 | |
| 3887 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | public int getStarts(int which) { |
| 3889 | int val; |
| 3890 | if (which == STATS_LAST) { |
| 3891 | val = mLastStarts; |
| 3892 | } else { |
| 3893 | val = mStarts; |
| 3894 | if (which == STATS_CURRENT) { |
| 3895 | val -= mLoadedStarts; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3896 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | val -= mUnpluggedStarts; |
| 3898 | } |
| 3899 | } |
| 3900 | return val; |
| 3901 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3902 | |
| 3903 | /* Called by ActivityManagerService when CPU times are updated. */ |
| 3904 | public void addSpeedStepTimes(long[] values) { |
| 3905 | for (int i = 0; i < mSpeedBins.length && i < values.length; i++) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3906 | long amt = values[i]; |
| 3907 | if (amt != 0) { |
| 3908 | SamplingCounter c = mSpeedBins[i]; |
| 3909 | if (c == null) { |
| 3910 | mSpeedBins[i] = c = new SamplingCounter(mUnpluggables); |
| 3911 | } |
| 3912 | c.addCountAtomic(values[i]); |
| 3913 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | @Override |
| 3918 | public long getTimeAtCpuSpeedStep(int speedStep, int which) { |
| 3919 | if (speedStep < mSpeedBins.length) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3920 | SamplingCounter c = mSpeedBins[speedStep]; |
| 3921 | return c != null ? c.getCountLocked(which) : 0; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 3922 | } else { |
| 3923 | return 0; |
| 3924 | } |
| 3925 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | /** |
| 3929 | * The statistics associated with a particular package. |
| 3930 | */ |
| 3931 | public final class Pkg extends BatteryStats.Uid.Pkg implements Unpluggable { |
| 3932 | /** |
| 3933 | * Number of times this package has done something that could wake up the |
| 3934 | * device from sleep. |
| 3935 | */ |
| 3936 | int mWakeups; |
| 3937 | |
| 3938 | /** |
| 3939 | * Number of things that could wake up the device loaded from a |
| 3940 | * previous save. |
| 3941 | */ |
| 3942 | int mLoadedWakeups; |
| 3943 | |
| 3944 | /** |
| 3945 | * Number of things that could wake up the device as of the |
| 3946 | * last run. |
| 3947 | */ |
| 3948 | int mLastWakeups; |
| 3949 | |
| 3950 | /** |
| 3951 | * Number of things that could wake up the device as of the |
| 3952 | * last run. |
| 3953 | */ |
| 3954 | int mUnpluggedWakeups; |
| 3955 | |
| 3956 | /** |
| 3957 | * The statics we have collected for this package's services. |
| 3958 | */ |
| 3959 | final HashMap<String, Serv> mServiceStats = new HashMap<String, Serv>(); |
| 3960 | |
| 3961 | Pkg() { |
| 3962 | mUnpluggables.add(this); |
| 3963 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3964 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3965 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | mUnpluggedWakeups = mWakeups; |
| 3967 | } |
| 3968 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3969 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3971 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3972 | void detach() { |
| 3973 | mUnpluggables.remove(this); |
| 3974 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | void readFromParcelLocked(Parcel in) { |
| 3977 | mWakeups = in.readInt(); |
| 3978 | mLoadedWakeups = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3979 | mLastWakeups = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | mUnpluggedWakeups = in.readInt(); |
| 3981 | |
| 3982 | int numServs = in.readInt(); |
| 3983 | mServiceStats.clear(); |
| 3984 | for (int m = 0; m < numServs; m++) { |
| 3985 | String serviceName = in.readString(); |
| 3986 | Uid.Pkg.Serv serv = new Serv(); |
| 3987 | mServiceStats.put(serviceName, serv); |
| 3988 | |
| 3989 | serv.readFromParcelLocked(in); |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | void writeToParcelLocked(Parcel out) { |
| 3994 | out.writeInt(mWakeups); |
| 3995 | out.writeInt(mLoadedWakeups); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | out.writeInt(mUnpluggedWakeups); |
| 3997 | |
| 3998 | out.writeInt(mServiceStats.size()); |
| 3999 | for (Map.Entry<String, Uid.Pkg.Serv> servEntry : mServiceStats.entrySet()) { |
| 4000 | out.writeString(servEntry.getKey()); |
| 4001 | Uid.Pkg.Serv serv = servEntry.getValue(); |
| 4002 | |
| 4003 | serv.writeToParcelLocked(out); |
| 4004 | } |
| 4005 | } |
| 4006 | |
| 4007 | @Override |
| 4008 | public Map<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 4009 | return mServiceStats; |
| 4010 | } |
| 4011 | |
| 4012 | @Override |
| 4013 | public int getWakeups(int which) { |
| 4014 | int val; |
| 4015 | if (which == STATS_LAST) { |
| 4016 | val = mLastWakeups; |
| 4017 | } else { |
| 4018 | val = mWakeups; |
| 4019 | if (which == STATS_CURRENT) { |
| 4020 | val -= mLoadedWakeups; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4021 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | val -= mUnpluggedWakeups; |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | return val; |
| 4027 | } |
| 4028 | |
| 4029 | /** |
| 4030 | * The statistics associated with a particular service. |
| 4031 | */ |
| 4032 | public final class Serv extends BatteryStats.Uid.Pkg.Serv implements Unpluggable { |
| 4033 | /** |
| 4034 | * Total time (ms in battery uptime) the service has been left started. |
| 4035 | */ |
| 4036 | long mStartTime; |
| 4037 | |
| 4038 | /** |
| 4039 | * If service has been started and not yet stopped, this is |
| 4040 | * when it was started. |
| 4041 | */ |
| 4042 | long mRunningSince; |
| 4043 | |
| 4044 | /** |
| 4045 | * True if we are currently running. |
| 4046 | */ |
| 4047 | boolean mRunning; |
| 4048 | |
| 4049 | /** |
| 4050 | * Total number of times startService() has been called. |
| 4051 | */ |
| 4052 | int mStarts; |
| 4053 | |
| 4054 | /** |
| 4055 | * Total time (ms in battery uptime) the service has been left launched. |
| 4056 | */ |
| 4057 | long mLaunchedTime; |
| 4058 | |
| 4059 | /** |
| 4060 | * If service has been launched and not yet exited, this is |
| 4061 | * when it was launched (ms in battery uptime). |
| 4062 | */ |
| 4063 | long mLaunchedSince; |
| 4064 | |
| 4065 | /** |
| 4066 | * True if we are currently launched. |
| 4067 | */ |
| 4068 | boolean mLaunched; |
| 4069 | |
| 4070 | /** |
| 4071 | * Total number times the service has been launched. |
| 4072 | */ |
| 4073 | int mLaunches; |
| 4074 | |
| 4075 | /** |
| 4076 | * The amount of time spent started loaded from a previous save |
| 4077 | * (ms in battery uptime). |
| 4078 | */ |
| 4079 | long mLoadedStartTime; |
| 4080 | |
| 4081 | /** |
| 4082 | * The number of starts loaded from a previous save. |
| 4083 | */ |
| 4084 | int mLoadedStarts; |
| 4085 | |
| 4086 | /** |
| 4087 | * The number of launches loaded from a previous save. |
| 4088 | */ |
| 4089 | int mLoadedLaunches; |
| 4090 | |
| 4091 | /** |
| 4092 | * The amount of time spent started as of the last run (ms |
| 4093 | * in battery uptime). |
| 4094 | */ |
| 4095 | long mLastStartTime; |
| 4096 | |
| 4097 | /** |
| 4098 | * The number of starts as of the last run. |
| 4099 | */ |
| 4100 | int mLastStarts; |
| 4101 | |
| 4102 | /** |
| 4103 | * The number of launches as of the last run. |
| 4104 | */ |
| 4105 | int mLastLaunches; |
| 4106 | |
| 4107 | /** |
| 4108 | * The amount of time spent started when last unplugged (ms |
| 4109 | * in battery uptime). |
| 4110 | */ |
| 4111 | long mUnpluggedStartTime; |
| 4112 | |
| 4113 | /** |
| 4114 | * The number of starts when last unplugged. |
| 4115 | */ |
| 4116 | int mUnpluggedStarts; |
| 4117 | |
| 4118 | /** |
| 4119 | * The number of launches when last unplugged. |
| 4120 | */ |
| 4121 | int mUnpluggedLaunches; |
| 4122 | |
| 4123 | Serv() { |
| 4124 | mUnpluggables.add(this); |
| 4125 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4126 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4127 | public void unplug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | mUnpluggedStartTime = getStartTimeToNowLocked(batteryUptime); |
| 4129 | mUnpluggedStarts = mStarts; |
| 4130 | mUnpluggedLaunches = mLaunches; |
| 4131 | } |
| 4132 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4133 | public void plug(long elapsedRealtime, long batteryUptime, long batteryRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4135 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4136 | void detach() { |
| 4137 | mUnpluggables.remove(this); |
| 4138 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | void readFromParcelLocked(Parcel in) { |
| 4141 | mStartTime = in.readLong(); |
| 4142 | mRunningSince = in.readLong(); |
| 4143 | mRunning = in.readInt() != 0; |
| 4144 | mStarts = in.readInt(); |
| 4145 | mLaunchedTime = in.readLong(); |
| 4146 | mLaunchedSince = in.readLong(); |
| 4147 | mLaunched = in.readInt() != 0; |
| 4148 | mLaunches = in.readInt(); |
| 4149 | mLoadedStartTime = in.readLong(); |
| 4150 | mLoadedStarts = in.readInt(); |
| 4151 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4152 | mLastStartTime = 0; |
| 4153 | mLastStarts = 0; |
| 4154 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | mUnpluggedStartTime = in.readLong(); |
| 4156 | mUnpluggedStarts = in.readInt(); |
| 4157 | mUnpluggedLaunches = in.readInt(); |
| 4158 | } |
| 4159 | |
| 4160 | void writeToParcelLocked(Parcel out) { |
| 4161 | out.writeLong(mStartTime); |
| 4162 | out.writeLong(mRunningSince); |
| 4163 | out.writeInt(mRunning ? 1 : 0); |
| 4164 | out.writeInt(mStarts); |
| 4165 | out.writeLong(mLaunchedTime); |
| 4166 | out.writeLong(mLaunchedSince); |
| 4167 | out.writeInt(mLaunched ? 1 : 0); |
| 4168 | out.writeInt(mLaunches); |
| 4169 | out.writeLong(mLoadedStartTime); |
| 4170 | out.writeInt(mLoadedStarts); |
| 4171 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | out.writeLong(mUnpluggedStartTime); |
| 4173 | out.writeInt(mUnpluggedStarts); |
| 4174 | out.writeInt(mUnpluggedLaunches); |
| 4175 | } |
| 4176 | |
| 4177 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 4178 | if (!mLaunched) return mLaunchedTime; |
| 4179 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 4180 | } |
| 4181 | |
| 4182 | long getStartTimeToNowLocked(long batteryUptime) { |
| 4183 | if (!mRunning) return mStartTime; |
| 4184 | return mStartTime + batteryUptime - mRunningSince; |
| 4185 | } |
| 4186 | |
| 4187 | public void startLaunchedLocked() { |
| 4188 | if (!mLaunched) { |
| 4189 | mLaunches++; |
| 4190 | mLaunchedSince = getBatteryUptimeLocked(); |
| 4191 | mLaunched = true; |
| 4192 | } |
| 4193 | } |
| 4194 | |
| 4195 | public void stopLaunchedLocked() { |
| 4196 | if (mLaunched) { |
| 4197 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 4198 | if (time > 0) { |
| 4199 | mLaunchedTime += time; |
| 4200 | } else { |
| 4201 | mLaunches--; |
| 4202 | } |
| 4203 | mLaunched = false; |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | public void startRunningLocked() { |
| 4208 | if (!mRunning) { |
| 4209 | mStarts++; |
| 4210 | mRunningSince = getBatteryUptimeLocked(); |
| 4211 | mRunning = true; |
| 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | public void stopRunningLocked() { |
| 4216 | if (mRunning) { |
| 4217 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 4218 | if (time > 0) { |
| 4219 | mStartTime += time; |
| 4220 | } else { |
| 4221 | mStarts--; |
| 4222 | } |
| 4223 | mRunning = false; |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | public BatteryStatsImpl getBatteryStats() { |
| 4228 | return BatteryStatsImpl.this; |
| 4229 | } |
| 4230 | |
| 4231 | @Override |
| 4232 | public int getLaunches(int which) { |
| 4233 | int val; |
| 4234 | |
| 4235 | if (which == STATS_LAST) { |
| 4236 | val = mLastLaunches; |
| 4237 | } else { |
| 4238 | val = mLaunches; |
| 4239 | if (which == STATS_CURRENT) { |
| 4240 | val -= mLoadedLaunches; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4241 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | val -= mUnpluggedLaunches; |
| 4243 | } |
| 4244 | } |
| 4245 | |
| 4246 | return val; |
| 4247 | } |
| 4248 | |
| 4249 | @Override |
| 4250 | public long getStartTime(long now, int which) { |
| 4251 | long val; |
| 4252 | if (which == STATS_LAST) { |
| 4253 | val = mLastStartTime; |
| 4254 | } else { |
| 4255 | val = getStartTimeToNowLocked(now); |
| 4256 | if (which == STATS_CURRENT) { |
| 4257 | val -= mLoadedStartTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4258 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | val -= mUnpluggedStartTime; |
| 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | return val; |
| 4264 | } |
| 4265 | |
| 4266 | @Override |
| 4267 | public int getStarts(int which) { |
| 4268 | int val; |
| 4269 | if (which == STATS_LAST) { |
| 4270 | val = mLastStarts; |
| 4271 | } else { |
| 4272 | val = mStarts; |
| 4273 | if (which == STATS_CURRENT) { |
| 4274 | val -= mLoadedStarts; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4275 | } else if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | val -= mUnpluggedStarts; |
| 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | return val; |
| 4281 | } |
| 4282 | } |
| 4283 | |
| 4284 | public BatteryStatsImpl getBatteryStats() { |
| 4285 | return BatteryStatsImpl.this; |
| 4286 | } |
| 4287 | |
| 4288 | public void incWakeupsLocked() { |
| 4289 | mWakeups++; |
| 4290 | } |
| 4291 | |
| 4292 | final Serv newServiceStatsLocked() { |
| 4293 | return new Serv(); |
| 4294 | } |
| 4295 | } |
| 4296 | |
| 4297 | /** |
| 4298 | * Retrieve the statistics object for a particular process, creating |
| 4299 | * if needed. |
| 4300 | */ |
| 4301 | public Proc getProcessStatsLocked(String name) { |
| 4302 | Proc ps = mProcessStats.get(name); |
| 4303 | if (ps == null) { |
| 4304 | ps = new Proc(); |
| 4305 | mProcessStats.put(name, ps); |
| 4306 | } |
| 4307 | |
| 4308 | return ps; |
| 4309 | } |
| 4310 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 4311 | public SparseArray<? extends Pid> getPidStats() { |
| 4312 | return mPids; |
| 4313 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4314 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4315 | public Pid getPidStatsLocked(int pid) { |
| 4316 | Pid p = mPids.get(pid); |
| 4317 | if (p == null) { |
| 4318 | p = new Pid(); |
| 4319 | mPids.put(pid, p); |
| 4320 | } |
| 4321 | return p; |
| 4322 | } |
| 4323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | /** |
| 4325 | * Retrieve the statistics object for a particular service, creating |
| 4326 | * if needed. |
| 4327 | */ |
| 4328 | public Pkg getPackageStatsLocked(String name) { |
| 4329 | Pkg ps = mPackageStats.get(name); |
| 4330 | if (ps == null) { |
| 4331 | ps = new Pkg(); |
| 4332 | mPackageStats.put(name, ps); |
| 4333 | } |
| 4334 | |
| 4335 | return ps; |
| 4336 | } |
| 4337 | |
| 4338 | /** |
| 4339 | * Retrieve the statistics object for a particular service, creating |
| 4340 | * if needed. |
| 4341 | */ |
| 4342 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 4343 | Pkg ps = getPackageStatsLocked(pkg); |
| 4344 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 4345 | if (ss == null) { |
| 4346 | ss = ps.newServiceStatsLocked(); |
| 4347 | ps.mServiceStats.put(serv, ss); |
| 4348 | } |
| 4349 | |
| 4350 | return ss; |
| 4351 | } |
| 4352 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4353 | public StopwatchTimer getWakeTimerLocked(String name, int type) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | Wakelock wl = mWakelockStats.get(name); |
| 4355 | if (wl == null) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 4356 | final int N = mWakelockStats.size(); |
Dianne Hackborn | af17baa | 2013-05-09 15:27:47 -0700 | [diff] [blame] | 4357 | if (N > MAX_WAKELOCKS_PER_UID) { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 4358 | name = BATCHED_WAKELOCK_NAME; |
| 4359 | wl = mWakelockStats.get(name); |
| 4360 | } |
| 4361 | if (wl == null) { |
| 4362 | wl = new Wakelock(); |
| 4363 | mWakelockStats.put(name, wl); |
| 4364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4366 | StopwatchTimer t = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | switch (type) { |
| 4368 | case WAKE_TYPE_PARTIAL: |
| 4369 | t = wl.mTimerPartial; |
| 4370 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4371 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
| 4372 | mPartialTimers, mUnpluggables); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | wl.mTimerPartial = t; |
| 4374 | } |
| 4375 | return t; |
| 4376 | case WAKE_TYPE_FULL: |
| 4377 | t = wl.mTimerFull; |
| 4378 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4379 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
| 4380 | mFullTimers, mUnpluggables); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | wl.mTimerFull = t; |
| 4382 | } |
| 4383 | return t; |
| 4384 | case WAKE_TYPE_WINDOW: |
| 4385 | t = wl.mTimerWindow; |
| 4386 | if (t == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4387 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
| 4388 | mWindowTimers, mUnpluggables); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | wl.mTimerWindow = t; |
| 4390 | } |
| 4391 | return t; |
| 4392 | default: |
| 4393 | throw new IllegalArgumentException("type=" + type); |
| 4394 | } |
| 4395 | } |
| 4396 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4397 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | Sensor se = mSensorStats.get(sensor); |
| 4399 | if (se == null) { |
| 4400 | if (!create) { |
| 4401 | return null; |
| 4402 | } |
| 4403 | se = new Sensor(sensor); |
| 4404 | mSensorStats.put(sensor, se); |
| 4405 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4406 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | if (t != null) { |
| 4408 | return t; |
| 4409 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4410 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4412 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | mSensorTimers.put(sensor, timers); |
| 4414 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4415 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mUnpluggables); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | se.mTimer = t; |
| 4417 | return t; |
| 4418 | } |
| 4419 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4420 | public void noteStartWakeLocked(int pid, String name, int type) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4421 | StopwatchTimer t = getWakeTimerLocked(name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | if (t != null) { |
| 4423 | t.startRunningLocked(BatteryStatsImpl.this); |
| 4424 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4425 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4426 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 4427 | if (p.mWakeStart == 0) { |
| 4428 | p.mWakeStart = SystemClock.elapsedRealtime(); |
| 4429 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4430 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | } |
| 4432 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4433 | public void noteStopWakeLocked(int pid, String name, int type) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4434 | StopwatchTimer t = getWakeTimerLocked(name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | if (t != null) { |
| 4436 | t.stopRunningLocked(BatteryStatsImpl.this); |
| 4437 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4438 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4439 | Pid p = mPids.get(pid); |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 4440 | if (p != null && p.mWakeStart != 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4441 | p.mWakeSum += SystemClock.elapsedRealtime() - p.mWakeStart; |
| 4442 | p.mWakeStart = 0; |
| 4443 | } |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 4448 | Proc p = getProcessStatsLocked(proc); |
| 4449 | if (p != null) { |
| 4450 | p.addExcessiveWake(overTime, usedTime); |
| 4451 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4453 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4454 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 4455 | Proc p = getProcessStatsLocked(proc); |
| 4456 | if (p != null) { |
| 4457 | p.addExcessiveCpu(overTime, usedTime); |
| 4458 | } |
| 4459 | } |
| 4460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | public void noteStartSensor(int sensor) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4462 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | if (t != null) { |
| 4464 | t.startRunningLocked(BatteryStatsImpl.this); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | public void noteStopSensor(int sensor) { |
| 4469 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4470 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | if (t != null) { |
| 4472 | t.stopRunningLocked(BatteryStatsImpl.this); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | public void noteStartGps() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4477 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | if (t != null) { |
| 4479 | t.startRunningLocked(BatteryStatsImpl.this); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4480 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | public void noteStopGps() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4484 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | if (t != null) { |
| 4486 | t.stopRunningLocked(BatteryStatsImpl.this); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | public BatteryStatsImpl getBatteryStats() { |
| 4491 | return BatteryStatsImpl.this; |
| 4492 | } |
| 4493 | } |
| 4494 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 4495 | public BatteryStatsImpl(String filename, Handler handler) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 4496 | mFile = new JournaledFile(new File(filename), new File(filename + ".tmp")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 4497 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | mStartCount++; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4499 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4500 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4501 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mUnpluggables); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4502 | } |
| 4503 | mInputEventCounter = new Counter(mUnpluggables); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4504 | mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4505 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4506 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, mUnpluggables); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4507 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4508 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mUnpluggables); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4509 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4510 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, mUnpluggables); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4511 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4512 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 4513 | mNetworkActivityCounters[i] = new LongSamplingCounter(mUnpluggables); |
| 4514 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4515 | mWifiOnTimer = new StopwatchTimer(null, -3, null, mUnpluggables); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4516 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -4, null, mUnpluggables); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4517 | mBluetoothOnTimer = new StopwatchTimer(null, -5, null, mUnpluggables); |
| 4518 | mAudioOnTimer = new StopwatchTimer(null, -6, null, mUnpluggables); |
| 4519 | mVideoOnTimer = new StopwatchTimer(null, -7, null, mUnpluggables); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4520 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4521 | initTimes(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | mTrackBatteryPastUptime = 0; |
| 4523 | mTrackBatteryPastRealtime = 0; |
| 4524 | mUptimeStart = mTrackBatteryUptimeStart = SystemClock.uptimeMillis() * 1000; |
| 4525 | mRealtimeStart = mTrackBatteryRealtimeStart = SystemClock.elapsedRealtime() * 1000; |
| 4526 | mUnpluggedBatteryUptime = getBatteryUptimeLocked(mUptimeStart); |
| 4527 | mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(mRealtimeStart); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 4528 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4529 | mDischargeUnplugLevel = 0; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 4530 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4531 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4532 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 4536 | mFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4537 | mHandler = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4538 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | readFromParcel(p); |
| 4540 | } |
| 4541 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4542 | public void setCallback(BatteryCallback cb) { |
| 4543 | mCallback = cb; |
| 4544 | } |
| 4545 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 4546 | public void setNumSpeedSteps(int steps) { |
| 4547 | if (sNumSpeedSteps == 0) sNumSpeedSteps = steps; |
| 4548 | } |
| 4549 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4550 | public void setRadioScanningTimeout(long timeout) { |
| 4551 | if (mPhoneSignalScanningTimer != null) { |
| 4552 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 4553 | } |
| 4554 | } |
| 4555 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4556 | @Override |
| 4557 | public boolean startIteratingOldHistoryLocked() { |
| 4558 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 4559 | + " pos=" + mHistoryBuffer.dataPosition()); |
| 4560 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 4561 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4562 | mReadOverflow = false; |
| 4563 | mIteratingHistory = true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 4564 | return (mHistoryIterator = mHistory) != null; |
| 4565 | } |
| 4566 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4567 | @Override |
| 4568 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 4569 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 4570 | if (!end) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 4571 | mHistoryReadTmp.readDelta(mHistoryBuffer); |
| 4572 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4573 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 4574 | HistoryItem cur = mHistoryIterator; |
| 4575 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4576 | if (!mReadOverflow && !end) { |
| 4577 | Slog.w(TAG, "Old history ends before new history!"); |
| 4578 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 4579 | return false; |
| 4580 | } |
| 4581 | out.setTo(cur); |
| 4582 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4583 | if (!mReadOverflow) { |
| 4584 | if (end) { |
| 4585 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 4586 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4587 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4588 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4589 | pw.println("Histories differ!"); |
| 4590 | pw.println("Old history:"); |
| 4591 | (new HistoryPrinter()).printNextItem(pw, out, now); |
| 4592 | pw.println("New history:"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 4593 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, now); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4594 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4595 | } |
| 4596 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 4597 | return true; |
| 4598 | } |
| 4599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4601 | public void finishIteratingOldHistoryLocked() { |
| 4602 | mIteratingHistory = false; |
| 4603 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
| 4604 | } |
| 4605 | |
| 4606 | @Override |
| 4607 | public boolean startIteratingHistoryLocked() { |
| 4608 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 4609 | + " pos=" + mHistoryBuffer.dataPosition()); |
| 4610 | mHistoryBuffer.setDataPosition(0); |
| 4611 | mReadOverflow = false; |
| 4612 | mIteratingHistory = true; |
| 4613 | return mHistoryBuffer.dataSize() > 0; |
| 4614 | } |
| 4615 | |
| 4616 | @Override |
| 4617 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 4618 | final int pos = mHistoryBuffer.dataPosition(); |
| 4619 | if (pos == 0) { |
| 4620 | out.clear(); |
| 4621 | } |
| 4622 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4623 | if (end) { |
| 4624 | return false; |
| 4625 | } |
| 4626 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 4627 | out.readDelta(mHistoryBuffer); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4628 | return true; |
| 4629 | } |
| 4630 | |
| 4631 | @Override |
| 4632 | public void finishIteratingHistoryLocked() { |
| 4633 | mIteratingHistory = false; |
| 4634 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4635 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4636 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4637 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 4638 | public long getHistoryBaseTime() { |
| 4639 | return mHistoryBaseTime; |
| 4640 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4641 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 4642 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4643 | public int getStartCount() { |
| 4644 | return mStartCount; |
| 4645 | } |
| 4646 | |
| 4647 | public boolean isOnBattery() { |
| 4648 | return mOnBattery; |
| 4649 | } |
| 4650 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4651 | public boolean isScreenOn() { |
| 4652 | return mScreenOn; |
| 4653 | } |
| 4654 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4655 | void initTimes() { |
| 4656 | mBatteryRealtime = mTrackBatteryPastUptime = 0; |
| 4657 | mBatteryUptime = mTrackBatteryPastRealtime = 0; |
| 4658 | mUptimeStart = mTrackBatteryUptimeStart = SystemClock.uptimeMillis() * 1000; |
| 4659 | mRealtimeStart = mTrackBatteryRealtimeStart = SystemClock.elapsedRealtime() * 1000; |
| 4660 | mUnpluggedBatteryUptime = getBatteryUptimeLocked(mUptimeStart); |
| 4661 | mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(mRealtimeStart); |
| 4662 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4663 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4664 | void initDischarge() { |
| 4665 | mLowDischargeAmountSinceCharge = 0; |
| 4666 | mHighDischargeAmountSinceCharge = 0; |
| 4667 | mDischargeAmountScreenOn = 0; |
| 4668 | mDischargeAmountScreenOnSinceCharge = 0; |
| 4669 | mDischargeAmountScreenOff = 0; |
| 4670 | mDischargeAmountScreenOffSinceCharge = 0; |
| 4671 | } |
| 4672 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4673 | public void resetAllStatsLocked() { |
| 4674 | mStartCount = 0; |
| 4675 | initTimes(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4676 | mScreenOnTimer.reset(this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4677 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4678 | mScreenBrightnessTimer[i].reset(this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4679 | } |
| 4680 | mInputEventCounter.reset(false); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4681 | mPhoneOnTimer.reset(this, false); |
| 4682 | mAudioOnTimer.reset(this, false); |
| 4683 | mVideoOnTimer.reset(this, false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4684 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4685 | mPhoneSignalStrengthsTimer[i].reset(this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4686 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4687 | mPhoneSignalScanningTimer.reset(this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4688 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4689 | mPhoneDataConnectionsTimer[i].reset(this, false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4690 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4691 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 4692 | mNetworkActivityCounters[i].reset(false); |
| 4693 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4694 | mWifiOnTimer.reset(this, false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4695 | mGlobalWifiRunningTimer.reset(this, false); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4696 | mBluetoothOnTimer.reset(this, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4697 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4698 | for (int i=0; i<mUidStats.size(); i++) { |
| 4699 | if (mUidStats.valueAt(i).reset()) { |
| 4700 | mUidStats.remove(mUidStats.keyAt(i)); |
| 4701 | i--; |
| 4702 | } |
| 4703 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4704 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4705 | if (mKernelWakelockStats.size() > 0) { |
| 4706 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
| 4707 | mUnpluggables.remove(timer); |
| 4708 | } |
| 4709 | mKernelWakelockStats.clear(); |
| 4710 | } |
| 4711 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4712 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4713 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4714 | clearHistoryLocked(); |
| 4715 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4716 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4717 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4718 | if (oldScreenOn) { |
| 4719 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 4720 | if (diff > 0) { |
| 4721 | mDischargeAmountScreenOn += diff; |
| 4722 | mDischargeAmountScreenOnSinceCharge += diff; |
| 4723 | } |
| 4724 | } else { |
| 4725 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 4726 | if (diff > 0) { |
| 4727 | mDischargeAmountScreenOff += diff; |
| 4728 | mDischargeAmountScreenOffSinceCharge += diff; |
| 4729 | } |
| 4730 | } |
| 4731 | if (newScreenOn) { |
| 4732 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 4733 | mDischargeScreenOffUnplugLevel = 0; |
| 4734 | } else { |
| 4735 | mDischargeScreenOnUnplugLevel = 0; |
| 4736 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 4737 | } |
| 4738 | } |
| 4739 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4740 | void setOnBattery(boolean onBattery, int oldStatus, int level) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4741 | synchronized(this) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4742 | setOnBatteryLocked(onBattery, oldStatus, level); |
| 4743 | } |
| 4744 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4745 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4746 | void setOnBatteryLocked(boolean onBattery, int oldStatus, int level) { |
| 4747 | boolean doWrite = false; |
| 4748 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 4749 | m.arg1 = onBattery ? 1 : 0; |
| 4750 | mHandler.sendMessage(m); |
| 4751 | mOnBattery = mOnBatteryInternal = onBattery; |
| 4752 | |
| 4753 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 4754 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 4755 | long realtime = mSecRealtime * 1000; |
| 4756 | if (onBattery) { |
| 4757 | // We will reset our status if we are unplugging after the |
| 4758 | // battery was last full, or the level is at 100, or |
| 4759 | // we have gone through a significant charge (from a very low |
| 4760 | // level to a now very high level). |
| 4761 | if (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
| 4762 | || level >= 90 |
| 4763 | || (mDischargeCurrentLevel < 20 && level >= 80)) { |
| 4764 | doWrite = true; |
| 4765 | resetAllStatsLocked(); |
| 4766 | mDischargeStartLevel = level; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4767 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4768 | updateKernelWakelocksLocked(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4769 | updateNetworkActivityLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4770 | mHistoryCur.batteryLevel = (byte)level; |
| 4771 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 4772 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 4773 | + Integer.toHexString(mHistoryCur.states)); |
| 4774 | addHistoryRecordLocked(mSecRealtime); |
| 4775 | mTrackBatteryUptimeStart = uptime; |
| 4776 | mTrackBatteryRealtimeStart = realtime; |
| 4777 | mUnpluggedBatteryUptime = getBatteryUptimeLocked(uptime); |
| 4778 | mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(realtime); |
| 4779 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
| 4780 | if (mScreenOn) { |
| 4781 | mDischargeScreenOnUnplugLevel = level; |
| 4782 | mDischargeScreenOffUnplugLevel = 0; |
| 4783 | } else { |
| 4784 | mDischargeScreenOnUnplugLevel = 0; |
| 4785 | mDischargeScreenOffUnplugLevel = level; |
| 4786 | } |
| 4787 | mDischargeAmountScreenOn = 0; |
| 4788 | mDischargeAmountScreenOff = 0; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4789 | doUnplugLocked(realtime, mUnpluggedBatteryUptime, mUnpluggedBatteryRealtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4790 | } else { |
| 4791 | updateKernelWakelocksLocked(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4792 | updateNetworkActivityLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4793 | mHistoryCur.batteryLevel = (byte)level; |
| 4794 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 4795 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 4796 | + Integer.toHexString(mHistoryCur.states)); |
| 4797 | addHistoryRecordLocked(mSecRealtime); |
| 4798 | mTrackBatteryPastUptime += uptime - mTrackBatteryUptimeStart; |
| 4799 | mTrackBatteryPastRealtime += realtime - mTrackBatteryRealtimeStart; |
| 4800 | mDischargeCurrentLevel = level; |
| 4801 | if (level < mDischargeUnplugLevel) { |
| 4802 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 4803 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 4804 | } |
| 4805 | updateDischargeScreenLevelsLocked(mScreenOn, mScreenOn); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4806 | doPlugLocked(realtime, getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime)); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4807 | } |
| 4808 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 4809 | if (mFile != null) { |
| 4810 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4811 | } |
| 4812 | } |
| 4813 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4814 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4815 | // This should probably be exposed in the API, though it's not critical |
| 4816 | private static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4817 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4818 | public void setBatteryState(int status, int health, int plugType, int level, |
| 4819 | int temp, int volt) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4820 | synchronized(this) { |
| 4821 | boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 4822 | int oldStatus = mHistoryCur.batteryStatus; |
| 4823 | if (!mHaveBatteryLevel) { |
| 4824 | mHaveBatteryLevel = true; |
| 4825 | // We start out assuming that the device is plugged in (not |
| 4826 | // on battery). If our first report is now that we are indeed |
| 4827 | // plugged in, then twiddle our state to correctly reflect that |
| 4828 | // since we won't be going through the full setOnBattery(). |
| 4829 | if (onBattery == mOnBattery) { |
| 4830 | if (onBattery) { |
| 4831 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 4832 | } else { |
| 4833 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 4834 | } |
| 4835 | } |
| 4836 | oldStatus = status; |
| 4837 | } |
| 4838 | if (onBattery) { |
| 4839 | mDischargeCurrentLevel = level; |
| 4840 | mRecordingHistory = true; |
| 4841 | } |
| 4842 | if (onBattery != mOnBattery) { |
| 4843 | mHistoryCur.batteryLevel = (byte)level; |
| 4844 | mHistoryCur.batteryStatus = (byte)status; |
| 4845 | mHistoryCur.batteryHealth = (byte)health; |
| 4846 | mHistoryCur.batteryPlugType = (byte)plugType; |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 4847 | mHistoryCur.batteryTemperature = (short)temp; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4848 | mHistoryCur.batteryVoltage = (char)volt; |
| 4849 | setOnBatteryLocked(onBattery, oldStatus, level); |
| 4850 | } else { |
| 4851 | boolean changed = false; |
| 4852 | if (mHistoryCur.batteryLevel != level) { |
| 4853 | mHistoryCur.batteryLevel = (byte)level; |
| 4854 | changed = true; |
| 4855 | } |
| 4856 | if (mHistoryCur.batteryStatus != status) { |
| 4857 | mHistoryCur.batteryStatus = (byte)status; |
| 4858 | changed = true; |
| 4859 | } |
| 4860 | if (mHistoryCur.batteryHealth != health) { |
| 4861 | mHistoryCur.batteryHealth = (byte)health; |
| 4862 | changed = true; |
| 4863 | } |
| 4864 | if (mHistoryCur.batteryPlugType != plugType) { |
| 4865 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 4866 | changed = true; |
| 4867 | } |
| 4868 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 4869 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 4870 | mHistoryCur.batteryTemperature = (short)temp; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4871 | changed = true; |
| 4872 | } |
| 4873 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 4874 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 4875 | mHistoryCur.batteryVoltage = (char)volt; |
| 4876 | changed = true; |
| 4877 | } |
| 4878 | if (changed) { |
| 4879 | addHistoryRecordLocked(SystemClock.elapsedRealtime()); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4880 | } |
| 4881 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 4882 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 4883 | // We don't record history while we are plugged in and fully charged. |
| 4884 | // The next time we are unplugged, history will be cleared. |
| 4885 | mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4886 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4887 | } |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 4888 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4889 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4890 | public void updateKernelWakelocksLocked() { |
| 4891 | Map<String, KernelWakelockStats> m = readKernelWakelockStats(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4892 | |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 4893 | if (m == null) { |
| 4894 | // Not crashing might make board bringup easier. |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 4895 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 4896 | return; |
| 4897 | } |
| 4898 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4899 | for (Map.Entry<String, KernelWakelockStats> ent : m.entrySet()) { |
| 4900 | String name = ent.getKey(); |
| 4901 | KernelWakelockStats kws = ent.getValue(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4902 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4903 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 4904 | if (kwlt == null) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4905 | kwlt = new SamplingTimer(mUnpluggables, mOnBatteryInternal, |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4906 | true /* track reported values */); |
| 4907 | mKernelWakelockStats.put(name, kwlt); |
| 4908 | } |
| 4909 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 4910 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 4911 | kwlt.setUpdateVersion(sKernelWakelockUpdateVersion); |
| 4912 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4913 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4914 | if (m.size() != mKernelWakelockStats.size()) { |
| 4915 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 4916 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 4917 | SamplingTimer st = ent.getValue(); |
| 4918 | if (st.getUpdateVersion() != sKernelWakelockUpdateVersion) { |
| 4919 | st.setStale(); |
| 4920 | } |
| 4921 | } |
| 4922 | } |
| 4923 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4925 | private void updateNetworkActivityLocked() { |
| 4926 | if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) return; |
| 4927 | |
| 4928 | final NetworkStats snapshot; |
| 4929 | try { |
| 4930 | snapshot = mNetworkStatsFactory.readNetworkStatsDetail(); |
| 4931 | } catch (IOException e) { |
| 4932 | Log.wtf(TAG, "Failed to read network stats", e); |
| 4933 | return; |
| 4934 | } |
| 4935 | |
| 4936 | if (mLastSnapshot == null) { |
| 4937 | mLastSnapshot = snapshot; |
| 4938 | return; |
| 4939 | } |
| 4940 | |
| 4941 | final NetworkStats delta = snapshot.subtract(mLastSnapshot); |
| 4942 | mLastSnapshot = snapshot; |
| 4943 | |
| 4944 | NetworkStats.Entry entry = null; |
| 4945 | final int size = delta.size(); |
| 4946 | for (int i = 0; i < size; i++) { |
| 4947 | entry = delta.getValues(i, entry); |
| 4948 | |
| 4949 | if (entry.rxBytes == 0 || entry.txBytes == 0) continue; |
| 4950 | if (entry.tag != NetworkStats.TAG_NONE) continue; |
| 4951 | |
| 4952 | final Uid u = getUidStatsLocked(entry.uid); |
| 4953 | |
| 4954 | if (mMobileIfaces.contains(entry.iface)) { |
| 4955 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_BYTES, entry.rxBytes); |
| 4956 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_BYTES, entry.txBytes); |
| 4957 | |
| 4958 | mNetworkActivityCounters[NETWORK_MOBILE_RX_BYTES].addCountLocked(entry.rxBytes); |
| 4959 | mNetworkActivityCounters[NETWORK_MOBILE_TX_BYTES].addCountLocked(entry.txBytes); |
| 4960 | |
| 4961 | } else if (mWifiIfaces.contains(entry.iface)) { |
| 4962 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_BYTES, entry.rxBytes); |
| 4963 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_BYTES, entry.txBytes); |
| 4964 | |
| 4965 | mNetworkActivityCounters[NETWORK_WIFI_RX_BYTES].addCountLocked(entry.rxBytes); |
| 4966 | mNetworkActivityCounters[NETWORK_WIFI_TX_BYTES].addCountLocked(entry.txBytes); |
| 4967 | } |
| 4968 | } |
| 4969 | } |
| 4970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | public long getAwakeTimeBattery() { |
| 4972 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 4973 | } |
| 4974 | |
| 4975 | public long getAwakeTimePlugged() { |
| 4976 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 4977 | } |
| 4978 | |
| 4979 | @Override |
| 4980 | public long computeUptime(long curTime, int which) { |
| 4981 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4982 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | case STATS_LAST: return mLastUptime; |
| 4984 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4985 | case STATS_SINCE_UNPLUGGED: return (curTime-mTrackBatteryUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | } |
| 4987 | return 0; |
| 4988 | } |
| 4989 | |
| 4990 | @Override |
| 4991 | public long computeRealtime(long curTime, int which) { |
| 4992 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4993 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | case STATS_LAST: return mLastRealtime; |
| 4995 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4996 | case STATS_SINCE_UNPLUGGED: return (curTime-mTrackBatteryRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4997 | } |
| 4998 | return 0; |
| 4999 | } |
| 5000 | |
| 5001 | @Override |
| 5002 | public long computeBatteryUptime(long curTime, int which) { |
| 5003 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5004 | case STATS_SINCE_CHARGED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | return mBatteryUptime + getBatteryUptime(curTime); |
| 5006 | case STATS_LAST: |
| 5007 | return mBatteryLastUptime; |
| 5008 | case STATS_CURRENT: |
| 5009 | return getBatteryUptime(curTime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5010 | case STATS_SINCE_UNPLUGGED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5011 | return getBatteryUptimeLocked(curTime) - mUnpluggedBatteryUptime; |
| 5012 | } |
| 5013 | return 0; |
| 5014 | } |
| 5015 | |
| 5016 | @Override |
| 5017 | public long computeBatteryRealtime(long curTime, int which) { |
| 5018 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5019 | case STATS_SINCE_CHARGED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5020 | return mBatteryRealtime + getBatteryRealtimeLocked(curTime); |
| 5021 | case STATS_LAST: |
| 5022 | return mBatteryLastRealtime; |
| 5023 | case STATS_CURRENT: |
| 5024 | return getBatteryRealtimeLocked(curTime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5025 | case STATS_SINCE_UNPLUGGED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | return getBatteryRealtimeLocked(curTime) - mUnpluggedBatteryRealtime; |
| 5027 | } |
| 5028 | return 0; |
| 5029 | } |
| 5030 | |
| 5031 | long getBatteryUptimeLocked(long curTime) { |
| 5032 | long time = mTrackBatteryPastUptime; |
| 5033 | if (mOnBatteryInternal) { |
| 5034 | time += curTime - mTrackBatteryUptimeStart; |
| 5035 | } |
| 5036 | return time; |
| 5037 | } |
| 5038 | |
| 5039 | long getBatteryUptimeLocked() { |
| 5040 | return getBatteryUptime(SystemClock.uptimeMillis() * 1000); |
| 5041 | } |
| 5042 | |
| 5043 | @Override |
| 5044 | public long getBatteryUptime(long curTime) { |
| 5045 | return getBatteryUptimeLocked(curTime); |
| 5046 | } |
| 5047 | |
| 5048 | long getBatteryRealtimeLocked(long curTime) { |
| 5049 | long time = mTrackBatteryPastRealtime; |
| 5050 | if (mOnBatteryInternal) { |
| 5051 | time += curTime - mTrackBatteryRealtimeStart; |
| 5052 | } |
| 5053 | return time; |
| 5054 | } |
| 5055 | |
| 5056 | @Override |
| 5057 | public long getBatteryRealtime(long curTime) { |
| 5058 | return getBatteryRealtimeLocked(curTime); |
| 5059 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 5060 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5061 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5062 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5063 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5064 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5065 | } |
| 5066 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5067 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5068 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5069 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5070 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5071 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5072 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5073 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5074 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5075 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5076 | } |
| 5077 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5078 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5079 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5080 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5081 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5082 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5083 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5084 | public int getLowDischargeAmountSinceCharge() { |
| 5085 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5086 | int val = mLowDischargeAmountSinceCharge; |
| 5087 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 5088 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 5089 | } |
| 5090 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | @Override |
| 5095 | public int getHighDischargeAmountSinceCharge() { |
| 5096 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5097 | int val = mHighDischargeAmountSinceCharge; |
| 5098 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 5099 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 5100 | } |
| 5101 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5102 | } |
| 5103 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5104 | |
| 5105 | public int getDischargeAmountScreenOn() { |
| 5106 | synchronized(this) { |
| 5107 | int val = mDischargeAmountScreenOn; |
| 5108 | if (mOnBattery && mScreenOn |
| 5109 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 5110 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 5111 | } |
| 5112 | return val; |
| 5113 | } |
| 5114 | } |
| 5115 | |
| 5116 | public int getDischargeAmountScreenOnSinceCharge() { |
| 5117 | synchronized(this) { |
| 5118 | int val = mDischargeAmountScreenOnSinceCharge; |
| 5119 | if (mOnBattery && mScreenOn |
| 5120 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 5121 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 5122 | } |
| 5123 | return val; |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | public int getDischargeAmountScreenOff() { |
| 5128 | synchronized(this) { |
| 5129 | int val = mDischargeAmountScreenOff; |
| 5130 | if (mOnBattery && !mScreenOn |
| 5131 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 5132 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 5133 | } |
| 5134 | return val; |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | public int getDischargeAmountScreenOffSinceCharge() { |
| 5139 | synchronized(this) { |
| 5140 | int val = mDischargeAmountScreenOffSinceCharge; |
| 5141 | if (mOnBattery && !mScreenOn |
| 5142 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 5143 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 5144 | } |
| 5145 | return val; |
| 5146 | } |
| 5147 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5148 | |
| 5149 | @Override |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5150 | public int getCpuSpeedSteps() { |
| 5151 | return sNumSpeedSteps; |
| 5152 | } |
| 5153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5154 | /** |
| 5155 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 5156 | */ |
| 5157 | public Uid getUidStatsLocked(int uid) { |
| 5158 | Uid u = mUidStats.get(uid); |
| 5159 | if (u == null) { |
| 5160 | u = new Uid(uid); |
| 5161 | mUidStats.put(uid, u); |
| 5162 | } |
| 5163 | return u; |
| 5164 | } |
| 5165 | |
| 5166 | /** |
| 5167 | * Remove the statistics object for a particular uid. |
| 5168 | */ |
| 5169 | public void removeUidStatsLocked(int uid) { |
| 5170 | mUidStats.remove(uid); |
| 5171 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | /** |
| 5174 | * Retrieve the statistics object for a particular process, creating |
| 5175 | * if needed. |
| 5176 | */ |
| 5177 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
| 5178 | Uid u = getUidStatsLocked(uid); |
| 5179 | return u.getProcessStatsLocked(name); |
| 5180 | } |
| 5181 | |
| 5182 | /** |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5183 | * Retrieve the statistics object for a particular process, given |
| 5184 | * the name of the process. |
| 5185 | * @param name process name |
| 5186 | * @return the statistics object for the process |
| 5187 | */ |
Amith Yamasani | 819f928 | 2009-06-24 23:18:15 -0700 | [diff] [blame] | 5188 | public Uid.Proc getProcessStatsLocked(String name, int pid) { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5189 | int uid; |
| 5190 | if (mUidCache.containsKey(name)) { |
| 5191 | uid = mUidCache.get(name); |
| 5192 | } else { |
Amith Yamasani | 819f928 | 2009-06-24 23:18:15 -0700 | [diff] [blame] | 5193 | uid = Process.getUidForPid(pid); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5194 | mUidCache.put(name, uid); |
| 5195 | } |
| 5196 | Uid u = getUidStatsLocked(uid); |
| 5197 | return u.getProcessStatsLocked(name); |
| 5198 | } |
| 5199 | |
| 5200 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5201 | * Retrieve the statistics object for a particular process, creating |
| 5202 | * if needed. |
| 5203 | */ |
| 5204 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
| 5205 | Uid u = getUidStatsLocked(uid); |
| 5206 | return u.getPackageStatsLocked(pkg); |
| 5207 | } |
| 5208 | |
| 5209 | /** |
| 5210 | * Retrieve the statistics object for a particular service, creating |
| 5211 | * if needed. |
| 5212 | */ |
| 5213 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
| 5214 | Uid u = getUidStatsLocked(uid); |
| 5215 | return u.getServiceStatsLocked(pkg, name); |
| 5216 | } |
| 5217 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5218 | /** |
| 5219 | * Massage data to distribute any reasonable work down to more specific |
| 5220 | * owners. Must only be called on a dead BatteryStats object! |
| 5221 | */ |
| 5222 | public void distributeWorkLocked(int which) { |
| 5223 | // Aggregate all CPU time associated with WIFI. |
| 5224 | Uid wifiUid = mUidStats.get(Process.WIFI_UID); |
| 5225 | if (wifiUid != null) { |
| 5226 | long uSecTime = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which); |
| 5227 | for (Uid.Proc proc : wifiUid.mProcessStats.values()) { |
| 5228 | long totalRunningTime = getGlobalWifiRunningTime(uSecTime, which); |
| 5229 | for (int i=0; i<mUidStats.size(); i++) { |
| 5230 | Uid uid = mUidStats.valueAt(i); |
| 5231 | if (uid.mUid != Process.WIFI_UID) { |
| 5232 | long uidRunningTime = uid.getWifiRunningTime(uSecTime, which); |
| 5233 | if (uidRunningTime > 0) { |
| 5234 | Uid.Proc uidProc = uid.getProcessStatsLocked("*wifi*"); |
| 5235 | long time = proc.getUserTime(which); |
| 5236 | time = (time*uidRunningTime)/totalRunningTime; |
| 5237 | uidProc.mUserTime += time; |
| 5238 | proc.mUserTime -= time; |
| 5239 | time = proc.getSystemTime(which); |
| 5240 | time = (time*uidRunningTime)/totalRunningTime; |
| 5241 | uidProc.mSystemTime += time; |
| 5242 | proc.mSystemTime -= time; |
| 5243 | time = proc.getForegroundTime(which); |
| 5244 | time = (time*uidRunningTime)/totalRunningTime; |
| 5245 | uidProc.mForegroundTime += time; |
| 5246 | proc.mForegroundTime -= time; |
| 5247 | for (int sb=0; sb<proc.mSpeedBins.length; sb++) { |
| 5248 | SamplingCounter sc = proc.mSpeedBins[sb]; |
| 5249 | if (sc != null) { |
| 5250 | time = sc.getCountLocked(which); |
| 5251 | time = (time*uidRunningTime)/totalRunningTime; |
| 5252 | SamplingCounter uidSc = uidProc.mSpeedBins[sb]; |
| 5253 | if (uidSc == null) { |
| 5254 | uidSc = new SamplingCounter(mUnpluggables); |
| 5255 | uidProc.mSpeedBins[sb] = uidSc; |
| 5256 | } |
| 5257 | uidSc.mCount.addAndGet((int)time); |
| 5258 | sc.mCount.addAndGet((int)-time); |
| 5259 | } |
| 5260 | } |
| 5261 | totalRunningTime -= uidRunningTime; |
| 5262 | } |
| 5263 | } |
| 5264 | } |
| 5265 | } |
| 5266 | } |
| 5267 | } |
| 5268 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5269 | public void shutdownLocked() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5270 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5271 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5272 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5273 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5274 | Parcel mPendingWrite = null; |
| 5275 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 5276 | |
| 5277 | public void writeAsyncLocked() { |
| 5278 | writeLocked(false); |
| 5279 | } |
| 5280 | |
| 5281 | public void writeSyncLocked() { |
| 5282 | writeLocked(true); |
| 5283 | } |
| 5284 | |
| 5285 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5286 | if (mFile == null) { |
| 5287 | 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] | 5288 | return; |
| 5289 | } |
| 5290 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5291 | if (mShuttingDown) { |
| 5292 | return; |
| 5293 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5294 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5295 | Parcel out = Parcel.obtain(); |
| 5296 | writeSummaryToParcel(out); |
| 5297 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 5298 | |
| 5299 | if (mPendingWrite != null) { |
| 5300 | mPendingWrite.recycle(); |
| 5301 | } |
| 5302 | mPendingWrite = out; |
| 5303 | |
| 5304 | if (sync) { |
| 5305 | commitPendingDataToDisk(); |
| 5306 | } else { |
| 5307 | Thread thr = new Thread("BatteryStats-Write") { |
| 5308 | @Override |
| 5309 | public void run() { |
| 5310 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 5311 | commitPendingDataToDisk(); |
| 5312 | } |
| 5313 | }; |
| 5314 | thr.start(); |
| 5315 | } |
| 5316 | } |
| 5317 | |
| 5318 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 5319 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5320 | synchronized (this) { |
| 5321 | next = mPendingWrite; |
| 5322 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 5323 | if (next == null) { |
| 5324 | return; |
| 5325 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5326 | |
| 5327 | mWriteLock.lock(); |
| 5328 | } |
| 5329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5330 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5331 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5332 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 5334 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5335 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5336 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5337 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5338 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 5339 | mFile.rollback(); |
| 5340 | } finally { |
| 5341 | next.recycle(); |
| 5342 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 5343 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | static byte[] readFully(FileInputStream stream) throws java.io.IOException { |
| 5347 | int pos = 0; |
| 5348 | int avail = stream.available(); |
| 5349 | byte[] data = new byte[avail]; |
| 5350 | while (true) { |
| 5351 | int amt = stream.read(data, pos, data.length-pos); |
| 5352 | //Log.i("foo", "Read " + amt + " bytes at " + pos |
| 5353 | // + " of avail " + data.length); |
| 5354 | if (amt <= 0) { |
| 5355 | //Log.i("foo", "**** FINISHED READING: pos=" + pos |
| 5356 | // + " len=" + data.length); |
| 5357 | return data; |
| 5358 | } |
| 5359 | pos += amt; |
| 5360 | avail = stream.available(); |
| 5361 | if (avail > data.length-pos) { |
| 5362 | byte[] newData = new byte[pos+avail]; |
| 5363 | System.arraycopy(data, 0, newData, 0, pos); |
| 5364 | data = newData; |
| 5365 | } |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | public void readLocked() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5370 | if (mFile == null) { |
| 5371 | 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] | 5372 | return; |
| 5373 | } |
| 5374 | |
| 5375 | mUidStats.clear(); |
| 5376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5378 | File file = mFile.chooseForRead(); |
| 5379 | if (!file.exists()) { |
| 5380 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5382 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5383 | |
| 5384 | byte[] raw = readFully(stream); |
| 5385 | Parcel in = Parcel.obtain(); |
| 5386 | in.unmarshall(raw, 0, raw.length); |
| 5387 | in.setDataPosition(0); |
| 5388 | stream.close(); |
| 5389 | |
| 5390 | readSummaryFromParcel(in); |
| 5391 | } catch(java.io.IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5392 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5394 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5395 | long now = SystemClock.elapsedRealtime(); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 5396 | if (USE_OLD_HISTORY) { |
| 5397 | addHistoryRecordLocked(now, HistoryItem.CMD_START); |
| 5398 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5399 | addHistoryBufferLocked(now, HistoryItem.CMD_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | public int describeContents() { |
| 5403 | return 0; |
| 5404 | } |
| 5405 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5406 | void readHistory(Parcel in, boolean andOldHistory) { |
| 5407 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5408 | |
| 5409 | mHistoryBuffer.setDataSize(0); |
| 5410 | mHistoryBuffer.setDataPosition(0); |
| 5411 | |
| 5412 | int bufSize = in.readInt(); |
| 5413 | int curPos = in.dataPosition(); |
| 5414 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
| 5415 | Slog.w(TAG, "File corrupt: history data buffer too large " + bufSize); |
| 5416 | } else if ((bufSize&~3) != bufSize) { |
| 5417 | Slog.w(TAG, "File corrupt: history data buffer not aligned " + bufSize); |
| 5418 | } else { |
| 5419 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 5420 | + " bytes at " + curPos); |
| 5421 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 5422 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5423 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5424 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5425 | if (andOldHistory) { |
| 5426 | readOldHistory(in); |
| 5427 | } |
| 5428 | |
| 5429 | if (DEBUG_HISTORY) { |
| 5430 | StringBuilder sb = new StringBuilder(128); |
| 5431 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 5432 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 5433 | Slog.i(TAG, sb.toString()); |
| 5434 | } |
| 5435 | mHistoryBaseTime = historyBaseTime; |
| 5436 | if (DEBUG_HISTORY) { |
| 5437 | StringBuilder sb = new StringBuilder(128); |
| 5438 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 5439 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 5440 | Slog.i(TAG, sb.toString()); |
| 5441 | } |
| 5442 | |
| 5443 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 5444 | // the last run until samples in this run. |
| 5445 | if (mHistoryBaseTime > 0) { |
| 5446 | long oldnow = SystemClock.elapsedRealtime(); |
| 5447 | mHistoryBaseTime = (mHistoryBaseTime - oldnow) + 60*1000; |
| 5448 | if (DEBUG_HISTORY) { |
| 5449 | StringBuilder sb = new StringBuilder(128); |
| 5450 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 5451 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 5452 | Slog.i(TAG, sb.toString()); |
| 5453 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 5454 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5455 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5456 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5457 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 5458 | if (!USE_OLD_HISTORY) { |
| 5459 | return; |
| 5460 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5461 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 5462 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 5463 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5464 | HistoryItem rec = new HistoryItem(time, in); |
| 5465 | addHistoryRecordLocked(rec); |
| 5466 | } |
| 5467 | } |
| 5468 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5469 | void writeHistory(Parcel out, boolean andOldHistory) { |
| 5470 | if (DEBUG_HISTORY) { |
| 5471 | StringBuilder sb = new StringBuilder(128); |
| 5472 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 5473 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 5474 | sb.append(" mLastHistoryTime: "); |
| 5475 | TimeUtils.formatDuration(mLastHistoryTime, sb); |
| 5476 | Slog.i(TAG, sb.toString()); |
| 5477 | } |
| 5478 | out.writeLong(mHistoryBaseTime + mLastHistoryTime); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5479 | out.writeInt(mHistoryBuffer.dataSize()); |
| 5480 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 5481 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 5482 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5483 | |
| 5484 | if (andOldHistory) { |
| 5485 | writeOldHistory(out); |
| 5486 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 5490 | if (!USE_OLD_HISTORY) { |
| 5491 | return; |
| 5492 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5493 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5494 | while (rec != null) { |
| 5495 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 5496 | rec = rec.next; |
| 5497 | } |
| 5498 | out.writeLong(-1); |
| 5499 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5501 | private void readSummaryFromParcel(Parcel in) { |
| 5502 | final int version = in.readInt(); |
| 5503 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5504 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | + ", expected " + VERSION + "; erasing old stats"); |
| 5506 | return; |
| 5507 | } |
| 5508 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5509 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5511 | mStartCount = in.readInt(); |
| 5512 | mBatteryUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | mBatteryRealtime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | mRealtime = in.readLong(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5516 | mDischargeUnplugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5517 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5518 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 5519 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5520 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 5521 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5523 | mStartCount++; |
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 | mScreenOn = false; |
| 5526 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5527 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 5528 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 5529 | } |
| 5530 | mInputEventCounter.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5531 | mPhoneOn = false; |
| 5532 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5533 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5534 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 5535 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5536 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5537 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 5538 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 5539 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5540 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 5541 | mNetworkActivityCounters[i].readSummaryFromParcelLocked(in); |
| 5542 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5543 | mWifiOn = false; |
| 5544 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5545 | mGlobalWifiRunning = false; |
| 5546 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5547 | mBluetoothOn = false; |
| 5548 | mBluetoothOnTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5550 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5551 | if (NKW > 10000) { |
| 5552 | Slog.w(TAG, "File corrupt: too many kernel wake locks " + NKW); |
| 5553 | return; |
| 5554 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5555 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 5556 | if (in.readInt() != 0) { |
| 5557 | String kwltName = in.readString(); |
| 5558 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 5559 | } |
| 5560 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5561 | |
| 5562 | sNumSpeedSteps = in.readInt(); |
| 5563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5565 | if (NU > 10000) { |
| 5566 | Slog.w(TAG, "File corrupt: too many uids " + NU); |
| 5567 | return; |
| 5568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5569 | for (int iu = 0; iu < NU; iu++) { |
| 5570 | int uid = in.readInt(); |
| 5571 | Uid u = new Uid(uid); |
| 5572 | mUidStats.put(uid, u); |
| 5573 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5574 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5575 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5576 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5577 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5578 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5579 | if (in.readInt() != 0) { |
| 5580 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 5581 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5582 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5583 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5584 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5585 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5586 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 5587 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5588 | if (in.readInt() != 0) { |
| 5589 | u.makeWifiBatchedScanBin(i, null); |
| 5590 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 5591 | } |
| 5592 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5593 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5594 | if (in.readInt() != 0) { |
| 5595 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 5596 | } |
| 5597 | u.mAudioTurnedOn = false; |
| 5598 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5599 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5600 | } |
| 5601 | u.mVideoTurnedOn = false; |
| 5602 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5603 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 5604 | } |
| 5605 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5606 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 5607 | } |
| 5608 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5609 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5610 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5611 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5612 | if (in.readInt() != 0) { |
| 5613 | if (u.mUserActivityCounters == null) { |
| 5614 | u.initUserActivityLocked(); |
| 5615 | } |
| 5616 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 5617 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 5618 | } |
| 5619 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5620 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5621 | if (in.readInt() != 0) { |
| 5622 | if (u.mNetworkActivityCounters == null) { |
| 5623 | u.initNetworkActivityLocked(); |
| 5624 | } |
| 5625 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 5626 | u.mNetworkActivityCounters[i].readSummaryFromParcelLocked(in); |
| 5627 | } |
| 5628 | } |
| 5629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5631 | if (NW > 100) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5632 | Slog.w(TAG, "File corrupt: too many wake locks " + NW); |
| 5633 | return; |
| 5634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | for (int iw = 0; iw < NW; iw++) { |
| 5636 | String wlName = in.readString(); |
| 5637 | if (in.readInt() != 0) { |
| 5638 | u.getWakeTimerLocked(wlName, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
| 5639 | } |
| 5640 | if (in.readInt() != 0) { |
| 5641 | u.getWakeTimerLocked(wlName, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 5642 | } |
| 5643 | if (in.readInt() != 0) { |
| 5644 | u.getWakeTimerLocked(wlName, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5649 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5650 | Slog.w(TAG, "File corrupt: too many sensors " + NP); |
| 5651 | return; |
| 5652 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | for (int is = 0; is < NP; is++) { |
| 5654 | int seNumber = in.readInt(); |
| 5655 | if (in.readInt() != 0) { |
| 5656 | u.getSensorTimerLocked(seNumber, true) |
| 5657 | .readSummaryFromParcelLocked(in); |
| 5658 | } |
| 5659 | } |
| 5660 | |
| 5661 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5662 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5663 | Slog.w(TAG, "File corrupt: too many processes " + NP); |
| 5664 | return; |
| 5665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5666 | for (int ip = 0; ip < NP; ip++) { |
| 5667 | String procName = in.readString(); |
| 5668 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 5669 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5671 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5672 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5673 | int NSB = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5674 | if (NSB > 100) { |
| 5675 | Slog.w(TAG, "File corrupt: too many speed bins " + NSB); |
| 5676 | return; |
| 5677 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5678 | p.mSpeedBins = new SamplingCounter[NSB]; |
| 5679 | for (int i=0; i<NSB; i++) { |
| 5680 | if (in.readInt() != 0) { |
| 5681 | p.mSpeedBins[i] = new SamplingCounter(mUnpluggables); |
| 5682 | p.mSpeedBins[i].readSummaryFromParcelLocked(in); |
| 5683 | } |
| 5684 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5685 | if (!p.readExcessivePowerFromParcelLocked(in)) { |
| 5686 | return; |
| 5687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 5691 | if (NP > 10000) { |
| 5692 | Slog.w(TAG, "File corrupt: too many packages " + NP); |
| 5693 | return; |
| 5694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5695 | for (int ip = 0; ip < NP; ip++) { |
| 5696 | String pkgName = in.readString(); |
| 5697 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
| 5698 | p.mWakeups = p.mLoadedWakeups = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5699 | final int NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5700 | if (NS > 1000) { |
| 5701 | Slog.w(TAG, "File corrupt: too many services " + NS); |
| 5702 | return; |
| 5703 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5704 | for (int is = 0; is < NS; is++) { |
| 5705 | String servName = in.readString(); |
| 5706 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 5707 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5708 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5710 | } |
| 5711 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | /** |
| 5716 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 5717 | * disk. This format does not allow a lossless round-trip. |
| 5718 | * |
| 5719 | * @param out the Parcel to be written to. |
| 5720 | */ |
| 5721 | public void writeSummaryToParcel(Parcel out) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5722 | // Need to update with current kernel wake lock counts. |
| 5723 | updateKernelWakelocksLocked(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5724 | updateNetworkActivityLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 5727 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
| 5728 | final long NOW = getBatteryUptimeLocked(NOW_SYS); |
| 5729 | final long NOWREAL = getBatteryRealtimeLocked(NOWREAL_SYS); |
| 5730 | |
| 5731 | out.writeInt(VERSION); |
| 5732 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5733 | writeHistory(out, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5736 | out.writeLong(computeBatteryUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5737 | out.writeLong(computeBatteryRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5738 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5739 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5740 | out.writeInt(mDischargeUnplugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 5741 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5742 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 5743 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 5744 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 5745 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5746 | |
| 5747 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5748 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 5749 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); |
| 5750 | } |
| 5751 | mInputEventCounter.writeSummaryFromParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5752 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5753 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5754 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); |
| 5755 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5756 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5757 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 5758 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); |
| 5759 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5760 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 5761 | mNetworkActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 5762 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5763 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5764 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5765 | mBluetoothOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5766 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5767 | out.writeInt(mKernelWakelockStats.size()); |
| 5768 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 5769 | Timer kwlt = ent.getValue(); |
| 5770 | if (kwlt != null) { |
| 5771 | out.writeInt(1); |
| 5772 | out.writeString(ent.getKey()); |
| 5773 | ent.getValue().writeSummaryFromParcelLocked(out, NOWREAL); |
| 5774 | } else { |
| 5775 | out.writeInt(0); |
| 5776 | } |
| 5777 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5778 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5779 | out.writeInt(sNumSpeedSteps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | final int NU = mUidStats.size(); |
| 5781 | out.writeInt(NU); |
| 5782 | for (int iu = 0; iu < NU; iu++) { |
| 5783 | out.writeInt(mUidStats.keyAt(iu)); |
| 5784 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5785 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5786 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5787 | out.writeInt(1); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5788 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5789 | } else { |
| 5790 | out.writeInt(0); |
| 5791 | } |
| 5792 | if (u.mFullWifiLockTimer != null) { |
| 5793 | out.writeInt(1); |
| 5794 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5795 | } else { |
| 5796 | out.writeInt(0); |
| 5797 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5798 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5799 | out.writeInt(1); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5800 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5801 | } else { |
| 5802 | out.writeInt(0); |
| 5803 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5804 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5805 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 5806 | out.writeInt(1); |
| 5807 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); |
| 5808 | } else { |
| 5809 | out.writeInt(0); |
| 5810 | } |
| 5811 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5812 | if (u.mWifiMulticastTimer != null) { |
| 5813 | out.writeInt(1); |
| 5814 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5815 | } else { |
| 5816 | out.writeInt(0); |
| 5817 | } |
| 5818 | if (u.mAudioTurnedOnTimer != null) { |
| 5819 | out.writeInt(1); |
| 5820 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5821 | } else { |
| 5822 | out.writeInt(0); |
| 5823 | } |
| 5824 | if (u.mVideoTurnedOnTimer != null) { |
| 5825 | out.writeInt(1); |
| 5826 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5827 | } else { |
| 5828 | out.writeInt(0); |
| 5829 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5830 | if (u.mForegroundActivityTimer != null) { |
| 5831 | out.writeInt(1); |
| 5832 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5833 | } else { |
| 5834 | out.writeInt(0); |
| 5835 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5836 | if (u.mVibratorOnTimer != null) { |
| 5837 | out.writeInt(1); |
| 5838 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5839 | } else { |
| 5840 | out.writeInt(0); |
| 5841 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5842 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5843 | if (u.mUserActivityCounters == null) { |
| 5844 | out.writeInt(0); |
| 5845 | } else { |
| 5846 | out.writeInt(1); |
| 5847 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 5848 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 5849 | } |
| 5850 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5851 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5852 | if (u.mNetworkActivityCounters == null) { |
| 5853 | out.writeInt(0); |
| 5854 | } else { |
| 5855 | out.writeInt(1); |
| 5856 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 5857 | u.mNetworkActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 5858 | } |
| 5859 | } |
| 5860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | int NW = u.mWakelockStats.size(); |
| 5862 | out.writeInt(NW); |
| 5863 | if (NW > 0) { |
| 5864 | for (Map.Entry<String, BatteryStatsImpl.Uid.Wakelock> ent |
| 5865 | : u.mWakelockStats.entrySet()) { |
| 5866 | out.writeString(ent.getKey()); |
| 5867 | Uid.Wakelock wl = ent.getValue(); |
| 5868 | if (wl.mTimerFull != null) { |
| 5869 | out.writeInt(1); |
| 5870 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5871 | } else { |
| 5872 | out.writeInt(0); |
| 5873 | } |
| 5874 | if (wl.mTimerPartial != null) { |
| 5875 | out.writeInt(1); |
| 5876 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5877 | } else { |
| 5878 | out.writeInt(0); |
| 5879 | } |
| 5880 | if (wl.mTimerWindow != null) { |
| 5881 | out.writeInt(1); |
| 5882 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5883 | } else { |
| 5884 | out.writeInt(0); |
| 5885 | } |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | int NSE = u.mSensorStats.size(); |
| 5890 | out.writeInt(NSE); |
| 5891 | if (NSE > 0) { |
| 5892 | for (Map.Entry<Integer, BatteryStatsImpl.Uid.Sensor> ent |
| 5893 | : u.mSensorStats.entrySet()) { |
| 5894 | out.writeInt(ent.getKey()); |
| 5895 | Uid.Sensor se = ent.getValue(); |
| 5896 | if (se.mTimer != null) { |
| 5897 | out.writeInt(1); |
| 5898 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL); |
| 5899 | } else { |
| 5900 | out.writeInt(0); |
| 5901 | } |
| 5902 | } |
| 5903 | } |
| 5904 | |
| 5905 | int NP = u.mProcessStats.size(); |
| 5906 | out.writeInt(NP); |
| 5907 | if (NP > 0) { |
| 5908 | for (Map.Entry<String, BatteryStatsImpl.Uid.Proc> ent |
| 5909 | : u.mProcessStats.entrySet()) { |
| 5910 | out.writeString(ent.getKey()); |
| 5911 | Uid.Proc ps = ent.getValue(); |
| 5912 | out.writeLong(ps.mUserTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5913 | out.writeLong(ps.mSystemTime); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5914 | out.writeLong(ps.mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5915 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5916 | final int N = ps.mSpeedBins.length; |
| 5917 | out.writeInt(N); |
| 5918 | for (int i=0; i<N; i++) { |
| 5919 | if (ps.mSpeedBins[i] != null) { |
| 5920 | out.writeInt(1); |
| 5921 | ps.mSpeedBins[i].writeSummaryFromParcelLocked(out); |
| 5922 | } else { |
| 5923 | out.writeInt(0); |
| 5924 | } |
| 5925 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5926 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | NP = u.mPackageStats.size(); |
| 5931 | out.writeInt(NP); |
| 5932 | if (NP > 0) { |
| 5933 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 5934 | : u.mPackageStats.entrySet()) { |
| 5935 | out.writeString(ent.getKey()); |
| 5936 | Uid.Pkg ps = ent.getValue(); |
| 5937 | out.writeInt(ps.mWakeups); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5938 | final int NS = ps.mServiceStats.size(); |
| 5939 | out.writeInt(NS); |
| 5940 | if (NS > 0) { |
| 5941 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg.Serv> sent |
| 5942 | : ps.mServiceStats.entrySet()) { |
| 5943 | out.writeString(sent.getKey()); |
| 5944 | BatteryStatsImpl.Uid.Pkg.Serv ss = sent.getValue(); |
| 5945 | long time = ss.getStartTimeToNowLocked(NOW); |
| 5946 | out.writeLong(time); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | out.writeInt(ss.mStarts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5949 | } |
| 5950 | } |
| 5951 | } |
| 5952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5953 | } |
| 5954 | } |
| 5955 | |
| 5956 | public void readFromParcel(Parcel in) { |
| 5957 | readFromParcelLocked(in); |
| 5958 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | void readFromParcelLocked(Parcel in) { |
| 5961 | int magic = in.readInt(); |
| 5962 | if (magic != MAGIC) { |
| 5963 | throw new ParcelFormatException("Bad magic number"); |
| 5964 | } |
| 5965 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 5966 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | mStartCount = in.readInt(); |
| 5969 | mBatteryUptime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5970 | mBatteryLastUptime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5971 | mBatteryRealtime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5972 | mBatteryLastRealtime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5973 | mScreenOn = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5974 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5975 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5976 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, |
| 5977 | null, mUnpluggables, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5978 | } |
| 5979 | mInputEventCounter = new Counter(mUnpluggables, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | mPhoneOn = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5981 | mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5982 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5983 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 5984 | null, mUnpluggables, in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5985 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5986 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mUnpluggables, in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5987 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5988 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 5989 | null, mUnpluggables, in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5990 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5991 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 5992 | mNetworkActivityCounters[i] = new LongSamplingCounter(mUnpluggables, in); |
| 5993 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5994 | mWifiOn = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5995 | mWifiOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5996 | mGlobalWifiRunning = false; |
| 5997 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5998 | mBluetoothOn = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5999 | mBluetoothOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | mUptime = in.readLong(); |
| 6001 | mUptimeStart = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6002 | mLastUptime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | mRealtime = in.readLong(); |
| 6004 | mRealtimeStart = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6005 | mLastRealtime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | mOnBattery = in.readInt() != 0; |
| 6007 | mOnBatteryInternal = false; // we are no longer really running. |
| 6008 | mTrackBatteryPastUptime = in.readLong(); |
| 6009 | mTrackBatteryUptimeStart = in.readLong(); |
| 6010 | mTrackBatteryPastRealtime = in.readLong(); |
| 6011 | mTrackBatteryRealtimeStart = in.readLong(); |
| 6012 | mUnpluggedBatteryUptime = in.readLong(); |
| 6013 | mUnpluggedBatteryRealtime = in.readLong(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6014 | mDischargeUnplugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6015 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6016 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 6017 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6018 | mDischargeAmountScreenOn = in.readInt(); |
| 6019 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 6020 | mDischargeAmountScreenOff = in.readInt(); |
| 6021 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | mLastWriteTime = in.readLong(); |
| 6023 | |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 6024 | mRadioDataUptime = in.readLong(); |
| 6025 | mRadioDataStart = -1; |
| 6026 | |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 6027 | mBluetoothPingCount = in.readInt(); |
| 6028 | mBluetoothPingStart = -1; |
| 6029 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6030 | mKernelWakelockStats.clear(); |
| 6031 | int NKW = in.readInt(); |
| 6032 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 6033 | if (in.readInt() != 0) { |
| 6034 | String wakelockName = in.readString(); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6035 | in.readInt(); // Extra 0/1 written by Timer.writeTimerToParcel |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6036 | SamplingTimer kwlt = new SamplingTimer(mUnpluggables, mOnBattery, in); |
| 6037 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 6038 | } |
| 6039 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6041 | mPartialTimers.clear(); |
| 6042 | mFullTimers.clear(); |
| 6043 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6044 | mWifiRunningTimers.clear(); |
| 6045 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6046 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6047 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6048 | mWifiMulticastTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6050 | sNumSpeedSteps = in.readInt(); |
| 6051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6052 | int numUids = in.readInt(); |
| 6053 | mUidStats.clear(); |
| 6054 | for (int i = 0; i < numUids; i++) { |
| 6055 | int uid = in.readInt(); |
| 6056 | Uid u = new Uid(uid); |
| 6057 | u.readFromParcelLocked(mUnpluggables, in); |
| 6058 | mUidStats.append(uid, u); |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6063 | writeToParcelLocked(out, true, flags); |
| 6064 | } |
| 6065 | |
| 6066 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 6067 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6068 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6069 | |
| 6070 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6071 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6072 | // Need to update with current kernel wake lock counts. |
| 6073 | updateKernelWakelocksLocked(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6074 | updateNetworkActivityLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 6077 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
| 6078 | final long batteryUptime = getBatteryUptimeLocked(uSecUptime); |
| 6079 | final long batteryRealtime = getBatteryRealtimeLocked(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6081 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6082 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 6083 | writeHistory(out, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6085 | out.writeInt(mStartCount); |
| 6086 | out.writeLong(mBatteryUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6087 | out.writeLong(mBatteryRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6088 | mScreenOnTimer.writeToParcel(out, batteryRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6089 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 6090 | mScreenBrightnessTimer[i].writeToParcel(out, batteryRealtime); |
| 6091 | } |
| 6092 | mInputEventCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6093 | mPhoneOnTimer.writeToParcel(out, batteryRealtime); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6094 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6095 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, batteryRealtime); |
| 6096 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6097 | mPhoneSignalScanningTimer.writeToParcel(out, batteryRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6098 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 6099 | mPhoneDataConnectionsTimer[i].writeToParcel(out, batteryRealtime); |
| 6100 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6101 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 6102 | mNetworkActivityCounters[i].writeToParcel(out); |
| 6103 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6104 | mWifiOnTimer.writeToParcel(out, batteryRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6105 | mGlobalWifiRunningTimer.writeToParcel(out, batteryRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6106 | mBluetoothOnTimer.writeToParcel(out, batteryRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | out.writeLong(mUptime); |
| 6108 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6109 | out.writeLong(mRealtime); |
| 6110 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | out.writeInt(mOnBattery ? 1 : 0); |
| 6112 | out.writeLong(batteryUptime); |
| 6113 | out.writeLong(mTrackBatteryUptimeStart); |
| 6114 | out.writeLong(batteryRealtime); |
| 6115 | out.writeLong(mTrackBatteryRealtimeStart); |
| 6116 | out.writeLong(mUnpluggedBatteryUptime); |
| 6117 | out.writeLong(mUnpluggedBatteryRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6118 | out.writeInt(mDischargeUnplugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6119 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6120 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 6121 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6122 | out.writeInt(mDischargeAmountScreenOn); |
| 6123 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 6124 | out.writeInt(mDischargeAmountScreenOff); |
| 6125 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | out.writeLong(mLastWriteTime); |
| 6127 | |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 6128 | // Write radio uptime for data |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 6129 | out.writeLong(getRadioDataUptime()); |
| 6130 | |
| 6131 | out.writeInt(getBluetoothPingCount()); |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 6132 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6133 | if (inclUids) { |
| 6134 | out.writeInt(mKernelWakelockStats.size()); |
| 6135 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 6136 | SamplingTimer kwlt = ent.getValue(); |
| 6137 | if (kwlt != null) { |
| 6138 | out.writeInt(1); |
| 6139 | out.writeString(ent.getKey()); |
| 6140 | Timer.writeTimerToParcel(out, kwlt, batteryRealtime); |
| 6141 | } else { |
| 6142 | out.writeInt(0); |
| 6143 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6144 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6145 | } else { |
| 6146 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6147 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6148 | |
| 6149 | out.writeInt(sNumSpeedSteps); |
| 6150 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6151 | if (inclUids) { |
| 6152 | int size = mUidStats.size(); |
| 6153 | out.writeInt(size); |
| 6154 | for (int i = 0; i < size; i++) { |
| 6155 | out.writeInt(mUidStats.keyAt(i)); |
| 6156 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6157 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6158 | uid.writeToParcelLocked(out, batteryRealtime); |
| 6159 | } |
| 6160 | } else { |
| 6161 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 6166 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 6167 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 6168 | return new BatteryStatsImpl(in); |
| 6169 | } |
| 6170 | |
| 6171 | public BatteryStatsImpl[] newArray(int size) { |
| 6172 | return new BatteryStatsImpl[size]; |
| 6173 | } |
| 6174 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6175 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6176 | public void prepareForDumpLocked() { |
| 6177 | // Need to retrieve current kernel wake lock stats before printing. |
| 6178 | updateKernelWakelocksLocked(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6179 | updateNetworkActivityLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 6182 | public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly, int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6183 | if (DEBUG) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6184 | Printer pr = new PrintWriterPrinter(pw); |
| 6185 | pr.println("*** Screen timer:"); |
| 6186 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6187 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6188 | pr.println("*** Screen brightness #" + i + ":"); |
| 6189 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6190 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6191 | pr.println("*** Input event counter:"); |
| 6192 | mInputEventCounter.logState(pr, " "); |
| 6193 | pr.println("*** Phone timer:"); |
| 6194 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6195 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6196 | pr.println("*** Signal strength #" + i + ":"); |
| 6197 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6198 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6199 | pr.println("*** Signal scanning :"); |
| 6200 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6201 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6202 | pr.println("*** Data connection type #" + i + ":"); |
| 6203 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6204 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6205 | pr.println("*** Wifi timer:"); |
| 6206 | mWifiOnTimer.logState(pr, " "); |
| 6207 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6208 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6209 | pr.println("*** Bluetooth timer:"); |
| 6210 | mBluetoothOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | } |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 6212 | super.dumpLocked(pw, isUnpluggedOnly, reqUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6214 | } |