The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.os; |
| 18 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 23 | import android.content.Intent; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 24 | import android.net.ConnectivityManager; |
| 25 | import android.net.NetworkStats; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 26 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 27 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 28 | import android.os.BadParcelableException; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 29 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 31 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 32 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 34 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 35 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.ParcelFormatException; |
| 38 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 39 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 41 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 42 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 43 | import android.telephony.DataConnectionRealTimeInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 44 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 45 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 46 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 47 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 48 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 50 | import android.util.LogWriter; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 51 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 52 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 54 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 56 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 57 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 58 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 59 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 60 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 62 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 63 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 64 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 65 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 66 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 67 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 68 | import com.android.server.NetworkManagementSocketTagger; |
| 69 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 70 | import org.xmlpull.v1.XmlPullParser; |
| 71 | import org.xmlpull.v1.XmlPullParserException; |
| 72 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 73 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 74 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import java.io.File; |
| 76 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 77 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import java.io.FileOutputStream; |
| 79 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 80 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 81 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 83 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 85 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 87 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 88 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * All information we are collecting about things that can happen that impact |
| 92 | * battery life. All times are represented in microseconds except where indicated |
| 93 | * otherwise. |
| 94 | */ |
| 95 | public final class BatteryStatsImpl extends BatteryStats { |
| 96 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 97 | private static final boolean DEBUG = false; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 98 | private static final boolean DEBUG_ENERGY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 99 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 100 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 101 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 102 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | // 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] | 105 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
| 107 | // Current on-disk Parcel version |
Adam Lesinski | df6235c | 2015-06-08 15:04:16 -0700 | [diff] [blame] | 108 | private static final int VERSION = 127 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 109 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 110 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 111 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 112 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 113 | // No, really, THIS is the maximum number of items we will record in the history. |
| 114 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 115 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 116 | // The maximum number of names wakelocks we will keep track of |
| 117 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 118 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 119 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 120 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 121 | private static int sNumSpeedSteps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 123 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 124 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 125 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 127 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 128 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 129 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 130 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 131 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 132 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 133 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 134 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 135 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 136 | private final KernelCpuSpeedReader mKernelCpuSpeedReader = new KernelCpuSpeedReader(); |
| 137 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 138 | public interface BatteryCallback { |
| 139 | public void batteryNeedsCpuUpdate(); |
| 140 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 141 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 145 | public MyHandler(Looper looper) { |
| 146 | super(looper, null, true); |
| 147 | } |
| 148 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 149 | @Override |
| 150 | public void handleMessage(Message msg) { |
| 151 | BatteryCallback cb = mCallback; |
| 152 | switch (msg.what) { |
| 153 | case MSG_UPDATE_WAKELOCKS: |
| 154 | if (cb != null) { |
| 155 | cb.batteryNeedsCpuUpdate(); |
| 156 | } |
| 157 | break; |
| 158 | case MSG_REPORT_POWER_CHANGE: |
| 159 | if (cb != null) { |
| 160 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 161 | } |
| 162 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 163 | case MSG_REPORT_CHARGING: |
| 164 | if (cb != null) { |
| 165 | final String action; |
| 166 | synchronized (BatteryStatsImpl.this) { |
| 167 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 168 | : BatteryManager.ACTION_DISCHARGING; |
| 169 | } |
| 170 | Intent intent = new Intent(action); |
| 171 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 172 | cb.batterySendBroadcast(intent); |
| 173 | } |
| 174 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 179 | public interface ExternalStatsSync { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 180 | void scheduleSync(String reason); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 183 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 184 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 185 | |
| 186 | private BatteryCallback mCallback; |
| 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 189 | * Mapping isolated uids to the actual owning app uid. |
| 190 | */ |
| 191 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 192 | |
| 193 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | * The statistics we have collected organized by uids. |
| 195 | */ |
| 196 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 197 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 198 | |
| 199 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 200 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 201 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 202 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 203 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 204 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 205 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
| 206 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 207 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 208 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 209 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 210 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 211 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 212 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 213 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 214 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 215 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 217 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 218 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | // These are the objects that will want to do something when the device |
| 221 | // is unplugged from power. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 222 | final TimeBase mOnBatteryTimeBase = new TimeBase(); |
| 223 | |
| 224 | // These are the objects that will want to do something when the device |
| 225 | // is unplugged from power *and* the screen is off. |
| 226 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 227 | |
| 228 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 229 | // CPU update, even if we aren't currently running wake locks. |
| 230 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 231 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 232 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 233 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 234 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 235 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 236 | long mHistoryBaseTime; |
| 237 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 238 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 239 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 240 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 241 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 242 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 243 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 244 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 245 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 246 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 247 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 248 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 249 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 250 | int[] mReadHistoryUids; |
| 251 | int mReadHistoryChars; |
| 252 | int mNextHistoryTagIdx = 0; |
| 253 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 254 | int mHistoryBufferLastPos = -1; |
| 255 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 256 | int mActiveHistoryStates = 0xffffffff; |
| 257 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 258 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 259 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 260 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 261 | |
| 262 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 263 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 264 | HistoryItem mHistory; |
| 265 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 266 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 267 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 268 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 269 | // Used by computeHistoryStepDetails |
| 270 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 271 | byte mLastHistoryStepLevel = 0; |
| 272 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 273 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 274 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 275 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 276 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 277 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 278 | */ |
| 279 | long mLastStepCpuUserTime; |
| 280 | long mCurStepCpuUserTime; |
| 281 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 282 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 283 | */ |
| 284 | long mLastStepCpuSystemTime; |
| 285 | long mCurStepCpuSystemTime; |
| 286 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 287 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 288 | */ |
| 289 | long mLastStepStatUserTime; |
| 290 | long mLastStepStatSystemTime; |
| 291 | long mLastStepStatIOWaitTime; |
| 292 | long mLastStepStatIrqTime; |
| 293 | long mLastStepStatSoftIrqTime; |
| 294 | long mLastStepStatIdleTime; |
| 295 | long mCurStepStatUserTime; |
| 296 | long mCurStepStatSystemTime; |
| 297 | long mCurStepStatIOWaitTime; |
| 298 | long mCurStepStatIrqTime; |
| 299 | long mCurStepStatSoftIrqTime; |
| 300 | long mCurStepStatIdleTime; |
| 301 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 302 | private HistoryItem mHistoryIterator; |
| 303 | private boolean mReadOverflow; |
| 304 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | int mStartCount; |
| 307 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 308 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 309 | String mStartPlatformVersion; |
| 310 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | long mUptime; |
| 313 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | long mRealtime; |
| 315 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 316 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 317 | int mWakeLockNesting; |
| 318 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 319 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 320 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 321 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 322 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 323 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 324 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 325 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 326 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 327 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 328 | boolean mInteractive; |
| 329 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 330 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 331 | boolean mPowerSaveModeEnabled; |
| 332 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 333 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 334 | boolean mDeviceIdling; |
| 335 | StopwatchTimer mDeviceIdlingTimer; |
| 336 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 337 | boolean mDeviceIdleModeEnabled; |
| 338 | StopwatchTimer mDeviceIdleModeEnabledTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 341 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 343 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 344 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 345 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 346 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 347 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 348 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 349 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 350 | StopwatchTimer mFlashlightOnTimer; |
| 351 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 352 | int mCameraOnNesting; |
| 353 | StopwatchTimer mCameraOnTimer; |
| 354 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 355 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 356 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 357 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 358 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 359 | |
| 360 | StopwatchTimer mPhoneSignalScanningTimer; |
| 361 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 362 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 363 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 364 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 365 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 366 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 367 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 368 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 369 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 370 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 371 | final LongSamplingCounter[] mBluetoothActivityCounters = |
| 372 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 373 | |
| 374 | final LongSamplingCounter[] mWifiActivityCounters = |
| 375 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 376 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 377 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 378 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 379 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 380 | boolean mGlobalWifiRunning; |
| 381 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 382 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 383 | int mWifiState = -1; |
| 384 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 385 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 386 | int mWifiSupplState = -1; |
| 387 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 388 | |
| 389 | int mWifiSignalStrengthBin = -1; |
| 390 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 391 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 392 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 393 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 394 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 395 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 396 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 397 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 398 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 399 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 400 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 401 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | /** |
| 404 | * These provide time bases that discount the time the device is plugged |
| 405 | * in to power. |
| 406 | */ |
| 407 | boolean mOnBattery; |
| 408 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 409 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 410 | /** |
| 411 | * External reporting of whether the device is actually charging. |
| 412 | */ |
| 413 | boolean mCharging = true; |
| 414 | int mLastChargingStateLevel; |
| 415 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 416 | /* |
| 417 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 418 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 419 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 420 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 421 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 422 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 423 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 424 | int mLowDischargeAmountSinceCharge; |
| 425 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 426 | int mDischargeScreenOnUnplugLevel; |
| 427 | int mDischargeScreenOffUnplugLevel; |
| 428 | int mDischargeAmountScreenOn; |
| 429 | int mDischargeAmountScreenOnSinceCharge; |
| 430 | int mDischargeAmountScreenOff; |
| 431 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 432 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 433 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 434 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 435 | int mInitStepMode = 0; |
| 436 | int mCurStepMode = 0; |
| 437 | int mModStepMode = 0; |
| 438 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 439 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 440 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 441 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 442 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 443 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 444 | |
| 445 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 446 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 447 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 448 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 449 | |
| 450 | static final int MAX_DAILY_ITEMS = 10; |
| 451 | |
| 452 | long mDailyStartTime = 0; |
| 453 | long mNextMinDailyDeadline = 0; |
| 454 | long mNextMaxDailyDeadline = 0; |
| 455 | |
| 456 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 459 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 460 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 461 | private int mPhoneServiceStateRaw = -1; |
| 462 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 463 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 464 | private int mNumConnectivityChange; |
| 465 | private int mLoadedNumConnectivityChange; |
| 466 | private int mUnpluggedNumConnectivityChange; |
| 467 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 468 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 469 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 470 | private PowerProfile mPowerProfile; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 471 | private boolean mHasWifiEnergyReporting = false; |
| 472 | private boolean mHasBluetoothEnergyReporting = false; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 473 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 474 | /* |
| 475 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 476 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 477 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 478 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 479 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 480 | return mKernelWakelockStats; |
| 481 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 482 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 483 | String mLastWakeupReason = null; |
| 484 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 485 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 486 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 487 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 488 | return mWakeupReasonStats; |
| 489 | } |
| 490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 492 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 493 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 494 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 495 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 496 | mExternalSync = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 497 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 500 | public static interface TimeBaseObs { |
| 501 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 502 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 503 | } |
| 504 | |
| 505 | static class TimeBase { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 506 | private final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 507 | |
| 508 | private long mUptime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 509 | private long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 510 | |
| 511 | private boolean mRunning; |
| 512 | |
| 513 | private long mPastUptime; |
| 514 | private long mUptimeStart; |
| 515 | private long mPastRealtime; |
| 516 | private long mRealtimeStart; |
| 517 | private long mUnpluggedUptime; |
| 518 | private long mUnpluggedRealtime; |
| 519 | |
| 520 | public void dump(PrintWriter pw, String prefix) { |
| 521 | StringBuilder sb = new StringBuilder(128); |
| 522 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 523 | sb.setLength(0); |
| 524 | sb.append(prefix); |
| 525 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 526 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 527 | pw.println(sb.toString()); |
| 528 | sb.setLength(0); |
| 529 | sb.append(prefix); |
| 530 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 531 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 532 | pw.println(sb.toString()); |
| 533 | sb.setLength(0); |
| 534 | sb.append(prefix); |
| 535 | sb.append("mPastUptime="); |
| 536 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 537 | formatTimeMs(sb, mUptimeStart / 1000); |
| 538 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 539 | pw.println(sb.toString()); |
| 540 | sb.setLength(0); |
| 541 | sb.append(prefix); |
| 542 | sb.append("mPastRealtime="); |
| 543 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 544 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 545 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 546 | pw.println(sb.toString()); |
| 547 | } |
| 548 | |
| 549 | public void add(TimeBaseObs observer) { |
| 550 | mObservers.add(observer); |
| 551 | } |
| 552 | |
| 553 | public void remove(TimeBaseObs observer) { |
| 554 | if (!mObservers.remove(observer)) { |
| 555 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | public void init(long uptime, long realtime) { |
| 560 | mRealtime = 0; |
| 561 | mUptime = 0; |
| 562 | mPastUptime = 0; |
| 563 | mPastRealtime = 0; |
| 564 | mUptimeStart = uptime; |
| 565 | mRealtimeStart = realtime; |
| 566 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 567 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 568 | } |
| 569 | |
| 570 | public void reset(long uptime, long realtime) { |
| 571 | if (!mRunning) { |
| 572 | mPastUptime = 0; |
| 573 | mPastRealtime = 0; |
| 574 | } else { |
| 575 | mUptimeStart = uptime; |
| 576 | mRealtimeStart = realtime; |
| 577 | mUnpluggedUptime = getUptime(uptime); |
| 578 | mUnpluggedRealtime = getRealtime(realtime); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | public long computeUptime(long curTime, int which) { |
| 583 | switch (which) { |
| 584 | case STATS_SINCE_CHARGED: |
| 585 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 586 | case STATS_CURRENT: |
| 587 | return getUptime(curTime); |
| 588 | case STATS_SINCE_UNPLUGGED: |
| 589 | return getUptime(curTime) - mUnpluggedUptime; |
| 590 | } |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | public long computeRealtime(long curTime, int which) { |
| 595 | switch (which) { |
| 596 | case STATS_SINCE_CHARGED: |
| 597 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 598 | case STATS_CURRENT: |
| 599 | return getRealtime(curTime); |
| 600 | case STATS_SINCE_UNPLUGGED: |
| 601 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | public long getUptime(long curTime) { |
| 607 | long time = mPastUptime; |
| 608 | if (mRunning) { |
| 609 | time += curTime - mUptimeStart; |
| 610 | } |
| 611 | return time; |
| 612 | } |
| 613 | |
| 614 | public long getRealtime(long curTime) { |
| 615 | long time = mPastRealtime; |
| 616 | if (mRunning) { |
| 617 | time += curTime - mRealtimeStart; |
| 618 | } |
| 619 | return time; |
| 620 | } |
| 621 | |
| 622 | public long getUptimeStart() { |
| 623 | return mUptimeStart; |
| 624 | } |
| 625 | |
| 626 | public long getRealtimeStart() { |
| 627 | return mRealtimeStart; |
| 628 | } |
| 629 | |
| 630 | public boolean isRunning() { |
| 631 | return mRunning; |
| 632 | } |
| 633 | |
| 634 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 635 | if (mRunning != running) { |
| 636 | mRunning = running; |
| 637 | if (running) { |
| 638 | mUptimeStart = uptime; |
| 639 | mRealtimeStart = realtime; |
| 640 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 641 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 642 | |
| 643 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 644 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 645 | } |
| 646 | } else { |
| 647 | mPastUptime += uptime - mUptimeStart; |
| 648 | mPastRealtime += realtime - mRealtimeStart; |
| 649 | |
| 650 | long batteryUptime = getUptime(uptime); |
| 651 | long batteryRealtime = getRealtime(realtime); |
| 652 | |
| 653 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 654 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 655 | } |
| 656 | } |
| 657 | return true; |
| 658 | } |
| 659 | return false; |
| 660 | } |
| 661 | |
| 662 | public void readSummaryFromParcel(Parcel in) { |
| 663 | mUptime = in.readLong(); |
| 664 | mRealtime = in.readLong(); |
| 665 | } |
| 666 | |
| 667 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 668 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 669 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 670 | } |
| 671 | |
| 672 | public void readFromParcel(Parcel in) { |
| 673 | mRunning = false; |
| 674 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 675 | mPastUptime = in.readLong(); |
| 676 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 677 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 678 | mPastRealtime = in.readLong(); |
| 679 | mRealtimeStart = in.readLong(); |
| 680 | mUnpluggedUptime = in.readLong(); |
| 681 | mUnpluggedRealtime = in.readLong(); |
| 682 | } |
| 683 | |
| 684 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 685 | final long runningUptime = getUptime(uptime); |
| 686 | final long runningRealtime = getRealtime(realtime); |
| 687 | out.writeLong(mUptime); |
| 688 | out.writeLong(runningUptime); |
| 689 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 690 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 691 | out.writeLong(runningRealtime); |
| 692 | out.writeLong(mRealtimeStart); |
| 693 | out.writeLong(mUnpluggedUptime); |
| 694 | out.writeLong(mUnpluggedRealtime); |
| 695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 699 | * State for keeping track of counting information. |
| 700 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 701 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 702 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 703 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 704 | int mLoadedCount; |
| 705 | int mLastCount; |
| 706 | int mUnpluggedCount; |
| 707 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 708 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 709 | Counter(TimeBase timeBase, Parcel in) { |
| 710 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 711 | mPluggedCount = in.readInt(); |
| 712 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 713 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 714 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 715 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 716 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 719 | Counter(TimeBase timeBase) { |
| 720 | mTimeBase = timeBase; |
| 721 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 722 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 723 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 724 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 725 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 726 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 727 | out.writeInt(mUnpluggedCount); |
| 728 | } |
| 729 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 730 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 731 | mUnpluggedCount = mPluggedCount; |
| 732 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 735 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 736 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 737 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 738 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 739 | /** |
| 740 | * Writes a possibly null Counter to a Parcel. |
| 741 | * |
| 742 | * @param out the Parcel to be written to. |
| 743 | * @param counter a Counter, or null. |
| 744 | */ |
| 745 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 746 | if (counter == null) { |
| 747 | out.writeInt(0); // indicates null |
| 748 | return; |
| 749 | } |
| 750 | out.writeInt(1); // indicates non-null |
| 751 | |
| 752 | counter.writeToParcel(out); |
| 753 | } |
| 754 | |
| 755 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 756 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 757 | int val = mCount.get(); |
| 758 | if (which == STATS_SINCE_UNPLUGGED) { |
| 759 | val -= mUnpluggedCount; |
| 760 | } else if (which != STATS_SINCE_CHARGED) { |
| 761 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | return val; |
| 765 | } |
| 766 | |
| 767 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 768 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 769 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 770 | + " mUnpluggedCount=" + mUnpluggedCount |
| 771 | + " mPluggedCount=" + mPluggedCount); |
| 772 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 773 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 774 | void stepAtomic() { |
| 775 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 778 | /** |
| 779 | * Clear state of this counter. |
| 780 | */ |
| 781 | void reset(boolean detachIfReset) { |
| 782 | mCount.set(0); |
| 783 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 784 | if (detachIfReset) { |
| 785 | detach(); |
| 786 | } |
| 787 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 788 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 789 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 790 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 791 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 792 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 793 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 794 | int count = mCount.get(); |
| 795 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 799 | mLoadedCount = in.readInt(); |
| 800 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 801 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 802 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 803 | } |
| 804 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 805 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 806 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 807 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 808 | long mCount; |
| 809 | long mLoadedCount; |
| 810 | long mLastCount; |
| 811 | long mUnpluggedCount; |
| 812 | long mPluggedCount; |
| 813 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 814 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 815 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 816 | mPluggedCount = in.readLong(); |
| 817 | mCount = mPluggedCount; |
| 818 | mLoadedCount = in.readLong(); |
| 819 | mLastCount = 0; |
| 820 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 821 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 824 | LongSamplingCounter(TimeBase timeBase) { |
| 825 | mTimeBase = timeBase; |
| 826 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | public void writeToParcel(Parcel out) { |
| 830 | out.writeLong(mCount); |
| 831 | out.writeLong(mLoadedCount); |
| 832 | out.writeLong(mUnpluggedCount); |
| 833 | } |
| 834 | |
| 835 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 836 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 837 | mUnpluggedCount = mPluggedCount; |
| 838 | mCount = mPluggedCount; |
| 839 | } |
| 840 | |
| 841 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 842 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 843 | mPluggedCount = mCount; |
| 844 | } |
| 845 | |
| 846 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 847 | long val = mCount; |
| 848 | if (which == STATS_SINCE_UNPLUGGED) { |
| 849 | val -= mUnpluggedCount; |
| 850 | } else if (which != STATS_SINCE_CHARGED) { |
| 851 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | return val; |
| 855 | } |
| 856 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 857 | @Override |
| 858 | public void logState(Printer pw, String prefix) { |
| 859 | pw.println(prefix + "mCount=" + mCount |
| 860 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 861 | + " mUnpluggedCount=" + mUnpluggedCount |
| 862 | + " mPluggedCount=" + mPluggedCount); |
| 863 | } |
| 864 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 865 | void addCountLocked(long count) { |
| 866 | mCount += count; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Clear state of this counter. |
| 871 | */ |
| 872 | void reset(boolean detachIfReset) { |
| 873 | mCount = 0; |
| 874 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 875 | if (detachIfReset) { |
| 876 | detach(); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 881 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | void writeSummaryFromParcelLocked(Parcel out) { |
| 885 | out.writeLong(mCount); |
| 886 | } |
| 887 | |
| 888 | void readSummaryFromParcelLocked(Parcel in) { |
| 889 | mLoadedCount = in.readLong(); |
| 890 | mCount = mLoadedCount; |
| 891 | mLastCount = 0; |
| 892 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 893 | } |
| 894 | } |
| 895 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 896 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | * State for keeping track of timing information. |
| 898 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 899 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | final int mType; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 901 | final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | int mCount; |
| 904 | int mLoadedCount; |
| 905 | int mLastCount; |
| 906 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | // Times are in microseconds for better accuracy when dividing by the |
| 909 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | /** |
| 912 | * The total time we have accumulated since the start of the original |
| 913 | * boot, to the last time something interesting happened in the |
| 914 | * current run. |
| 915 | */ |
| 916 | long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | /** |
| 919 | * The total time we loaded for the previous runs. Subtract this from |
| 920 | * mTotalTime to find the time for the current run of the system. |
| 921 | */ |
| 922 | long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | /** |
| 925 | * The run time of the last run of the system, as loaded from the |
| 926 | * saved data. |
| 927 | */ |
| 928 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 930 | /** |
| 931 | * The value of mTotalTime when unplug() was last called. Subtract |
| 932 | * this from mTotalTime to find the time since the last unplug from |
| 933 | * power. |
| 934 | */ |
| 935 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 936 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 937 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 938 | * The total time this timer has been running until the latest mark has been set. |
| 939 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 940 | */ |
| 941 | long mTimeBeforeMark; |
| 942 | |
| 943 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 944 | * Constructs from a parcel. |
| 945 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 946 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 947 | * @param in |
| 948 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 949 | Timer(int type, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 951 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | mCount = in.readInt(); |
| 954 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 955 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | mUnpluggedCount = in.readInt(); |
| 957 | mTotalTime = in.readLong(); |
| 958 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 959 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 961 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 962 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 963 | if (DEBUG) Log.i(TAG, "**** READ TIMER #" + mType + ": mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 966 | Timer(int type, TimeBase timeBase) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 968 | mTimeBase = timeBase; |
| 969 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 971 | |
| 972 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 973 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 974 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 975 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 976 | /** |
| 977 | * Clear state of this timer. Returns true if the timer is inactive |
| 978 | * so can be completely dropped. |
| 979 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 980 | boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 981 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 982 | mCount = mLoadedCount = mLastCount = 0; |
| 983 | if (detachIfReset) { |
| 984 | detach(); |
| 985 | } |
| 986 | return true; |
| 987 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 988 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 989 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 990 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 991 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 992 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 993 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 994 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 995 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | out.writeInt(mCount); |
| 997 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 999 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1002 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1005 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1006 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1008 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1010 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1011 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1012 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | mUnpluggedCount = mCount; |
| 1014 | if (DEBUG && mType < 0) { |
| 1015 | Log.v(TAG, "unplug #" + mType |
| 1016 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1017 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1018 | } |
| 1019 | } |
| 1020 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1021 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1022 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1023 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1024 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1025 | + " old mTotalTime=" + mTotalTime); |
| 1026 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1027 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1028 | mCount = computeCurrentCountLocked(); |
| 1029 | if (DEBUG && mType < 0) { |
| 1030 | Log.v(TAG, "plug #" + mType |
| 1031 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | /** |
| 1036 | * Writes a possibly null Timer to a Parcel. |
| 1037 | * |
| 1038 | * @param out the Parcel to be written to. |
| 1039 | * @param timer a Timer, or null. |
| 1040 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1041 | public static void writeTimerToParcel(Parcel out, Timer timer, long elapsedRealtimeUs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | if (timer == null) { |
| 1043 | out.writeInt(0); // indicates null |
| 1044 | return; |
| 1045 | } |
| 1046 | out.writeInt(1); // indicates non-null |
| 1047 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1048 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1052 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1053 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1054 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1055 | val -= mUnpluggedTime; |
| 1056 | } else if (which != STATS_SINCE_CHARGED) { |
| 1057 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | return val; |
| 1061 | } |
| 1062 | |
| 1063 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1064 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1065 | int val = computeCurrentCountLocked(); |
| 1066 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1067 | val -= mUnpluggedCount; |
| 1068 | } else if (which != STATS_SINCE_CHARGED) { |
| 1069 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | return val; |
| 1073 | } |
| 1074 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1075 | @Override |
| 1076 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1077 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1078 | return val - mTimeBeforeMark; |
| 1079 | } |
| 1080 | |
| 1081 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1082 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1083 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1085 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1086 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1088 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1090 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1091 | |
| 1092 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1093 | void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1094 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1095 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1096 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | void readSummaryFromParcelLocked(Parcel in) { |
| 1100 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1101 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1102 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1103 | mUnpluggedTime = mTotalTime; |
| 1104 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1105 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1106 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1107 | |
| 1108 | // When reading the summary, we set the mark to be the latest information. |
| 1109 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1110 | } |
| 1111 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1112 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1113 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1114 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * The most recent reported count from /proc/wakelocks. |
| 1117 | */ |
| 1118 | int mCurrentReportedCount; |
| 1119 | |
| 1120 | /** |
| 1121 | * The reported count from /proc/wakelocks when unplug() was last |
| 1122 | * called. |
| 1123 | */ |
| 1124 | int mUnpluggedReportedCount; |
| 1125 | |
| 1126 | /** |
| 1127 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1128 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1129 | long mCurrentReportedTotalTime; |
| 1130 | |
| 1131 | |
| 1132 | /** |
| 1133 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1134 | * called. |
| 1135 | */ |
| 1136 | long mUnpluggedReportedTotalTime; |
| 1137 | |
| 1138 | /** |
| 1139 | * Whether we are currently in a discharge cycle. |
| 1140 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1141 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1142 | |
| 1143 | /** |
| 1144 | * Whether we are currently recording reported values. |
| 1145 | */ |
| 1146 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1147 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1148 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1149 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1150 | */ |
| 1151 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1152 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1153 | SamplingTimer(TimeBase timeBase, Parcel in) { |
| 1154 | super(0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1155 | mCurrentReportedCount = in.readInt(); |
| 1156 | mUnpluggedReportedCount = in.readInt(); |
| 1157 | mCurrentReportedTotalTime = in.readLong(); |
| 1158 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1159 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1160 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1161 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1162 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1163 | SamplingTimer(TimeBase timeBase, boolean trackReportedValues) { |
| 1164 | super(0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1165 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1166 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1167 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1168 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1169 | public void setStale() { |
| 1170 | mTrackingReportedValues = false; |
| 1171 | mUnpluggedReportedTotalTime = 0; |
| 1172 | mUnpluggedReportedCount = 0; |
| 1173 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1174 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1175 | public void setUpdateVersion(int version) { |
| 1176 | mUpdateVersion = version; |
| 1177 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1178 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1179 | public int getUpdateVersion() { |
| 1180 | return mUpdateVersion; |
| 1181 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1182 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1183 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1184 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1185 | // Updating the reported value for the first time. |
| 1186 | mUnpluggedReportedCount = count; |
| 1187 | // If we are receiving an update update mTrackingReportedValues; |
| 1188 | mTrackingReportedValues = true; |
| 1189 | } |
| 1190 | mCurrentReportedCount = count; |
| 1191 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1192 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1193 | public void addCurrentReportedCount(int delta) { |
| 1194 | updateCurrentReportedCount(mCurrentReportedCount + delta); |
| 1195 | } |
| 1196 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1197 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1198 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1199 | // Updating the reported value for the first time. |
| 1200 | mUnpluggedReportedTotalTime = totalTime; |
| 1201 | // If we are receiving an update update mTrackingReportedValues; |
| 1202 | mTrackingReportedValues = true; |
| 1203 | } |
| 1204 | mCurrentReportedTotalTime = totalTime; |
| 1205 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1206 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1207 | public void addCurrentReportedTotalTime(long delta) { |
| 1208 | updateCurrentReportedTotalTime(mCurrentReportedTotalTime + delta); |
| 1209 | } |
| 1210 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1211 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1212 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1213 | if (mTrackingReportedValues) { |
| 1214 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1215 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1216 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1217 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1220 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1221 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1222 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1223 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1224 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1225 | public void logState(Printer pw, String prefix) { |
| 1226 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1227 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1228 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1229 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1230 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1231 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1232 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1233 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1234 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1235 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1236 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1237 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1238 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1239 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1240 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1241 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1242 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1243 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1244 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1245 | out.writeInt(mCurrentReportedCount); |
| 1246 | out.writeInt(mUnpluggedReportedCount); |
| 1247 | out.writeLong(mCurrentReportedTotalTime); |
| 1248 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1249 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1250 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1251 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1252 | boolean reset(boolean detachIfReset) { |
| 1253 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1254 | setStale(); |
| 1255 | return true; |
| 1256 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1257 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1258 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 1259 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1260 | out.writeLong(mCurrentReportedTotalTime); |
| 1261 | out.writeInt(mCurrentReportedCount); |
| 1262 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1263 | } |
| 1264 | |
| 1265 | void readSummaryFromParcelLocked(Parcel in) { |
| 1266 | super.readSummaryFromParcelLocked(in); |
| 1267 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1268 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1269 | mTrackingReportedValues = in.readInt() == 1; |
| 1270 | } |
| 1271 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1272 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1273 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1274 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1275 | * for a pre-determined amount. |
| 1276 | */ |
| 1277 | public static final class BatchTimer extends Timer { |
| 1278 | final Uid mUid; |
| 1279 | |
| 1280 | /** |
| 1281 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1282 | */ |
| 1283 | long mLastAddedTime; |
| 1284 | |
| 1285 | /** |
| 1286 | * The last duration that we added to the timer. This is in microseconds. |
| 1287 | */ |
| 1288 | long mLastAddedDuration; |
| 1289 | |
| 1290 | /** |
| 1291 | * Whether we are currently in a discharge cycle. |
| 1292 | */ |
| 1293 | boolean mInDischarge; |
| 1294 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1295 | BatchTimer(Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1296 | super(type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1297 | mUid = uid; |
| 1298 | mLastAddedTime = in.readLong(); |
| 1299 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1300 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1303 | BatchTimer(Uid uid, int type, TimeBase timeBase) { |
| 1304 | super(type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1305 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1306 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1310 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1311 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1312 | out.writeLong(mLastAddedTime); |
| 1313 | out.writeLong(mLastAddedDuration); |
| 1314 | } |
| 1315 | |
| 1316 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1317 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1318 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 1319 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1320 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1324 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1325 | recomputeLastDuration(elapsedRealtime, false); |
| 1326 | mInDischarge = true; |
| 1327 | // If we are still within the last added duration, then re-added whatever remains. |
| 1328 | if (mLastAddedTime == elapsedRealtime) { |
| 1329 | mTotalTime += mLastAddedDuration; |
| 1330 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1331 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | @Override |
| 1335 | public void logState(Printer pw, String prefix) { |
| 1336 | super.logState(pw, prefix); |
| 1337 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1338 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1339 | } |
| 1340 | |
| 1341 | private long computeOverage(long curTime) { |
| 1342 | if (mLastAddedTime > 0) { |
| 1343 | return mLastTime + mLastAddedDuration - curTime; |
| 1344 | } |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
| 1348 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1349 | final long overage = computeOverage(curTime); |
| 1350 | if (overage > 0) { |
| 1351 | // Aborting before the duration ran out -- roll back the remaining |
| 1352 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1353 | // actually add the time. |
| 1354 | if (mInDischarge) { |
| 1355 | mTotalTime -= overage; |
| 1356 | } |
| 1357 | if (abort) { |
| 1358 | mLastAddedTime = 0; |
| 1359 | } else { |
| 1360 | mLastAddedTime = curTime; |
| 1361 | mLastAddedDuration -= overage; |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1367 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1368 | recomputeLastDuration(now, true); |
| 1369 | mLastAddedTime = now; |
| 1370 | mLastAddedDuration = durationMillis * 1000; |
| 1371 | if (mInDischarge) { |
| 1372 | mTotalTime += mLastAddedDuration; |
| 1373 | mCount++; |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1378 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1379 | recomputeLastDuration(now, true); |
| 1380 | } |
| 1381 | |
| 1382 | @Override |
| 1383 | protected int computeCurrentCountLocked() { |
| 1384 | return mCount; |
| 1385 | } |
| 1386 | |
| 1387 | @Override |
| 1388 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1389 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1390 | if (overage > 0) { |
| 1391 | return mTotalTime = overage; |
| 1392 | } |
| 1393 | return mTotalTime; |
| 1394 | } |
| 1395 | |
| 1396 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1397 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1398 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1399 | recomputeLastDuration(now, true); |
| 1400 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1401 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1402 | return !stillActive; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1407 | * State for keeping track of timing information. |
| 1408 | */ |
| 1409 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1410 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1411 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1412 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1413 | int mNesting; |
| 1414 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1415 | /** |
| 1416 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1417 | * subtract this from the current battery time to find the amount of |
| 1418 | * time we have been running since we last computed an update. |
| 1419 | */ |
| 1420 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1421 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1422 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1423 | * 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] | 1424 | * was actually held for an interesting duration. |
| 1425 | */ |
| 1426 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1427 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1428 | long mTimeout; |
| 1429 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1430 | /** |
| 1431 | * For partial wake locks, keep track of whether we are in the list |
| 1432 | * to consume CPU cycles. |
| 1433 | */ |
| 1434 | boolean mInList; |
| 1435 | |
| 1436 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1437 | TimeBase timeBase, Parcel in) { |
| 1438 | super(type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1439 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1440 | mTimerPool = timerPool; |
| 1441 | mUpdateTime = in.readLong(); |
| 1442 | } |
| 1443 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1444 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1445 | TimeBase timeBase) { |
| 1446 | super(type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1447 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1448 | mTimerPool = timerPool; |
| 1449 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1450 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1451 | void setTimeout(long timeout) { |
| 1452 | mTimeout = timeout; |
| 1453 | } |
| 1454 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1455 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1456 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1457 | out.writeLong(mUpdateTime); |
| 1458 | } |
| 1459 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1460 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1461 | if (mNesting > 0) { |
| 1462 | if (DEBUG && mType < 0) { |
| 1463 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1464 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1465 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1466 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1467 | if (DEBUG && mType < 0) { |
| 1468 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | public void logState(Printer pw, String prefix) { |
| 1474 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1475 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | + " mAcquireTime=" + mAcquireTime); |
| 1477 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1478 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1479 | void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1481 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1482 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | if (mTimerPool != null) { |
| 1484 | // Accumulate time to all currently active timers before adding |
| 1485 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1486 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | // Add this timer to the active pool |
| 1488 | mTimerPool.add(this); |
| 1489 | } |
| 1490 | // Increment the count |
| 1491 | mCount++; |
| 1492 | mAcquireTime = mTotalTime; |
| 1493 | if (DEBUG && mType < 0) { |
| 1494 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1495 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1496 | + " mAcquireTime=" + mAcquireTime); |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1501 | boolean isRunningLocked() { |
| 1502 | return mNesting > 0; |
| 1503 | } |
| 1504 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1505 | void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | // Ignore attempt to stop a timer that isn't running |
| 1507 | if (mNesting == 0) { |
| 1508 | return; |
| 1509 | } |
| 1510 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1511 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | if (mTimerPool != null) { |
| 1513 | // Accumulate time to all active counters, scaled by the total |
| 1514 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1515 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | // Remove this timer from the active pool |
| 1517 | mTimerPool.remove(this); |
| 1518 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | mNesting = 1; |
| 1520 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1521 | mNesting = 0; |
| 1522 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | if (DEBUG && mType < 0) { |
| 1525 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1526 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1527 | + " mAcquireTime=" + mAcquireTime); |
| 1528 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | if (mTotalTime == mAcquireTime) { |
| 1531 | // If there was no change in the time, then discard this |
| 1532 | // count. A somewhat cheezy strategy, but hey. |
| 1533 | mCount--; |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1538 | void stopAllRunningLocked(long elapsedRealtimeMs) { |
| 1539 | if (mNesting > 0) { |
| 1540 | mNesting = 1; |
| 1541 | stopRunningLocked(elapsedRealtimeMs); |
| 1542 | } |
| 1543 | } |
| 1544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | // Update the total time for all other running Timers with the same type as this Timer |
| 1546 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1547 | private static long refreshTimersLocked(long batteryRealtime, |
| 1548 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1549 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | final int N = pool.size(); |
| 1551 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1552 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1554 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1555 | final long myTime = heldTime / N; |
| 1556 | if (t == self) { |
| 1557 | selfTime = myTime; |
| 1558 | } |
| 1559 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | } |
| 1561 | t.mUpdateTime = batteryRealtime; |
| 1562 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1563 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1566 | @Override |
| 1567 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1568 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1569 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1570 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | return mTotalTime + (mNesting > 0 |
| 1572 | ? (curBatteryRealtime - mUpdateTime) |
| 1573 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1574 | : 0); |
| 1575 | } |
| 1576 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1577 | @Override |
| 1578 | protected int computeCurrentCountLocked() { |
| 1579 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1582 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1583 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1584 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1585 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1586 | if (mNesting > 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1587 | mUpdateTime = mTimeBase.getRealtime(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1588 | } |
| 1589 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1590 | return canDetach; |
| 1591 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1592 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1593 | @Override |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1594 | void detach() { |
| 1595 | super.detach(); |
| 1596 | if (mTimerPool != null) { |
| 1597 | mTimerPool.remove(this); |
| 1598 | } |
| 1599 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1600 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1601 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1603 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | mNesting = 0; |
| 1605 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1606 | |
| 1607 | /** |
| 1608 | * Set the mark so that we can query later for the total time the timer has |
| 1609 | * accumulated since this point. The timer can be running or not. |
| 1610 | * |
| 1611 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1612 | */ |
| 1613 | public void setMark(long elapsedRealtimeMs) { |
| 1614 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1615 | if (mNesting > 0) { |
| 1616 | // We are running. |
| 1617 | if (mTimerPool != null) { |
| 1618 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1619 | } else { |
| 1620 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1621 | mUpdateTime = batteryRealtime; |
| 1622 | } |
| 1623 | } |
| 1624 | mTimeBeforeMark = mTotalTime; |
| 1625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1627 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1628 | public abstract class OverflowArrayMap<T> { |
| 1629 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1630 | |
| 1631 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1632 | T mCurOverflow; |
| 1633 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1634 | |
| 1635 | public OverflowArrayMap() { |
| 1636 | } |
| 1637 | |
| 1638 | public ArrayMap<String, T> getMap() { |
| 1639 | return mMap; |
| 1640 | } |
| 1641 | |
| 1642 | public void clear() { |
| 1643 | mMap.clear(); |
| 1644 | mCurOverflow = null; |
| 1645 | mActiveOverflow = null; |
| 1646 | } |
| 1647 | |
| 1648 | public void add(String name, T obj) { |
| 1649 | mMap.put(name, obj); |
| 1650 | if (OVERFLOW_NAME.equals(name)) { |
| 1651 | mCurOverflow = obj; |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | public void cleanup() { |
| 1656 | if (mActiveOverflow != null) { |
| 1657 | if (mActiveOverflow.size() == 0) { |
| 1658 | mActiveOverflow = null; |
| 1659 | } |
| 1660 | } |
| 1661 | if (mActiveOverflow == null) { |
| 1662 | // There is no currently active overflow, so we should no longer have |
| 1663 | // an overflow entry. |
| 1664 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1665 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1666 | + mMap.get(OVERFLOW_NAME)); |
| 1667 | mMap.remove(OVERFLOW_NAME); |
| 1668 | } |
| 1669 | mCurOverflow = null; |
| 1670 | } else { |
| 1671 | // There is currently active overflow, so we should still have an overflow entry. |
| 1672 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1673 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1674 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | public T startObject(String name) { |
| 1680 | T obj = mMap.get(name); |
| 1681 | if (obj != null) { |
| 1682 | return obj; |
| 1683 | } |
| 1684 | |
| 1685 | // No object exists for the given name, but do we currently have it |
| 1686 | // running as part of the overflow? |
| 1687 | if (mActiveOverflow != null) { |
| 1688 | MutableInt over = mActiveOverflow.get(name); |
| 1689 | if (over != null) { |
| 1690 | // We are already actively counting this name in the overflow object. |
| 1691 | obj = mCurOverflow; |
| 1692 | if (obj == null) { |
| 1693 | // Shouldn't be here, but we'll try to recover. |
| 1694 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1695 | obj = mCurOverflow = instantiateObject(); |
| 1696 | mMap.put(OVERFLOW_NAME, obj); |
| 1697 | } |
| 1698 | over.value++; |
| 1699 | return obj; |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | // No object exists for given name nor in the overflow; we need to make |
| 1704 | // a new one. |
| 1705 | final int N = mMap.size(); |
| 1706 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1707 | // Went over the limit on number of objects to track; this one goes |
| 1708 | // in to the overflow. |
| 1709 | obj = mCurOverflow; |
| 1710 | if (obj == null) { |
| 1711 | // Need to start overflow now... |
| 1712 | obj = mCurOverflow = instantiateObject(); |
| 1713 | mMap.put(OVERFLOW_NAME, obj); |
| 1714 | } |
| 1715 | if (mActiveOverflow == null) { |
| 1716 | mActiveOverflow = new ArrayMap<>(); |
| 1717 | } |
| 1718 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1719 | return obj; |
| 1720 | } |
| 1721 | |
| 1722 | // Normal case where we just need to make a new object. |
| 1723 | obj = instantiateObject(); |
| 1724 | mMap.put(name, obj); |
| 1725 | return obj; |
| 1726 | } |
| 1727 | |
| 1728 | public T stopObject(String name) { |
| 1729 | T obj = mMap.get(name); |
| 1730 | if (obj != null) { |
| 1731 | return obj; |
| 1732 | } |
| 1733 | |
| 1734 | // No object exists for the given name, but do we currently have it |
| 1735 | // running as part of the overflow? |
| 1736 | if (mActiveOverflow != null) { |
| 1737 | MutableInt over = mActiveOverflow.get(name); |
| 1738 | if (over != null) { |
| 1739 | // We are already actively counting this name in the overflow object. |
| 1740 | obj = mCurOverflow; |
| 1741 | if (obj != null) { |
| 1742 | over.value--; |
| 1743 | if (over.value <= 0) { |
| 1744 | mActiveOverflow.remove(name); |
| 1745 | } |
| 1746 | return obj; |
| 1747 | } |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | // Huh, they are stopping an active operation but we can't find one! |
| 1752 | // That's not good. |
| 1753 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1754 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1755 | + " curoverflow=" + mCurOverflow); |
| 1756 | return null; |
| 1757 | } |
| 1758 | |
| 1759 | public abstract T instantiateObject(); |
| 1760 | } |
| 1761 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1762 | /* |
| 1763 | * Get the wakeup reason counter, and create a new one if one |
| 1764 | * doesn't already exist. |
| 1765 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1766 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 1767 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 1768 | if (timer == null) { |
| 1769 | timer = new SamplingTimer(mOnBatteryTimeBase, true); |
| 1770 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1771 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1772 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1775 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1776 | * 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] | 1777 | * doesn't already exist. |
| 1778 | */ |
| 1779 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1780 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1781 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1782 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1783 | mKernelWakelockStats.put(name, kwlt); |
| 1784 | } |
| 1785 | return kwlt; |
| 1786 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1787 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1788 | private int writeHistoryTag(HistoryTag tag) { |
| 1789 | Integer idxObj = mHistoryTagPool.get(tag); |
| 1790 | int idx; |
| 1791 | if (idxObj != null) { |
| 1792 | idx = idxObj; |
| 1793 | } else { |
| 1794 | idx = mNextHistoryTagIdx; |
| 1795 | HistoryTag key = new HistoryTag(); |
| 1796 | key.setTo(tag); |
| 1797 | tag.poolIdx = idx; |
| 1798 | mHistoryTagPool.put(key, idx); |
| 1799 | mNextHistoryTagIdx++; |
| 1800 | mNumHistoryTagChars += key.string.length() + 1; |
| 1801 | } |
| 1802 | return idx; |
| 1803 | } |
| 1804 | |
| 1805 | private void readHistoryTag(int index, HistoryTag tag) { |
| 1806 | tag.string = mReadHistoryStrings[index]; |
| 1807 | tag.uid = mReadHistoryUids[index]; |
| 1808 | tag.poolIdx = index; |
| 1809 | } |
| 1810 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1811 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1812 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 1813 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 1814 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 1815 | static final int DELTA_TIME_ABS = 0x7fffd; // Following is an entire abs update. |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1816 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1817 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1818 | // Flag in delta int: a new full state and battery status int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1819 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 1820 | // Flag in delta int: a new full state2 int follows. |
| 1821 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1822 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1823 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1824 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1825 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1826 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1827 | static final int DELTA_STATE_MASK = 0xff000000; |
| 1828 | |
| 1829 | // These are the pieces of battery state that are packed in to the upper bits of |
| 1830 | // the state int that have been packed in to the first delta int. They must fit |
| 1831 | // in DELTA_STATE_MASK. |
| 1832 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 1833 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 1834 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 1835 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 1836 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 1837 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1838 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1839 | // We use the low bit of the battery state int to indicate that we have full details |
| 1840 | // from a battery level change. |
| 1841 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 1842 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1843 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1844 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1845 | dest.writeInt(DELTA_TIME_ABS); |
| 1846 | cur.writeToParcel(dest, 0); |
| 1847 | return; |
| 1848 | } |
| 1849 | |
| 1850 | final long deltaTime = cur.time - last.time; |
| 1851 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 1852 | final int lastStateInt = buildStateInt(last); |
| 1853 | |
| 1854 | int deltaTimeToken; |
| 1855 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 1856 | deltaTimeToken = DELTA_TIME_LONG; |
| 1857 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 1858 | deltaTimeToken = DELTA_TIME_INT; |
| 1859 | } else { |
| 1860 | deltaTimeToken = (int)deltaTime; |
| 1861 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1862 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1863 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 1864 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 1865 | final boolean computeStepDetails = includeStepDetails != 0 |
| 1866 | || mLastHistoryStepDetails == null; |
| 1867 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1868 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 1869 | if (batteryLevelIntChanged) { |
| 1870 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 1871 | } |
| 1872 | final int stateInt = buildStateInt(cur); |
| 1873 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 1874 | if (stateIntChanged) { |
| 1875 | firstToken |= DELTA_STATE_FLAG; |
| 1876 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1877 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 1878 | if (state2IntChanged) { |
| 1879 | firstToken |= DELTA_STATE2_FLAG; |
| 1880 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1881 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1882 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 1883 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1884 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 1885 | firstToken |= DELTA_EVENT_FLAG; |
| 1886 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1887 | dest.writeInt(firstToken); |
| 1888 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1889 | + " deltaTime=" + deltaTime); |
| 1890 | |
| 1891 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 1892 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 1893 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 1894 | dest.writeInt((int)deltaTime); |
| 1895 | } else { |
| 1896 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 1897 | dest.writeLong(deltaTime); |
| 1898 | } |
| 1899 | } |
| 1900 | if (batteryLevelIntChanged) { |
| 1901 | dest.writeInt(batteryLevelInt); |
| 1902 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 1903 | + Integer.toHexString(batteryLevelInt) |
| 1904 | + " batteryLevel=" + cur.batteryLevel |
| 1905 | + " batteryTemp=" + cur.batteryTemperature |
| 1906 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1907 | } |
| 1908 | if (stateIntChanged) { |
| 1909 | dest.writeInt(stateInt); |
| 1910 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 1911 | + Integer.toHexString(stateInt) |
| 1912 | + " batteryStatus=" + cur.batteryStatus |
| 1913 | + " batteryHealth=" + cur.batteryHealth |
| 1914 | + " batteryPlugType=" + cur.batteryPlugType |
| 1915 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1916 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1917 | if (state2IntChanged) { |
| 1918 | dest.writeInt(cur.states2); |
| 1919 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 1920 | + Integer.toHexString(cur.states2)); |
| 1921 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1922 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 1923 | int wakeLockIndex; |
| 1924 | int wakeReasonIndex; |
| 1925 | if (cur.wakelockTag != null) { |
| 1926 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 1927 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1928 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1929 | } else { |
| 1930 | wakeLockIndex = 0xffff; |
| 1931 | } |
| 1932 | if (cur.wakeReasonTag != null) { |
| 1933 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 1934 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1935 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1936 | } else { |
| 1937 | wakeReasonIndex = 0xffff; |
| 1938 | } |
| 1939 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1940 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1941 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1942 | int index = writeHistoryTag(cur.eventTag); |
| 1943 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1944 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1945 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 1946 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 1947 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1948 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1949 | if (computeStepDetails) { |
| 1950 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 1951 | if (includeStepDetails != 0) { |
| 1952 | mCurHistoryStepDetails.writeToParcel(dest); |
| 1953 | } |
| 1954 | cur.stepDetails = mCurHistoryStepDetails; |
| 1955 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 1956 | } else { |
| 1957 | cur.stepDetails = null; |
| 1958 | } |
| 1959 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 1960 | mLastHistoryStepDetails = null; |
| 1961 | } |
| 1962 | mLastHistoryStepLevel = cur.batteryLevel; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | private int buildBatteryLevelInt(HistoryItem h) { |
| 1966 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1967 | | ((((int)h.batteryTemperature)<<14)&0x01ff8000) |
| 1968 | | ((((int)h.batteryVoltage)<<1)&0x00007fff); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1972 | int plugType = 0; |
| 1973 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 1974 | plugType = 1; |
| 1975 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 1976 | plugType = 2; |
| 1977 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 1978 | plugType = 3; |
| 1979 | } |
| 1980 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 1981 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 1982 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1983 | | (h.states&(~DELTA_STATE_MASK)); |
| 1984 | } |
| 1985 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1986 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 1987 | final HistoryStepDetails last) { |
| 1988 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 1989 | |
| 1990 | // Perform a CPU update right after we do this collection, so we have started |
| 1991 | // collecting good data for the next step. |
| 1992 | requestImmediateCpuUpdate(); |
| 1993 | |
| 1994 | if (last == null) { |
| 1995 | // We are not generating a delta, so all we need to do is reset the stats |
| 1996 | // we will later be doing a delta from. |
| 1997 | final int NU = mUidStats.size(); |
| 1998 | for (int i=0; i<NU; i++) { |
| 1999 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2000 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2001 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2002 | } |
| 2003 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2004 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2005 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2006 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2007 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2008 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2009 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2010 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2011 | tmp.clear(); |
| 2012 | return; |
| 2013 | } |
| 2014 | if (DEBUG) { |
| 2015 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2016 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2017 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2018 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2019 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2020 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2021 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2022 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2023 | } |
| 2024 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2025 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2026 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2027 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2028 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2029 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2030 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2031 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2032 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2033 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2034 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2035 | final int NU = mUidStats.size(); |
| 2036 | for (int i=0; i<NU; i++) { |
| 2037 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2038 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2039 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2040 | final int totalTime = totalUTime + totalSTime; |
| 2041 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2042 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2043 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2044 | continue; |
| 2045 | } |
| 2046 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2047 | out.appCpuUid3 = uid.mUid; |
| 2048 | out.appCpuUTime3 = totalUTime; |
| 2049 | out.appCpuSTime3 = totalSTime; |
| 2050 | } else { |
| 2051 | out.appCpuUid3 = out.appCpuUid2; |
| 2052 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2053 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2054 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2055 | out.appCpuUid2 = uid.mUid; |
| 2056 | out.appCpuUTime2 = totalUTime; |
| 2057 | out.appCpuSTime2 = totalSTime; |
| 2058 | } else { |
| 2059 | out.appCpuUid2 = out.appCpuUid1; |
| 2060 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2061 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2062 | out.appCpuUid1 = uid.mUid; |
| 2063 | out.appCpuUTime1 = totalUTime; |
| 2064 | out.appCpuSTime1 = totalSTime; |
| 2065 | } |
| 2066 | } |
| 2067 | } |
| 2068 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2069 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2070 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2071 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2072 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2073 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2074 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2075 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2076 | } |
| 2077 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2078 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2079 | int firstToken = src.readInt(); |
| 2080 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2081 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2082 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2083 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2084 | + " deltaTimeToken=" + deltaTimeToken); |
| 2085 | |
| 2086 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2087 | cur.time += deltaTimeToken; |
| 2088 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2089 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2090 | cur.numReadInts += 2; |
| 2091 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2092 | cur.readFromParcel(src); |
| 2093 | return; |
| 2094 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2095 | int delta = src.readInt(); |
| 2096 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2097 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2098 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2099 | } else { |
| 2100 | long delta = src.readLong(); |
| 2101 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2102 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2103 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2104 | } |
| 2105 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2106 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2107 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2108 | batteryLevelInt = src.readInt(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2109 | cur.batteryLevel = (byte)((batteryLevelInt>>25)&0x7f); |
| 2110 | cur.batteryTemperature = (short)((batteryLevelInt<<7)>>21); |
| 2111 | cur.batteryVoltage = (char)(batteryLevelInt&0x3fff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2112 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2113 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2114 | + Integer.toHexString(batteryLevelInt) |
| 2115 | + " batteryLevel=" + cur.batteryLevel |
| 2116 | + " batteryTemp=" + cur.batteryTemperature |
| 2117 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2118 | } else { |
| 2119 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2123 | int stateInt = src.readInt(); |
| 2124 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2125 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2126 | & STATE_BATTERY_STATUS_MASK); |
| 2127 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2128 | & STATE_BATTERY_HEALTH_MASK); |
| 2129 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2130 | & STATE_BATTERY_PLUG_MASK); |
| 2131 | switch (cur.batteryPlugType) { |
| 2132 | case 1: |
| 2133 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2134 | break; |
| 2135 | case 2: |
| 2136 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2137 | break; |
| 2138 | case 3: |
| 2139 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2140 | break; |
| 2141 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2142 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2143 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2144 | + Integer.toHexString(stateInt) |
| 2145 | + " batteryStatus=" + cur.batteryStatus |
| 2146 | + " batteryHealth=" + cur.batteryHealth |
| 2147 | + " batteryPlugType=" + cur.batteryPlugType |
| 2148 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2149 | } else { |
| 2150 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 2151 | } |
| 2152 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2153 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2154 | cur.states2 = src.readInt(); |
| 2155 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2156 | + Integer.toHexString(cur.states2)); |
| 2157 | } |
| 2158 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2159 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2160 | int indexes = src.readInt(); |
| 2161 | int wakeLockIndex = indexes&0xffff; |
| 2162 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2163 | if (wakeLockIndex != 0xffff) { |
| 2164 | cur.wakelockTag = cur.localWakelockTag; |
| 2165 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2166 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2167 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2168 | } else { |
| 2169 | cur.wakelockTag = null; |
| 2170 | } |
| 2171 | if (wakeReasonIndex != 0xffff) { |
| 2172 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2173 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2174 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2175 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2176 | } else { |
| 2177 | cur.wakeReasonTag = null; |
| 2178 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2179 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2180 | } else { |
| 2181 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2182 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2183 | } |
| 2184 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2185 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2186 | cur.eventTag = cur.localEventTag; |
| 2187 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2188 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2189 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2190 | readHistoryTag(index, cur.eventTag); |
| 2191 | cur.numReadInts += 1; |
| 2192 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2193 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2194 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2195 | } else { |
| 2196 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2197 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2198 | |
| 2199 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2200 | cur.stepDetails = mReadHistoryStepDetails; |
| 2201 | cur.stepDetails.readFromParcel(src); |
| 2202 | } else { |
| 2203 | cur.stepDetails = null; |
| 2204 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2207 | @Override |
| 2208 | public void commitCurrentHistoryBatchLocked() { |
| 2209 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2210 | } |
| 2211 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2212 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2213 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2214 | return; |
| 2215 | } |
| 2216 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2217 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2218 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2219 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2220 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2221 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2222 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2223 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2224 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2225 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2226 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2227 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2228 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2229 | && (diffStates2&lastDiffStates2) == 0 |
| 2230 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2231 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2232 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2233 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2234 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2235 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2236 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2237 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2238 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2239 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2240 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2241 | // We can merge this new change in with the last one. Merging is |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2242 | // allowed as long as only the states have changed, and within those states |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2243 | // as long as no bit has changed both between now and the last entry, as |
| 2244 | // well as the last entry and the one before it (so we capture any toggles). |
| 2245 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2246 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2247 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2248 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2249 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2250 | // If the last written history had a wakelock tag, we need to retain it. |
| 2251 | // Note that the condition above made sure that we aren't in a case where |
| 2252 | // both it and the current history item have a wakelock tag. |
| 2253 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2254 | cur.wakelockTag = cur.localWakelockTag; |
| 2255 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2256 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2257 | // If the last written history had a wake reason tag, we need to retain it. |
| 2258 | // Note that the condition above made sure that we aren't in a case where |
| 2259 | // both it and the current history item have a wakelock tag. |
| 2260 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2261 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2262 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2263 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2264 | // If the last written history had an event, we need to retain it. |
| 2265 | // Note that the condition above made sure that we aren't in a case where |
| 2266 | // both it and the current history item have an event. |
| 2267 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2268 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2269 | cur.eventTag = cur.localEventTag; |
| 2270 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2271 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2272 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2276 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2277 | if (!mHistoryOverflow) { |
| 2278 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2279 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2280 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2281 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2284 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2285 | boolean writeAnyway = false; |
| 2286 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2287 | & mActiveHistoryStates; |
| 2288 | if (mHistoryLastWritten.states != curStates) { |
| 2289 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2290 | // forced to 0. |
| 2291 | int old = mActiveHistoryStates; |
| 2292 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2293 | writeAnyway |= old != mActiveHistoryStates; |
| 2294 | } |
| 2295 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2296 | & mActiveHistoryStates2; |
| 2297 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2298 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2299 | // forced to 0. |
| 2300 | int old = mActiveHistoryStates2; |
| 2301 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2302 | writeAnyway |= old != mActiveHistoryStates2; |
| 2303 | } |
| 2304 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2305 | // Once we've reached the maximum number of items, we only |
| 2306 | // record changes to the battery level and the most interesting states. |
| 2307 | // Once we've reached the maximum maximum number of items, we only |
| 2308 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2309 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2310 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2311 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2312 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2313 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2314 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2315 | return; |
| 2316 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2317 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2318 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2319 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2322 | if (dataSize == 0) { |
| 2323 | // The history is currently empty; we need it to start with a time stamp. |
| 2324 | cur.currentTime = System.currentTimeMillis(); |
| 2325 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2326 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2327 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2330 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2331 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2332 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2333 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2334 | } |
| 2335 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2336 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2337 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2338 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2339 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2340 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2341 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2342 | cur.wakelockTag = null; |
| 2343 | cur.wakeReasonTag = null; |
| 2344 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2345 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2346 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2347 | + " now " + mHistoryBuffer.dataPosition() |
| 2348 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2351 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2352 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2353 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2354 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2355 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2356 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2357 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2358 | if (diffUptime < (diffElapsed-20)) { |
| 2359 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2360 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2361 | mHistoryAddTmp.wakelockTag = null; |
| 2362 | mHistoryAddTmp.wakeReasonTag = null; |
| 2363 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2364 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2365 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2366 | } |
| 2367 | } |
| 2368 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2369 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2370 | mTrackRunningHistoryUptime = uptimeMs; |
| 2371 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2372 | } |
| 2373 | |
| 2374 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2375 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2376 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2377 | if (!USE_OLD_HISTORY) { |
| 2378 | return; |
| 2379 | } |
| 2380 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2381 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2382 | return; |
| 2383 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2384 | |
| 2385 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2386 | // and no states have since the last recorded entry changed and |
| 2387 | // are now resetting back to their original value, then just collapse |
| 2388 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2389 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2390 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2391 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2392 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2393 | // If the current is the same as the one before, then we no |
| 2394 | // longer need the entry. |
| 2395 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2396 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2397 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2398 | mHistoryLastEnd.next = null; |
| 2399 | mHistoryEnd.next = mHistoryCache; |
| 2400 | mHistoryCache = mHistoryEnd; |
| 2401 | mHistoryEnd = mHistoryLastEnd; |
| 2402 | mHistoryLastEnd = null; |
| 2403 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2404 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2405 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2406 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2407 | } |
| 2408 | return; |
| 2409 | } |
| 2410 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2411 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2412 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2413 | |
| 2414 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2415 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2416 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2419 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2420 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2421 | // record changes to the battery level and the most interesting states. |
| 2422 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2423 | // record changes to the battery level. |
| 2424 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2425 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2426 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2427 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2428 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2429 | return; |
| 2430 | } |
| 2431 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2432 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2433 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2434 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2435 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2436 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2437 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2438 | mHistoryCur.eventCode = code; |
| 2439 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2440 | mHistoryCur.eventTag.string = name; |
| 2441 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2442 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2443 | } |
| 2444 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2445 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2446 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2447 | if (rec != null) { |
| 2448 | mHistoryCache = rec.next; |
| 2449 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2450 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2451 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2452 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2453 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2454 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2455 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2456 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2457 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2458 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2459 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2460 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2461 | if (mHistoryEnd != null) { |
| 2462 | mHistoryEnd.next = rec; |
| 2463 | mHistoryEnd = rec; |
| 2464 | } else { |
| 2465 | mHistory = mHistoryEnd = rec; |
| 2466 | } |
| 2467 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2468 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2469 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2470 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2471 | if (USE_OLD_HISTORY) { |
| 2472 | if (mHistory != null) { |
| 2473 | mHistoryEnd.next = mHistoryCache; |
| 2474 | mHistoryCache = mHistory; |
| 2475 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2476 | } |
| 2477 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2478 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2479 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2480 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2481 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2482 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2483 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2484 | |
| 2485 | mHistoryBuffer.setDataSize(0); |
| 2486 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2487 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2488 | mHistoryLastLastWritten.clear(); |
| 2489 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2490 | mHistoryTagPool.clear(); |
| 2491 | mNextHistoryTagIdx = 0; |
| 2492 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2493 | mHistoryBufferLastPos = -1; |
| 2494 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2495 | mActiveHistoryStates = 0xffffffff; |
| 2496 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2497 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2498 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2499 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2500 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2501 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2502 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2503 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2504 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2505 | updateKernelWakelocksLocked(); |
| 2506 | requestWakelockCpuUpdate(); |
| 2507 | if (!unpluggedScreenOff) { |
| 2508 | // We are switching to no longer tracking wake locks, but we want |
| 2509 | // the next CPU update we receive to take them in to account. |
| 2510 | mDistributeWakelockCpu = true; |
| 2511 | } |
| 2512 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | } |
| 2514 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2515 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2516 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2517 | mIsolatedUids.put(isolatedUid, appUid); |
| 2518 | } |
| 2519 | |
| 2520 | public void removeIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2521 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2522 | if (curUid == appUid) { |
| 2523 | mIsolatedUids.delete(isolatedUid); |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | public int mapUid(int uid) { |
| 2528 | int isolated = mIsolatedUids.get(uid, -1); |
| 2529 | return isolated > 0 ? isolated : uid; |
| 2530 | } |
| 2531 | |
| 2532 | public void noteEventLocked(int code, String name, int uid) { |
| 2533 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2534 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2535 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2536 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2537 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2538 | final long uptime = SystemClock.uptimeMillis(); |
| 2539 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2540 | } |
| 2541 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2542 | public void noteCurrentTimeChangedLocked() { |
| 2543 | final long currentTime = System.currentTimeMillis(); |
| 2544 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2545 | final long uptime = SystemClock.uptimeMillis(); |
| 2546 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
| 2547 | if (isStartClockTimeValid()) { |
| 2548 | mStartClockTime = currentTime; |
| 2549 | } |
| 2550 | } |
| 2551 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2552 | public void noteProcessStartLocked(String name, int uid) { |
| 2553 | uid = mapUid(uid); |
| 2554 | if (isOnBattery()) { |
| 2555 | Uid u = getUidStatsLocked(uid); |
| 2556 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2557 | } |
| 2558 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2559 | return; |
| 2560 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2561 | if (!mRecordAllHistory) { |
| 2562 | return; |
| 2563 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2564 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2565 | final long uptime = SystemClock.uptimeMillis(); |
| 2566 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2567 | } |
| 2568 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2569 | public void noteProcessCrashLocked(String name, int uid) { |
| 2570 | uid = mapUid(uid); |
| 2571 | if (isOnBattery()) { |
| 2572 | Uid u = getUidStatsLocked(uid); |
| 2573 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | public void noteProcessAnrLocked(String name, int uid) { |
| 2578 | uid = mapUid(uid); |
| 2579 | if (isOnBattery()) { |
| 2580 | Uid u = getUidStatsLocked(uid); |
| 2581 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2582 | } |
| 2583 | } |
| 2584 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2585 | public void noteProcessStateLocked(String name, int uid, int state) { |
| 2586 | uid = mapUid(uid); |
| 2587 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2588 | getUidStatsLocked(uid).updateProcessStateLocked(name, state, elapsedRealtime); |
| 2589 | } |
| 2590 | |
| 2591 | public void noteProcessFinishLocked(String name, int uid) { |
| 2592 | uid = mapUid(uid); |
| 2593 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2594 | return; |
| 2595 | } |
| 2596 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2597 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2598 | getUidStatsLocked(uid).updateProcessStateLocked(name, Uid.PROCESS_STATE_NONE, |
| 2599 | elapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2600 | if (!mRecordAllHistory) { |
| 2601 | return; |
| 2602 | } |
| 2603 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2606 | public void noteSyncStartLocked(String name, int uid) { |
| 2607 | uid = mapUid(uid); |
| 2608 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2609 | final long uptime = SystemClock.uptimeMillis(); |
| 2610 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2611 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2612 | return; |
| 2613 | } |
| 2614 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2615 | } |
| 2616 | |
| 2617 | public void noteSyncFinishLocked(String name, int uid) { |
| 2618 | uid = mapUid(uid); |
| 2619 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2620 | final long uptime = SystemClock.uptimeMillis(); |
| 2621 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2622 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2623 | return; |
| 2624 | } |
| 2625 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2626 | } |
| 2627 | |
| 2628 | public void noteJobStartLocked(String name, int uid) { |
| 2629 | uid = mapUid(uid); |
| 2630 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2631 | final long uptime = SystemClock.uptimeMillis(); |
| 2632 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2633 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2634 | return; |
| 2635 | } |
| 2636 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2637 | } |
| 2638 | |
| 2639 | public void noteJobFinishLocked(String name, int uid) { |
| 2640 | uid = mapUid(uid); |
| 2641 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2642 | final long uptime = SystemClock.uptimeMillis(); |
| 2643 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2644 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2645 | return; |
| 2646 | } |
| 2647 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2648 | } |
| 2649 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2650 | public void noteAlarmStartLocked(String name, int uid) { |
| 2651 | if (!mRecordAllHistory) { |
| 2652 | return; |
| 2653 | } |
| 2654 | uid = mapUid(uid); |
| 2655 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2656 | final long uptime = SystemClock.uptimeMillis(); |
| 2657 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 2658 | return; |
| 2659 | } |
| 2660 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 2661 | } |
| 2662 | |
| 2663 | public void noteAlarmFinishLocked(String name, int uid) { |
| 2664 | if (!mRecordAllHistory) { |
| 2665 | return; |
| 2666 | } |
| 2667 | uid = mapUid(uid); |
| 2668 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2669 | final long uptime = SystemClock.uptimeMillis(); |
| 2670 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 2671 | return; |
| 2672 | } |
| 2673 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 2674 | } |
| 2675 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2676 | private void requestWakelockCpuUpdate() { |
| 2677 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2678 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2679 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2680 | } |
| 2681 | } |
| 2682 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2683 | private void requestImmediateCpuUpdate() { |
| 2684 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2685 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 2686 | } |
| 2687 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2688 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 2689 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2690 | if (!enabled) { |
| 2691 | // Clear out any existing state. |
| 2692 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2693 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2694 | // Record the currently running processes as stopping, now that we are no |
| 2695 | // longer tracking them. |
| 2696 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2697 | HistoryItem.EVENT_PROC); |
| 2698 | if (active != null) { |
| 2699 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2700 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2701 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2702 | SparseIntArray uids = ent.getValue(); |
| 2703 | for (int j=0; j<uids.size(); j++) { |
| 2704 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2705 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 2706 | } |
| 2707 | } |
| 2708 | } |
| 2709 | } else { |
| 2710 | // Record the currently running processes as starting, now that we are tracking them. |
| 2711 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2712 | HistoryItem.EVENT_PROC); |
| 2713 | if (active != null) { |
| 2714 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2715 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2716 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2717 | SparseIntArray uids = ent.getValue(); |
| 2718 | for (int j=0; j<uids.size(); j++) { |
| 2719 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2720 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 2721 | } |
| 2722 | } |
| 2723 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2727 | public void setNoAutoReset(boolean enabled) { |
| 2728 | mNoAutoReset = enabled; |
| 2729 | } |
| 2730 | |
| 2731 | private String mInitialAcquireWakeName; |
| 2732 | private int mInitialAcquireWakeUid = -1; |
| 2733 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2734 | public void noteStartWakeLocked(int uid, int pid, String name, String historyName, int type, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2735 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2736 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2737 | if (type == WAKE_TYPE_PARTIAL) { |
| 2738 | // Only care about partial wake locks, since full wake locks |
| 2739 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2740 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2741 | if (historyName == null) { |
| 2742 | historyName = name; |
| 2743 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2744 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2745 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 2746 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2747 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2748 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2749 | } |
| 2750 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2751 | if (mWakeLockNesting == 0) { |
| 2752 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2753 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 2754 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2755 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2756 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2757 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2758 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2759 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2760 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 2761 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2762 | if (mHistoryLastWritten.wakelockTag != null) { |
| 2763 | // We'll try to update the last tag. |
| 2764 | mHistoryLastWritten.wakelockTag = null; |
| 2765 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2766 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2767 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2768 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2769 | } |
| 2770 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2771 | } |
| 2772 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2773 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2774 | if (uid >= 0) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2775 | //if (uid == 0) { |
| 2776 | // Slog.wtf(TAG, "Acquiring wake lock from root: " + name); |
| 2777 | //} |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2778 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2779 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2780 | } |
| 2781 | } |
| 2782 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2783 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 2784 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2785 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2786 | if (type == WAKE_TYPE_PARTIAL) { |
| 2787 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2788 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2789 | if (historyName == null) { |
| 2790 | historyName = name; |
| 2791 | } |
| 2792 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 2793 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2794 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2795 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2796 | } |
| 2797 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2798 | if (mWakeLockNesting == 0) { |
| 2799 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2800 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 2801 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2802 | mInitialAcquireWakeName = null; |
| 2803 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2804 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2805 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2806 | } |
| 2807 | if (uid >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2808 | requestWakelockCpuUpdate(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2809 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2813 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2814 | String historyName, int type, boolean unimportantForLogging) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2815 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2816 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2817 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2818 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2819 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2820 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2824 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 2825 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2826 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
| 2827 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2828 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2829 | // For correct semantics, we start the need worksources first, so that we won't |
| 2830 | // make inappropriate history items as if all wake locks went away and new ones |
| 2831 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2832 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2833 | for (int i=0; i<NN; i++) { |
| 2834 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2835 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2836 | } |
| 2837 | final int NO = ws.size(); |
| 2838 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2839 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2843 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2844 | String historyName, int type) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2845 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2846 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2847 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2848 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2849 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2853 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 2854 | if (mLastWakeupReason != null) { |
| 2855 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2856 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
| 2857 | timer.addCurrentReportedCount(1); |
| 2858 | timer.addCurrentReportedTotalTime(deltaUptime * 1000); // time is in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2859 | mLastWakeupReason = null; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | public void noteWakeupReasonLocked(String reason) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2864 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2865 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2866 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2867 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2868 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2869 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 2870 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2871 | mHistoryCur.wakeReasonTag.uid = 0; |
| 2872 | mLastWakeupReason = reason; |
| 2873 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2874 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2875 | } |
| 2876 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2877 | public int startAddingCpuLocked() { |
| 2878 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2879 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2880 | if (!mOnBatteryInternal) { |
| 2881 | return -1; |
| 2882 | } |
| 2883 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2884 | final int N = mPartialTimers.size(); |
| 2885 | if (N == 0) { |
| 2886 | mLastPartialTimers.clear(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2887 | mDistributeWakelockCpu = false; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2888 | return 0; |
| 2889 | } |
| 2890 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2891 | if (!mOnBatteryScreenOffTimeBase.isRunning() && !mDistributeWakelockCpu) { |
| 2892 | return 0; |
| 2893 | } |
| 2894 | |
| 2895 | mDistributeWakelockCpu = false; |
| 2896 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2897 | // How many timers should consume CPU? Only want to include ones |
| 2898 | // that have already been in the list. |
| 2899 | for (int i=0; i<N; i++) { |
| 2900 | StopwatchTimer st = mPartialTimers.get(i); |
| 2901 | if (st.mInList) { |
| 2902 | Uid uid = st.mUid; |
| 2903 | // We don't include the system UID, because it so often |
| 2904 | // holds wake locks at one request or another of an app. |
| 2905 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2906 | return 50; |
| 2907 | } |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | return 0; |
| 2912 | } |
| 2913 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2914 | public void finishAddingCpuLocked(int perc, int remainUTime, int remainSTtime, |
| 2915 | int totalUTime, int totalSTime, int statUserTime, int statSystemTime, |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 2916 | int statIOWaitTime, int statIrqTime, int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2917 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 2918 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 2919 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 2920 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 2921 | mCurStepCpuUserTime += totalUTime; |
| 2922 | mCurStepCpuSystemTime += totalSTime; |
| 2923 | mCurStepStatUserTime += statUserTime; |
| 2924 | mCurStepStatSystemTime += statSystemTime; |
| 2925 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 2926 | mCurStepStatIrqTime += statIrqTime; |
| 2927 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 2928 | mCurStepStatIdleTime += statIdleTime; |
| 2929 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2930 | final int N = mPartialTimers.size(); |
| 2931 | if (perc != 0) { |
| 2932 | int num = 0; |
| 2933 | for (int i=0; i<N; i++) { |
| 2934 | StopwatchTimer st = mPartialTimers.get(i); |
| 2935 | if (st.mInList) { |
| 2936 | Uid uid = st.mUid; |
| 2937 | // We don't include the system UID, because it so often |
| 2938 | // holds wake locks at one request or another of an app. |
| 2939 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
| 2940 | num++; |
| 2941 | } |
| 2942 | } |
| 2943 | } |
| 2944 | if (num != 0) { |
| 2945 | for (int i=0; i<N; i++) { |
| 2946 | StopwatchTimer st = mPartialTimers.get(i); |
| 2947 | if (st.mInList) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2948 | Uid uid = st.mUid; |
| 2949 | if (uid != null && uid.mUid != Process.SYSTEM_UID) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2950 | int myUTime = remainUTime/num; |
| 2951 | int mySTime = remainSTtime/num; |
| 2952 | remainUTime -= myUTime; |
| 2953 | remainSTtime -= mySTime; |
Dianne Hackborn | 618b8c1 | 2010-09-09 23:10:38 -0700 | [diff] [blame] | 2954 | num--; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2955 | Uid.Proc proc = uid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 2956 | proc.addCpuTimeLocked(myUTime, mySTime); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | // Just in case, collect any lost CPU time. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2963 | if (remainUTime != 0 || remainSTtime != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2964 | Uid uid = getUidStatsLocked(Process.SYSTEM_UID); |
| 2965 | if (uid != null) { |
| 2966 | Uid.Proc proc = uid.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 2967 | proc.addCpuTimeLocked(remainUTime, remainSTtime); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | final int NL = mLastPartialTimers.size(); |
| 2973 | boolean diff = N != NL; |
| 2974 | for (int i=0; i<NL && !diff; i++) { |
| 2975 | diff |= mPartialTimers.get(i) != mLastPartialTimers.get(i); |
| 2976 | } |
| 2977 | if (!diff) { |
| 2978 | for (int i=0; i<NL; i++) { |
| 2979 | mPartialTimers.get(i).mInList = true; |
| 2980 | } |
| 2981 | return; |
| 2982 | } |
| 2983 | |
| 2984 | for (int i=0; i<NL; i++) { |
| 2985 | mLastPartialTimers.get(i).mInList = false; |
| 2986 | } |
| 2987 | mLastPartialTimers.clear(); |
| 2988 | for (int i=0; i<N; i++) { |
| 2989 | StopwatchTimer st = mPartialTimers.get(i); |
| 2990 | st.mInList = true; |
| 2991 | mLastPartialTimers.add(st); |
| 2992 | } |
| 2993 | } |
| 2994 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2995 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2996 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2997 | Uid u = mUidStats.get(uid); |
| 2998 | if (u != null) { |
| 2999 | u.mPids.remove(pid); |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3004 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3005 | Uid u = mUidStats.get(uid); |
| 3006 | if (u != null) { |
| 3007 | Uid.Pid p = u.mPids.get(pid); |
| 3008 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3009 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3010 | } |
| 3011 | } |
| 3012 | return 0; |
| 3013 | } |
| 3014 | |
| 3015 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3016 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3017 | Uid u = mUidStats.get(uid); |
| 3018 | if (u != null) { |
| 3019 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3020 | } |
| 3021 | } |
| 3022 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3023 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3024 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3025 | Uid u = mUidStats.get(uid); |
| 3026 | if (u != null) { |
| 3027 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3028 | } |
| 3029 | } |
| 3030 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3031 | int mSensorNesting; |
| 3032 | |
| 3033 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3034 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3035 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3036 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3037 | if (mSensorNesting == 0) { |
| 3038 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3039 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3040 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3041 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3042 | } |
| 3043 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3044 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3048 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3049 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3050 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3051 | mSensorNesting--; |
| 3052 | if (mSensorNesting == 0) { |
| 3053 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3054 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3055 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3056 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3057 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3058 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3061 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3062 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3063 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3064 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3065 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3066 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3067 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3068 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3069 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3070 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3071 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3072 | } |
| 3073 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3074 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3076 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3077 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3078 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3079 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3080 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3081 | mGpsNesting--; |
| 3082 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3083 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3084 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3085 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3086 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3087 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3088 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3090 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3091 | public void noteScreenStateLocked(int state) { |
| 3092 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3093 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3094 | final int oldState = mScreenState; |
| 3095 | mScreenState = state; |
| 3096 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3097 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3098 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3099 | if (state != Display.STATE_UNKNOWN) { |
| 3100 | int stepState = state-1; |
| 3101 | if (stepState < 4) { |
| 3102 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3103 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3104 | } else { |
| 3105 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3106 | } |
| 3107 | } |
| 3108 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3109 | if (state == Display.STATE_ON) { |
| 3110 | // Screen turning on. |
| 3111 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3112 | final long uptime = SystemClock.uptimeMillis(); |
| 3113 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3114 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3115 | + Integer.toHexString(mHistoryCur.states)); |
| 3116 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3117 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3118 | if (mScreenBrightnessBin >= 0) { |
| 3119 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3120 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3121 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3122 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
| 3123 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3124 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3125 | // Fake a wake lock, so we consider the device waked as long |
| 3126 | // as the screen is on. |
| 3127 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3128 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3129 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3130 | // Update discharge amounts. |
| 3131 | if (mOnBatteryInternal) { |
| 3132 | updateDischargeScreenLevelsLocked(false, true); |
| 3133 | } |
| 3134 | } else if (oldState == Display.STATE_ON) { |
| 3135 | // Screen turning off or dozing. |
| 3136 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3137 | final long uptime = SystemClock.uptimeMillis(); |
| 3138 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3139 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3140 | + Integer.toHexString(mHistoryCur.states)); |
| 3141 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3142 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3143 | if (mScreenBrightnessBin >= 0) { |
| 3144 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3145 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3146 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3147 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3148 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3149 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3150 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
| 3151 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3152 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3153 | // Update discharge amounts. |
| 3154 | if (mOnBatteryInternal) { |
| 3155 | updateDischargeScreenLevelsLocked(true, false); |
| 3156 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3157 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3158 | } |
| 3159 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3160 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3161 | public void noteScreenBrightnessLocked(int brightness) { |
| 3162 | // Bin the brightness. |
| 3163 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3164 | if (bin < 0) bin = 0; |
| 3165 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3166 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3167 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3168 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3169 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3170 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3171 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3172 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3173 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3174 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3175 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3176 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3177 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3178 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3179 | } |
| 3180 | mScreenBrightnessBin = bin; |
| 3181 | } |
| 3182 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3183 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3184 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3185 | if (mOnBatteryInternal) { |
| 3186 | uid = mapUid(uid); |
| 3187 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3188 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3190 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3191 | public void noteInteractiveLocked(boolean interactive) { |
| 3192 | if (mInteractive != interactive) { |
| 3193 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3194 | mInteractive = interactive; |
| 3195 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3196 | if (interactive) { |
| 3197 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3198 | } else { |
| 3199 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3200 | } |
| 3201 | } |
| 3202 | } |
| 3203 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3204 | public void noteConnectivityChangedLocked(int type, String extra) { |
| 3205 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3206 | final long uptime = SystemClock.uptimeMillis(); |
| 3207 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3208 | extra, type); |
| 3209 | mNumConnectivityChange++; |
| 3210 | } |
| 3211 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3212 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
| 3213 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3214 | final long uptime = SystemClock.uptimeMillis(); |
| 3215 | if (mMobileRadioPowerState != powerState) { |
| 3216 | long realElapsedRealtimeMs; |
| 3217 | final boolean active = |
| 3218 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3219 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3220 | if (active) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3221 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3222 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3223 | } else { |
| 3224 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3225 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3226 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3227 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3228 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3229 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3230 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3231 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3232 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3233 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3234 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3235 | } |
| 3236 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3237 | + Integer.toHexString(mHistoryCur.states)); |
| 3238 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3239 | mMobileRadioPowerState = powerState; |
| 3240 | if (active) { |
| 3241 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3242 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3243 | } else { |
| 3244 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3245 | updateMobileRadioStateLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3246 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3247 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3248 | } |
| 3249 | } |
| 3250 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3251 | public void notePowerSaveMode(boolean enabled) { |
| 3252 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3253 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3254 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3255 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3256 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3257 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3258 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3259 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3260 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3261 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3262 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3263 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3264 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3265 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3266 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3267 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3268 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3269 | } |
| 3270 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3271 | } |
| 3272 | } |
| 3273 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3274 | public void noteDeviceIdleModeLocked(boolean enabled, boolean fromActive, boolean fromMotion) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3275 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3276 | final long uptime = SystemClock.uptimeMillis(); |
| 3277 | boolean nowIdling = enabled; |
| 3278 | if (mDeviceIdling && !enabled && !fromActive && !fromMotion) { |
| 3279 | // We don't go out of general idling mode until explicitly taken out of |
| 3280 | // device idle through going active or significant motion. |
| 3281 | nowIdling = true; |
| 3282 | } |
| 3283 | if (mDeviceIdling != nowIdling) { |
| 3284 | mDeviceIdling = nowIdling; |
| 3285 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3286 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3287 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
| 3288 | if (enabled) { |
| 3289 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3290 | } else { |
| 3291 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3292 | } |
| 3293 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3294 | if (mDeviceIdleModeEnabled != enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3295 | mDeviceIdleModeEnabled = enabled; |
| 3296 | if (fromMotion) { |
| 3297 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SIGNIFICANT_MOTION, |
| 3298 | "", 0); |
| 3299 | } |
| 3300 | if (fromActive) { |
| 3301 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3302 | "", 0); |
| 3303 | } |
| 3304 | if (enabled) { |
| 3305 | mHistoryCur.states2 |= HistoryItem.STATE2_DEVICE_IDLE_FLAG; |
| 3306 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode enabled to: " |
| 3307 | + Integer.toHexString(mHistoryCur.states2)); |
| 3308 | mDeviceIdleModeEnabledTimer.startRunningLocked(elapsedRealtime); |
| 3309 | } else { |
| 3310 | mHistoryCur.states2 &= ~HistoryItem.STATE2_DEVICE_IDLE_FLAG; |
| 3311 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode disabled to: " |
| 3312 | + Integer.toHexString(mHistoryCur.states2)); |
| 3313 | mDeviceIdleModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
| 3314 | } |
| 3315 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
| 3320 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3321 | final long uptime = SystemClock.uptimeMillis(); |
| 3322 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3323 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3324 | PackageChange pc = new PackageChange(); |
| 3325 | pc.mPackageName = pkgName; |
| 3326 | pc.mUpdate = true; |
| 3327 | pc.mVersionCode = versionCode; |
| 3328 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | public void notePackageUninstalledLocked(String pkgName) { |
| 3332 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3333 | final long uptime = SystemClock.uptimeMillis(); |
| 3334 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3335 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3336 | PackageChange pc = new PackageChange(); |
| 3337 | pc.mPackageName = pkgName; |
| 3338 | pc.mUpdate = true; |
| 3339 | addPackageChange(pc); |
| 3340 | } |
| 3341 | |
| 3342 | private void addPackageChange(PackageChange pc) { |
| 3343 | if (mDailyPackageChanges == null) { |
| 3344 | mDailyPackageChanges = new ArrayList<>(); |
| 3345 | } |
| 3346 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3347 | } |
| 3348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | public void notePhoneOnLocked() { |
| 3350 | if (!mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3351 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3352 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3353 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3354 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3355 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3356 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3357 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3358 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | } |
| 3360 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | public void notePhoneOffLocked() { |
| 3363 | if (mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3364 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3365 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3366 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3367 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3368 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3369 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3371 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | } |
| 3373 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3374 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3375 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3376 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3377 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3378 | if (i == except) { |
| 3379 | continue; |
| 3380 | } |
| 3381 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3382 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3383 | } |
| 3384 | } |
| 3385 | } |
| 3386 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3387 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3388 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3389 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3390 | // to infer that we are scanning from other data. |
| 3391 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3392 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3393 | state = ServiceState.STATE_IN_SERVICE; |
| 3394 | } |
| 3395 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3396 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3397 | return state; |
| 3398 | } |
| 3399 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3400 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3401 | boolean scanning = false; |
| 3402 | boolean newHistory = false; |
| 3403 | |
| 3404 | mPhoneServiceStateRaw = state; |
| 3405 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3406 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3407 | |
| 3408 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3409 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3410 | |
| 3411 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3412 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3413 | // to infer that we are scanning from other data. |
| 3414 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3415 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3416 | state = ServiceState.STATE_IN_SERVICE; |
| 3417 | } |
| 3418 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3419 | |
| 3420 | // If the phone is powered off, stop all timers. |
| 3421 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3422 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3423 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3424 | // If we are in service, make sure the correct signal string timer is running. |
| 3425 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3426 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3427 | |
| 3428 | // If we're out of service, we are in the lowest signal strength |
| 3429 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3430 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3431 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3432 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3433 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3434 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3435 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3436 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3437 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3438 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3439 | } |
| 3440 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3441 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3442 | if (!scanning) { |
| 3443 | // If we are no longer scanning, then stop the scanning timer. |
| 3444 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3445 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3446 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3447 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3448 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3449 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3453 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3454 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3455 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3456 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3457 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3458 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3459 | mPhoneServiceState = state; |
| 3460 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3461 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3462 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3463 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3464 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3465 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3466 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3467 | if (strengthBin >= 0) { |
| 3468 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3469 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3470 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3471 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3472 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3473 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3474 | + Integer.toHexString(mHistoryCur.states)); |
| 3475 | newHistory = true; |
| 3476 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3477 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3478 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3479 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3483 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | |
| 3487 | /** |
| 3488 | * Telephony stack updates the phone state. |
| 3489 | * @param state phone state from ServiceState.getState() |
| 3490 | */ |
| 3491 | public void notePhoneStateLocked(int state, int simState) { |
| 3492 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3495 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3496 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3497 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3498 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3499 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3500 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3501 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3502 | int bin = DATA_CONNECTION_NONE; |
| 3503 | if (hasData) { |
| 3504 | switch (dataType) { |
| 3505 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3506 | bin = DATA_CONNECTION_EDGE; |
| 3507 | break; |
| 3508 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3509 | bin = DATA_CONNECTION_GPRS; |
| 3510 | break; |
| 3511 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3512 | bin = DATA_CONNECTION_UMTS; |
| 3513 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3514 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3515 | bin = DATA_CONNECTION_CDMA; |
| 3516 | break; |
| 3517 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3518 | bin = DATA_CONNECTION_EVDO_0; |
| 3519 | break; |
| 3520 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3521 | bin = DATA_CONNECTION_EVDO_A; |
| 3522 | break; |
| 3523 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3524 | bin = DATA_CONNECTION_1xRTT; |
| 3525 | break; |
| 3526 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3527 | bin = DATA_CONNECTION_HSDPA; |
| 3528 | break; |
| 3529 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3530 | bin = DATA_CONNECTION_HSUPA; |
| 3531 | break; |
| 3532 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3533 | bin = DATA_CONNECTION_HSPA; |
| 3534 | break; |
| 3535 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3536 | bin = DATA_CONNECTION_IDEN; |
| 3537 | break; |
| 3538 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3539 | bin = DATA_CONNECTION_EVDO_B; |
| 3540 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3541 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3542 | bin = DATA_CONNECTION_LTE; |
| 3543 | break; |
| 3544 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3545 | bin = DATA_CONNECTION_EHRPD; |
| 3546 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3547 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3548 | bin = DATA_CONNECTION_HSPAP; |
| 3549 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3550 | default: |
| 3551 | bin = DATA_CONNECTION_OTHER; |
| 3552 | break; |
| 3553 | } |
| 3554 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3555 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3556 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3557 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3558 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3559 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3560 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3561 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3562 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3563 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3564 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3565 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3566 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3567 | } |
| 3568 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3569 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3570 | } |
| 3571 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3572 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3573 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3574 | if (!mWifiOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3575 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3576 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3577 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3578 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3579 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3580 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3581 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3582 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3583 | scheduleSyncExternalStatsLocked("wifi-off"); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3584 | } |
| 3585 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3586 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3587 | public void noteWifiOffLocked() { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3588 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3589 | final long uptime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3590 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3591 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3592 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3593 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3594 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3595 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3596 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3597 | scheduleSyncExternalStatsLocked("wifi-on"); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3598 | } |
| 3599 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3600 | |
| 3601 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3602 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3603 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3604 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3605 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3606 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3607 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3608 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3609 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3610 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3611 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3612 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3613 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3614 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3615 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3616 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3617 | if (mAudioOnNesting == 0) { |
| 3618 | return; |
| 3619 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3620 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3621 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3622 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3623 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3624 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3625 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3626 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3627 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3628 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3629 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3630 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3634 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3635 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3636 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3637 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3638 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3639 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3640 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3641 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3642 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3643 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3644 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3645 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3646 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3647 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3648 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3649 | if (mVideoOnNesting == 0) { |
| 3650 | return; |
| 3651 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3652 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3653 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3654 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3655 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3656 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3657 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3658 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3659 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3660 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3661 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3662 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3665 | public void noteResetAudioLocked() { |
| 3666 | if (mAudioOnNesting > 0) { |
| 3667 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3668 | final long uptime = SystemClock.uptimeMillis(); |
| 3669 | mAudioOnNesting = 0; |
| 3670 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3671 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3672 | + Integer.toHexString(mHistoryCur.states)); |
| 3673 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3674 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3675 | for (int i=0; i<mUidStats.size(); i++) { |
| 3676 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3677 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3678 | } |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | public void noteResetVideoLocked() { |
| 3683 | if (mVideoOnNesting > 0) { |
| 3684 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3685 | final long uptime = SystemClock.uptimeMillis(); |
| 3686 | mAudioOnNesting = 0; |
| 3687 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3688 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3689 | + Integer.toHexString(mHistoryCur.states)); |
| 3690 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3691 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3692 | for (int i=0; i<mUidStats.size(); i++) { |
| 3693 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3694 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3695 | } |
| 3696 | } |
| 3697 | } |
| 3698 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3699 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3700 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3701 | getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3705 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3706 | getUidStatsLocked(uid).noteActivityPausedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3709 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3710 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3711 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3712 | } |
| 3713 | |
| 3714 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3715 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3716 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3717 | } |
| 3718 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3719 | public void noteFlashlightOnLocked(int uid) { |
| 3720 | uid = mapUid(uid); |
| 3721 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3722 | final long uptime = SystemClock.uptimeMillis(); |
| 3723 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3724 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3725 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3726 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3727 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3728 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3729 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3730 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 3731 | } |
| 3732 | |
| 3733 | public void noteFlashlightOffLocked(int uid) { |
| 3734 | if (mFlashlightOnNesting == 0) { |
| 3735 | return; |
| 3736 | } |
| 3737 | uid = mapUid(uid); |
| 3738 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3739 | final long uptime = SystemClock.uptimeMillis(); |
| 3740 | if (--mFlashlightOnNesting == 0) { |
| 3741 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3742 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3743 | + Integer.toHexString(mHistoryCur.states2)); |
| 3744 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3745 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3746 | } |
| 3747 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 3748 | } |
| 3749 | |
| 3750 | public void noteCameraOnLocked(int uid) { |
| 3751 | uid = mapUid(uid); |
| 3752 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3753 | final long uptime = SystemClock.uptimeMillis(); |
| 3754 | if (mCameraOnNesting++ == 0) { |
| 3755 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 3756 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 3757 | + Integer.toHexString(mHistoryCur.states2)); |
| 3758 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3759 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 3760 | } |
| 3761 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 3762 | } |
| 3763 | |
| 3764 | public void noteCameraOffLocked(int uid) { |
| 3765 | if (mCameraOnNesting == 0) { |
| 3766 | return; |
| 3767 | } |
| 3768 | uid = mapUid(uid); |
| 3769 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3770 | final long uptime = SystemClock.uptimeMillis(); |
| 3771 | if (--mCameraOnNesting == 0) { |
| 3772 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3773 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3774 | + Integer.toHexString(mHistoryCur.states2)); |
| 3775 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3776 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 3777 | } |
| 3778 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 3779 | } |
| 3780 | |
| 3781 | public void noteResetCameraLocked() { |
| 3782 | if (mCameraOnNesting > 0) { |
| 3783 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3784 | final long uptime = SystemClock.uptimeMillis(); |
| 3785 | mCameraOnNesting = 0; |
| 3786 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3787 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3788 | + Integer.toHexString(mHistoryCur.states2)); |
| 3789 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3790 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3791 | for (int i=0; i<mUidStats.size(); i++) { |
| 3792 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3793 | uid.noteResetCameraLocked(elapsedRealtime); |
| 3794 | } |
| 3795 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3798 | public void noteResetFlashlightLocked() { |
| 3799 | if (mFlashlightOnNesting > 0) { |
| 3800 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3801 | final long uptime = SystemClock.uptimeMillis(); |
| 3802 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3803 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3804 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3805 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3806 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3807 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3808 | for (int i=0; i<mUidStats.size(); i++) { |
| 3809 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3810 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 3811 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3812 | } |
| 3813 | } |
| 3814 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3815 | public void noteWifiRadioPowerState(int powerState, long timestampNs) { |
| 3816 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3817 | final long uptime = SystemClock.uptimeMillis(); |
| 3818 | if (mWifiRadioPowerState != powerState) { |
| 3819 | final boolean active = |
| 3820 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3821 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3822 | if (active) { |
| 3823 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 3824 | } else { |
| 3825 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 3826 | } |
| 3827 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 3828 | + Integer.toHexString(mHistoryCur.states)); |
| 3829 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3830 | mWifiRadioPowerState = powerState; |
| 3831 | } |
| 3832 | } |
| 3833 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3834 | public void noteWifiRunningLocked(WorkSource ws) { |
| 3835 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3836 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3837 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3838 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3839 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 3840 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3841 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3842 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3843 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3844 | int N = ws.size(); |
| 3845 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3846 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3847 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3848 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3849 | scheduleSyncExternalStatsLocked("wifi-running"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3850 | } else { |
| 3851 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3855 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 3856 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3857 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3858 | int N = oldWs.size(); |
| 3859 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3860 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3861 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3862 | } |
| 3863 | N = newWs.size(); |
| 3864 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3865 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3866 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3867 | } |
| 3868 | } else { |
| 3869 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 3874 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3875 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3876 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3877 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3878 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 3879 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3880 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3881 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3882 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3883 | int N = ws.size(); |
| 3884 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3885 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3886 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3887 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3888 | scheduleSyncExternalStatsLocked("wifi-stopped"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3889 | } else { |
| 3890 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3894 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 3895 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 3896 | if (mWifiState != wifiState) { |
| 3897 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3898 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3899 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3900 | } |
| 3901 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3902 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3903 | scheduleSyncExternalStatsLocked("wifi-state"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3904 | } |
| 3905 | } |
| 3906 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3907 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 3908 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 3909 | if (mWifiSupplState != supplState) { |
| 3910 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3911 | final long uptime = SystemClock.uptimeMillis(); |
| 3912 | if (mWifiSupplState >= 0) { |
| 3913 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 3914 | } |
| 3915 | mWifiSupplState = supplState; |
| 3916 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 3917 | mHistoryCur.states2 = |
| 3918 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 3919 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 3920 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 3921 | + Integer.toHexString(mHistoryCur.states2)); |
| 3922 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3923 | } |
| 3924 | } |
| 3925 | |
| 3926 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
| 3927 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3928 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3929 | if (i == except) { |
| 3930 | continue; |
| 3931 | } |
| 3932 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 3933 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 3934 | } |
| 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 3939 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 3940 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 3941 | if (mWifiSignalStrengthBin != strengthBin) { |
| 3942 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3943 | final long uptime = SystemClock.uptimeMillis(); |
| 3944 | if (mWifiSignalStrengthBin >= 0) { |
| 3945 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 3946 | elapsedRealtime); |
| 3947 | } |
| 3948 | if (strengthBin >= 0) { |
| 3949 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 3950 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 3951 | } |
| 3952 | mHistoryCur.states2 = |
| 3953 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 3954 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 3955 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 3956 | + Integer.toHexString(mHistoryCur.states2)); |
| 3957 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3958 | } else { |
| 3959 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 3960 | } |
| 3961 | mWifiSignalStrengthBin = strengthBin; |
| 3962 | } |
| 3963 | } |
| 3964 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3965 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3966 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3967 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3968 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3969 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3970 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3971 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3972 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3973 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 3974 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3975 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3976 | } |
| 3977 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3978 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3982 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3983 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3984 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3985 | mWifiFullLockNesting--; |
| 3986 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3987 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3988 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 3989 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3990 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3991 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3992 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3995 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3996 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3997 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3998 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3999 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4000 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4001 | if (mWifiScanNesting == 0) { |
| 4002 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4003 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4004 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4005 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4006 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4007 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4008 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4011 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4012 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4013 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4014 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4015 | mWifiScanNesting--; |
| 4016 | if (mWifiScanNesting == 0) { |
| 4017 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4018 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4019 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4020 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4021 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4022 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4023 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4024 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4025 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4026 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4027 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4028 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4032 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4033 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4034 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4037 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4038 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4039 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4040 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4041 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4042 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4043 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4044 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4045 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4046 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4047 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4048 | } |
| 4049 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4050 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4054 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4055 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4056 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4057 | mWifiMulticastNesting--; |
| 4058 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4059 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4060 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4061 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4062 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4063 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4064 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4067 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4068 | int N = ws.size(); |
| 4069 | for (int i=0; i<N; i++) { |
| 4070 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4071 | } |
| 4072 | } |
| 4073 | |
| 4074 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4075 | int N = ws.size(); |
| 4076 | for (int i=0; i<N; i++) { |
| 4077 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4078 | } |
| 4079 | } |
| 4080 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4081 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4082 | int N = ws.size(); |
| 4083 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4084 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4085 | } |
| 4086 | } |
| 4087 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4088 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4089 | int N = ws.size(); |
| 4090 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4091 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4095 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4096 | int N = ws.size(); |
| 4097 | for (int i=0; i<N; i++) { |
| 4098 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4103 | int N = ws.size(); |
| 4104 | for (int i=0; i<N; i++) { |
| 4105 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4106 | } |
| 4107 | } |
| 4108 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4109 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4110 | int N = ws.size(); |
| 4111 | for (int i=0; i<N; i++) { |
| 4112 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4117 | int N = ws.size(); |
| 4118 | for (int i=0; i<N; i++) { |
| 4119 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4120 | } |
| 4121 | } |
| 4122 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4123 | private static String[] includeInStringArray(String[] array, String str) { |
| 4124 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4125 | return array; |
| 4126 | } |
| 4127 | String[] newArray = new String[array.length+1]; |
| 4128 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4129 | newArray[array.length] = str; |
| 4130 | return newArray; |
| 4131 | } |
| 4132 | |
| 4133 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4134 | int index = ArrayUtils.indexOf(array, str); |
| 4135 | if (index >= 0) { |
| 4136 | String[] newArray = new String[array.length-1]; |
| 4137 | if (index > 0) { |
| 4138 | System.arraycopy(array, 0, newArray, 0, index); |
| 4139 | } |
| 4140 | if (index < array.length-1) { |
| 4141 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4142 | } |
| 4143 | return newArray; |
| 4144 | } |
| 4145 | return array; |
| 4146 | } |
| 4147 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4148 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4149 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4150 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4151 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4152 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4153 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4154 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4155 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4156 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4157 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4158 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4159 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4160 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4161 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4162 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | public void noteNetworkStatsEnabledLocked() { |
| 4167 | // During device boot, qtaguid isn't enabled until after the inital |
| 4168 | // loading of battery stats. Now that they're enabled, take our initial |
| 4169 | // snapshot for future delta calculation. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4170 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 4171 | updateMobileRadioStateLocked(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4172 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4175 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4176 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4178 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4179 | @Override public int getScreenOnCount(int which) { |
| 4180 | return mScreenOnTimer.getCountLocked(which); |
| 4181 | } |
| 4182 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4183 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4184 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4185 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4186 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4187 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4188 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4189 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4190 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4191 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4192 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4193 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4194 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4197 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4198 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4199 | } |
| 4200 | |
| 4201 | @Override public long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4202 | return mDeviceIdleModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4203 | } |
| 4204 | |
| 4205 | @Override public int getDeviceIdleModeEnabledCount(int which) { |
| 4206 | return mDeviceIdleModeEnabledTimer.getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4209 | @Override public long getDeviceIdlingTime(long elapsedRealtimeUs, int which) { |
| 4210 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4211 | } |
| 4212 | |
| 4213 | @Override public int getDeviceIdlingCount(int which) { |
| 4214 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4215 | } |
| 4216 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4217 | @Override public int getNumConnectivityChange(int which) { |
| 4218 | int val = mNumConnectivityChange; |
| 4219 | if (which == STATS_CURRENT) { |
| 4220 | val -= mLoadedNumConnectivityChange; |
| 4221 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4222 | val -= mUnpluggedNumConnectivityChange; |
| 4223 | } |
| 4224 | return val; |
| 4225 | } |
| 4226 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4227 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4228 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4230 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4231 | @Override public int getPhoneOnCount(int which) { |
| 4232 | return mPhoneOnTimer.getCountLocked(which); |
| 4233 | } |
| 4234 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4235 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4236 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4237 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4238 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4239 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4240 | |
| 4241 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4242 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4243 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4244 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4245 | } |
| 4246 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4247 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4248 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4249 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4250 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4251 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4252 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4253 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4254 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4256 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4257 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4258 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4259 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4260 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4261 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4262 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4263 | } |
| 4264 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4265 | @Override public int getMobileRadioActiveCount(int which) { |
| 4266 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4267 | } |
| 4268 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4269 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4270 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4271 | } |
| 4272 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4273 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4274 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4275 | } |
| 4276 | |
| 4277 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4278 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4279 | } |
| 4280 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4281 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4282 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4283 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4284 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4285 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4286 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4289 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4290 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4291 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4292 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4296 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4297 | } |
| 4298 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4299 | @Override public long getWifiSupplStateTime(int state, |
| 4300 | long elapsedRealtimeUs, int which) { |
| 4301 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4302 | elapsedRealtimeUs, which); |
| 4303 | } |
| 4304 | |
| 4305 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4306 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4307 | } |
| 4308 | |
| 4309 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4310 | long elapsedRealtimeUs, int which) { |
| 4311 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4312 | elapsedRealtimeUs, which); |
| 4313 | } |
| 4314 | |
| 4315 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4316 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4317 | } |
| 4318 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4319 | @Override public boolean hasBluetoothActivityReporting() { |
| 4320 | return mHasBluetoothEnergyReporting; |
| 4321 | } |
| 4322 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4323 | @Override public long getBluetoothControllerActivity(int type, int which) { |
| 4324 | if (type >= 0 && type < mBluetoothActivityCounters.length) { |
| 4325 | return mBluetoothActivityCounters[type].getCountLocked(which); |
| 4326 | } |
| 4327 | return 0; |
| 4328 | } |
| 4329 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4330 | @Override public boolean hasWifiActivityReporting() { |
| 4331 | return mHasWifiEnergyReporting; |
| 4332 | } |
| 4333 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4334 | @Override public long getWifiControllerActivity(int type, int which) { |
| 4335 | if (type >= 0 && type < mWifiActivityCounters.length) { |
| 4336 | return mWifiActivityCounters[type].getCountLocked(which); |
| 4337 | } |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4341 | @Override |
| 4342 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4343 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4344 | } |
| 4345 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4346 | @Override |
| 4347 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4348 | return mFlashlightOnTimer.getCountLocked(which); |
| 4349 | } |
| 4350 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4351 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4352 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4353 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4354 | } |
| 4355 | |
| 4356 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4357 | public long getNetworkActivityBytes(int type, int which) { |
| 4358 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4359 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4360 | } else { |
| 4361 | return 0; |
| 4362 | } |
| 4363 | } |
| 4364 | |
| 4365 | @Override |
| 4366 | public long getNetworkActivityPackets(int type, int which) { |
| 4367 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4368 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4369 | } else { |
| 4370 | return 0; |
| 4371 | } |
| 4372 | } |
| 4373 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4374 | boolean isStartClockTimeValid() { |
| 4375 | return mStartClockTime > 365*24*60*60*1000L; |
| 4376 | } |
| 4377 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4378 | @Override public long getStartClockTime() { |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4379 | if (!isStartClockTimeValid()) { |
| 4380 | // If the last clock time we got was very small, then we hadn't had a real |
| 4381 | // time yet, so try to get it again. |
| 4382 | mStartClockTime = System.currentTimeMillis(); |
| 4383 | if (isStartClockTimeValid()) { |
| 4384 | recordCurrentTimeChangeLocked(mStartClockTime, SystemClock.elapsedRealtime(), |
| 4385 | SystemClock.uptimeMillis()); |
| 4386 | } |
| 4387 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4388 | return mStartClockTime; |
| 4389 | } |
| 4390 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4391 | @Override public String getStartPlatformVersion() { |
| 4392 | return mStartPlatformVersion; |
| 4393 | } |
| 4394 | |
| 4395 | @Override public String getEndPlatformVersion() { |
| 4396 | return mEndPlatformVersion; |
| 4397 | } |
| 4398 | |
| 4399 | @Override public int getParcelVersion() { |
| 4400 | return VERSION; |
| 4401 | } |
| 4402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | @Override public boolean getIsOnBattery() { |
| 4404 | return mOnBattery; |
| 4405 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4408 | return mUidStats; |
| 4409 | } |
| 4410 | |
| 4411 | /** |
| 4412 | * The statistics associated with a particular uid. |
| 4413 | */ |
| 4414 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4417 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4418 | boolean mWifiRunning; |
| 4419 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4420 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4421 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4422 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4423 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4424 | boolean mWifiScanStarted; |
| 4425 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4426 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4427 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4428 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4429 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4430 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4431 | boolean mWifiMulticastEnabled; |
| 4432 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4433 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4434 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4435 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4436 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 4437 | StopwatchTimer mCameraTurnedOnTimer; |
| 4438 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4439 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4440 | StopwatchTimer mForegroundActivityTimer; |
| 4441 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4442 | static final int PROCESS_STATE_NONE = NUM_PROCESS_STATE; |
| 4443 | int mProcessState = PROCESS_STATE_NONE; |
| 4444 | StopwatchTimer[] mProcessStateTimer; |
| 4445 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4446 | BatchTimer mVibratorOnTimer; |
| 4447 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4448 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4449 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4450 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4451 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4452 | LongSamplingCounter mMobileRadioActiveTime; |
| 4453 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4456 | * The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode. |
| 4457 | */ |
| 4458 | LongSamplingCounter[] mWifiControllerTime = |
| 4459 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4460 | |
| 4461 | /** |
| 4462 | * The amount of time this uid has kept the Bluetooth controller in idle, tx, and rx mode. |
| 4463 | */ |
| 4464 | LongSamplingCounter[] mBluetoothControllerTime = |
| 4465 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4466 | |
| 4467 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4468 | * The CPU times we had at the last history details update. |
| 4469 | */ |
| 4470 | long mLastStepUserTime; |
| 4471 | long mLastStepSystemTime; |
| 4472 | long mCurStepUserTime; |
| 4473 | long mCurStepSystemTime; |
| 4474 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4475 | LongSamplingCounter mUserCpuTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4476 | LongSamplingCounter mSystemCpuTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4477 | LongSamplingCounter[] mSpeedBins; |
| 4478 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4479 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | * The statistics we have collected for this uid's wake locks. |
| 4481 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4482 | final OverflowArrayMap<Wakelock> mWakelockStats = new OverflowArrayMap<Wakelock>() { |
| 4483 | @Override public Wakelock instantiateObject() { return new Wakelock(); } |
| 4484 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | |
| 4486 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4487 | * The statistics we have collected for this uid's syncs. |
| 4488 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4489 | final OverflowArrayMap<StopwatchTimer> mSyncStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4490 | @Override public StopwatchTimer instantiateObject() { |
| 4491 | return new StopwatchTimer(Uid.this, SYNC, null, mOnBatteryTimeBase); |
| 4492 | } |
| 4493 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4494 | |
| 4495 | /** |
| 4496 | * The statistics we have collected for this uid's jobs. |
| 4497 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4498 | final OverflowArrayMap<StopwatchTimer> mJobStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4499 | @Override public StopwatchTimer instantiateObject() { |
| 4500 | return new StopwatchTimer(Uid.this, JOB, null, mOnBatteryTimeBase); |
| 4501 | } |
| 4502 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4503 | |
| 4504 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | * The statistics we have collected for this uid's sensor activations. |
| 4506 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4507 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | |
| 4509 | /** |
| 4510 | * The statistics we have collected for this uid's processes. |
| 4511 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4512 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | |
| 4514 | /** |
| 4515 | * The statistics we have collected for this uid's processes. |
| 4516 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4517 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4518 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4519 | /** |
| 4520 | * The transient wake stats we have collected for this uid's pids. |
| 4521 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4522 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | public Uid(int uid) { |
| 4525 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4526 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4527 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4528 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4529 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4530 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4531 | mWifiScanTimers, mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4532 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4533 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4534 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4535 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4536 | mSpeedBins = new LongSamplingCounter[getCpuSpeedSteps()]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4540 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4541 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4545 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4546 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4550 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4551 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4555 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | return mSensorStats; |
| 4557 | } |
| 4558 | |
| 4559 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4560 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4561 | return mProcessStats; |
| 4562 | } |
| 4563 | |
| 4564 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4565 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4566 | return mPackageStats; |
| 4567 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4568 | |
| 4569 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | public int getUid() { |
| 4571 | return mUid; |
| 4572 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4573 | |
| 4574 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4575 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4576 | if (!mWifiRunning) { |
| 4577 | mWifiRunning = true; |
| 4578 | if (mWifiRunningTimer == null) { |
| 4579 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4580 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4581 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4582 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4583 | } |
| 4584 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4585 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4586 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4587 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4588 | if (mWifiRunning) { |
| 4589 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4590 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4591 | } |
| 4592 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4593 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4594 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4595 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4596 | if (!mFullWifiLockOut) { |
| 4597 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4598 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4599 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4600 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4601 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4602 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4603 | } |
| 4604 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4605 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4606 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4607 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4608 | if (mFullWifiLockOut) { |
| 4609 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4610 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4611 | } |
| 4612 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4613 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4614 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4615 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4616 | if (!mWifiScanStarted) { |
| 4617 | mWifiScanStarted = true; |
| 4618 | if (mWifiScanTimer == null) { |
| 4619 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4620 | mWifiScanTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4621 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4622 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4623 | } |
| 4624 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4625 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4626 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4627 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4628 | if (mWifiScanStarted) { |
| 4629 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4630 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4631 | } |
| 4632 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4633 | |
| 4634 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4635 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4636 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame^] | 4637 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4638 | csph = csph >> 3; |
| 4639 | bin++; |
| 4640 | } |
| 4641 | |
| 4642 | if (mWifiBatchedScanBinStarted == bin) return; |
| 4643 | |
| 4644 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4645 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4646 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4647 | } |
| 4648 | mWifiBatchedScanBinStarted = bin; |
| 4649 | if (mWifiBatchedScanTimer[bin] == null) { |
| 4650 | makeWifiBatchedScanBin(bin, null); |
| 4651 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4652 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4656 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4657 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4658 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4659 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4660 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4665 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4666 | if (!mWifiMulticastEnabled) { |
| 4667 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4668 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4669 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4670 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4671 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4672 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | |
| 4676 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4677 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4678 | if (mWifiMulticastEnabled) { |
| 4679 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4680 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4681 | } |
| 4682 | } |
| 4683 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4684 | public void noteWifiControllerActivityLocked(int type, long timeMs) { |
| 4685 | if (mWifiControllerTime[type] == null) { |
| 4686 | mWifiControllerTime[type] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4687 | } |
| 4688 | mWifiControllerTime[type].addCountLocked(timeMs); |
| 4689 | } |
| 4690 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4691 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 4692 | if (mAudioTurnedOnTimer == null) { |
| 4693 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4694 | mAudioTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4695 | } |
| 4696 | return mAudioTurnedOnTimer; |
| 4697 | } |
| 4698 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4699 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4700 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4701 | } |
| 4702 | |
| 4703 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 4704 | if (mAudioTurnedOnTimer != null) { |
| 4705 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4706 | } |
| 4707 | } |
| 4708 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4709 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 4710 | if (mAudioTurnedOnTimer != null) { |
| 4711 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4712 | } |
| 4713 | } |
| 4714 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4715 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 4716 | if (mVideoTurnedOnTimer == null) { |
| 4717 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4718 | mVideoTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4719 | } |
| 4720 | return mVideoTurnedOnTimer; |
| 4721 | } |
| 4722 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4723 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4724 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4725 | } |
| 4726 | |
| 4727 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 4728 | if (mVideoTurnedOnTimer != null) { |
| 4729 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4733 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 4734 | if (mVideoTurnedOnTimer != null) { |
| 4735 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4736 | } |
| 4737 | } |
| 4738 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4739 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 4740 | if (mFlashlightTurnedOnTimer == null) { |
| 4741 | mFlashlightTurnedOnTimer = new StopwatchTimer(Uid.this, FLASHLIGHT_TURNED_ON, |
| 4742 | mFlashlightTurnedOnTimers, mOnBatteryTimeBase); |
| 4743 | } |
| 4744 | return mFlashlightTurnedOnTimer; |
| 4745 | } |
| 4746 | |
| 4747 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 4748 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4749 | } |
| 4750 | |
| 4751 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 4752 | if (mFlashlightTurnedOnTimer != null) { |
| 4753 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 4758 | if (mFlashlightTurnedOnTimer != null) { |
| 4759 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 4760 | } |
| 4761 | } |
| 4762 | |
| 4763 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 4764 | if (mCameraTurnedOnTimer == null) { |
| 4765 | mCameraTurnedOnTimer = new StopwatchTimer(Uid.this, CAMERA_TURNED_ON, |
| 4766 | mCameraTurnedOnTimers, mOnBatteryTimeBase); |
| 4767 | } |
| 4768 | return mCameraTurnedOnTimer; |
| 4769 | } |
| 4770 | |
| 4771 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 4772 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4773 | } |
| 4774 | |
| 4775 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 4776 | if (mCameraTurnedOnTimer != null) { |
| 4777 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 4782 | if (mCameraTurnedOnTimer != null) { |
| 4783 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 4784 | } |
| 4785 | } |
| 4786 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4787 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 4788 | if (mForegroundActivityTimer == null) { |
| 4789 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4790 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4791 | } |
| 4792 | return mForegroundActivityTimer; |
| 4793 | } |
| 4794 | |
| 4795 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4796 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4797 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4798 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4802 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4803 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4804 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4805 | } |
| 4806 | } |
| 4807 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4808 | void updateUidProcessStateLocked(int state, long elapsedRealtimeMs) { |
| 4809 | if (mProcessState == state) return; |
| 4810 | |
| 4811 | if (mProcessState != PROCESS_STATE_NONE) { |
| 4812 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
| 4813 | } |
| 4814 | mProcessState = state; |
| 4815 | if (state != PROCESS_STATE_NONE) { |
| 4816 | if (mProcessStateTimer[state] == null) { |
| 4817 | makeProcessState(state, null); |
| 4818 | } |
| 4819 | mProcessStateTimer[state].startRunningLocked(elapsedRealtimeMs); |
| 4820 | } |
| 4821 | } |
| 4822 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4823 | public BatchTimer createVibratorOnTimerLocked() { |
| 4824 | if (mVibratorOnTimer == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4825 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4826 | } |
| 4827 | return mVibratorOnTimer; |
| 4828 | } |
| 4829 | |
| 4830 | public void noteVibratorOnLocked(long durationMillis) { |
| 4831 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 4832 | } |
| 4833 | |
| 4834 | public void noteVibratorOffLocked() { |
| 4835 | if (mVibratorOnTimer != null) { |
| 4836 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4840 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4841 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4842 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4843 | return 0; |
| 4844 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4845 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4846 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4847 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4848 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4849 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4850 | if (mFullWifiLockTimer == null) { |
| 4851 | return 0; |
| 4852 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4853 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4854 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4855 | |
| 4856 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4857 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4858 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4859 | return 0; |
| 4860 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4861 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4862 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4863 | |
| 4864 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4865 | public int getWifiScanCount(int which) { |
| 4866 | if (mWifiScanTimer == null) { |
| 4867 | return 0; |
| 4868 | } |
| 4869 | return mWifiScanTimer.getCountLocked(which); |
| 4870 | } |
| 4871 | |
| 4872 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4873 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4874 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4875 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4876 | return 0; |
| 4877 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4878 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4882 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 4883 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4884 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4885 | return 0; |
| 4886 | } |
| 4887 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 4888 | } |
| 4889 | |
| 4890 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4891 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4892 | if (mWifiMulticastTimer == null) { |
| 4893 | return 0; |
| 4894 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4895 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4896 | } |
| 4897 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4898 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4899 | public Timer getAudioTurnedOnTimer() { |
| 4900 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4903 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4904 | public Timer getVideoTurnedOnTimer() { |
| 4905 | return mVideoTurnedOnTimer; |
| 4906 | } |
| 4907 | |
| 4908 | @Override |
| 4909 | public Timer getFlashlightTurnedOnTimer() { |
| 4910 | return mFlashlightTurnedOnTimer; |
| 4911 | } |
| 4912 | |
| 4913 | @Override |
| 4914 | public Timer getCameraTurnedOnTimer() { |
| 4915 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4918 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4919 | public Timer getForegroundActivityTimer() { |
| 4920 | return mForegroundActivityTimer; |
| 4921 | } |
| 4922 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4923 | void makeProcessState(int i, Parcel in) { |
| 4924 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 4925 | |
| 4926 | if (in == null) { |
| 4927 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4928 | mOnBatteryTimeBase); |
| 4929 | } else { |
| 4930 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4931 | mOnBatteryTimeBase, in); |
| 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | @Override |
| 4936 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 4937 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 4938 | if (mProcessStateTimer[state] == null) { |
| 4939 | return 0; |
| 4940 | } |
| 4941 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4942 | } |
| 4943 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4944 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4945 | public Timer getVibratorOnTimer() { |
| 4946 | return mVibratorOnTimer; |
| 4947 | } |
| 4948 | |
| 4949 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4950 | public void noteUserActivityLocked(int type) { |
| 4951 | if (mUserActivityCounters == null) { |
| 4952 | initUserActivityLocked(); |
| 4953 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 4954 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 4955 | mUserActivityCounters[type].stepAtomic(); |
| 4956 | } else { |
| 4957 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 4958 | new Throwable()); |
| 4959 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4960 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4961 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4962 | @Override |
| 4963 | public boolean hasUserActivity() { |
| 4964 | return mUserActivityCounters != null; |
| 4965 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4966 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4967 | @Override |
| 4968 | public int getUserActivityCount(int type, int which) { |
| 4969 | if (mUserActivityCounters == null) { |
| 4970 | return 0; |
| 4971 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4972 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4973 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4974 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4975 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 4976 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 4977 | |
| 4978 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 4979 | if (collected == null) { |
| 4980 | collected = new ArrayList<StopwatchTimer>(); |
| 4981 | mWifiBatchedScanTimers.put(i, collected); |
| 4982 | } |
| 4983 | if (in == null) { |
| 4984 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4985 | mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4986 | } else { |
| 4987 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4988 | mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4993 | void initUserActivityLocked() { |
| 4994 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4995 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4996 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4997 | } |
| 4998 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4999 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5000 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5001 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5002 | initNetworkActivityLocked(); |
| 5003 | } |
| 5004 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5005 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5006 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5007 | } else { |
| 5008 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5009 | new Throwable()); |
| 5010 | } |
| 5011 | } |
| 5012 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5013 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5014 | if (mNetworkByteActivityCounters == null) { |
| 5015 | initNetworkActivityLocked(); |
| 5016 | } |
| 5017 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5018 | mMobileRadioActiveCount.addCountLocked(1); |
| 5019 | } |
| 5020 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5021 | @Override |
| 5022 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5023 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5027 | public long getNetworkActivityBytes(int type, int which) { |
| 5028 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5029 | && type < mNetworkByteActivityCounters.length) { |
| 5030 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5031 | } else { |
| 5032 | return 0; |
| 5033 | } |
| 5034 | } |
| 5035 | |
| 5036 | @Override |
| 5037 | public long getNetworkActivityPackets(int type, int which) { |
| 5038 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5039 | && type < mNetworkPacketActivityCounters.length) { |
| 5040 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5041 | } else { |
| 5042 | return 0; |
| 5043 | } |
| 5044 | } |
| 5045 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5046 | @Override |
| 5047 | public long getMobileRadioActiveTime(int which) { |
| 5048 | return mMobileRadioActiveTime != null |
| 5049 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5050 | } |
| 5051 | |
| 5052 | @Override |
| 5053 | public int getMobileRadioActiveCount(int which) { |
| 5054 | return mMobileRadioActiveCount != null |
| 5055 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5056 | } |
| 5057 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5058 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5059 | public long getUserCpuTimeUs(int which) { |
| 5060 | return mUserCpuTime.getCountLocked(which); |
| 5061 | } |
| 5062 | |
| 5063 | @Override |
| 5064 | public long getSystemCpuTimeUs(int which) { |
| 5065 | return mSystemCpuTime.getCountLocked(which); |
| 5066 | } |
| 5067 | |
| 5068 | @Override |
| 5069 | public long getTimeAtCpuSpeed(int step, int which) { |
| 5070 | if (step >= 0 && step < mSpeedBins.length) { |
| 5071 | if (mSpeedBins[step] != null) { |
| 5072 | return mSpeedBins[step].getCountLocked(which); |
| 5073 | } |
| 5074 | } |
| 5075 | return 0; |
| 5076 | } |
| 5077 | |
| 5078 | @Override |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5079 | public long getWifiControllerActivity(int type, int which) { |
| 5080 | if (type >= 0 && type < NUM_CONTROLLER_ACTIVITY_TYPES && |
| 5081 | mWifiControllerTime[type] != null) { |
| 5082 | return mWifiControllerTime[type].getCountLocked(which); |
| 5083 | } |
| 5084 | return 0; |
| 5085 | } |
| 5086 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5087 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5088 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5089 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5090 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5091 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5092 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5093 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5094 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5095 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5096 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5097 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5098 | /** |
| 5099 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5100 | * inactive so can be dropped. |
| 5101 | */ |
| 5102 | boolean reset() { |
| 5103 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5104 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5105 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5106 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5107 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5108 | } |
| 5109 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5110 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5111 | active |= mFullWifiLockOut; |
| 5112 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5113 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5114 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5115 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5116 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5117 | if (mWifiBatchedScanTimer != null) { |
| 5118 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5119 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5120 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5124 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5125 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5126 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5127 | active |= mWifiMulticastEnabled; |
| 5128 | } |
| 5129 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5130 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5131 | } |
| 5132 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5133 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5134 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5135 | if (mFlashlightTurnedOnTimer != null) { |
| 5136 | active |= !mFlashlightTurnedOnTimer.reset(false); |
| 5137 | } |
| 5138 | if (mCameraTurnedOnTimer != null) { |
| 5139 | active |= !mCameraTurnedOnTimer.reset(false); |
| 5140 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5141 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5142 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5143 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5144 | if (mProcessStateTimer != null) { |
| 5145 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5146 | if (mProcessStateTimer[i] != null) { |
| 5147 | active |= !mProcessStateTimer[i].reset(false); |
| 5148 | } |
| 5149 | } |
| 5150 | active |= (mProcessState != PROCESS_STATE_NONE); |
| 5151 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5152 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5153 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5154 | mVibratorOnTimer.detach(); |
| 5155 | mVibratorOnTimer = null; |
| 5156 | } else { |
| 5157 | active = true; |
| 5158 | } |
| 5159 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5160 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5161 | if (mUserActivityCounters != null) { |
| 5162 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5163 | mUserActivityCounters[i].reset(false); |
| 5164 | } |
| 5165 | } |
| 5166 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5167 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5168 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5169 | mNetworkByteActivityCounters[i].reset(false); |
| 5170 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5171 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5172 | mMobileRadioActiveTime.reset(false); |
| 5173 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5176 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5177 | if (mWifiControllerTime[i] != null) { |
| 5178 | mWifiControllerTime[i].reset(false); |
| 5179 | } |
| 5180 | |
| 5181 | if (mBluetoothControllerTime[i] != null) { |
| 5182 | mBluetoothControllerTime[i].reset(false); |
| 5183 | } |
| 5184 | } |
| 5185 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5186 | mUserCpuTime.reset(false); |
| 5187 | mSystemCpuTime.reset(false); |
| 5188 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5189 | LongSamplingCounter c = mSpeedBins[i]; |
| 5190 | if (c != null) { |
| 5191 | c.reset(false); |
| 5192 | } |
| 5193 | } |
| 5194 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5195 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5196 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5197 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5198 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5199 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5200 | } else { |
| 5201 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5202 | } |
| 5203 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5204 | mWakelockStats.cleanup(); |
| 5205 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5206 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5207 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5208 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5209 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5210 | timer.detach(); |
| 5211 | } else { |
| 5212 | active = true; |
| 5213 | } |
| 5214 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5215 | mSyncStats.cleanup(); |
| 5216 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5217 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5218 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5219 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5220 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5221 | timer.detach(); |
| 5222 | } else { |
| 5223 | active = true; |
| 5224 | } |
| 5225 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5226 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5227 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5228 | Sensor s = mSensorStats.valueAt(ise); |
| 5229 | if (s.reset()) { |
| 5230 | mSensorStats.removeAt(ise); |
| 5231 | } else { |
| 5232 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5233 | } |
| 5234 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5235 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5236 | Proc proc = mProcessStats.valueAt(ip); |
| 5237 | if (proc.mProcessState == PROCESS_STATE_NONE) { |
| 5238 | proc.detach(); |
| 5239 | mProcessStats.removeAt(ip); |
| 5240 | } else { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5241 | proc.reset(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5242 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5243 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5244 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5245 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5246 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5247 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5248 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5249 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5250 | } else { |
| 5251 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5252 | } |
| 5253 | } |
| 5254 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5255 | if (mPackageStats.size() > 0) { |
| 5256 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5257 | while (it.hasNext()) { |
| 5258 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5259 | Pkg p = pkgEntry.getValue(); |
| 5260 | p.detach(); |
| 5261 | if (p.mServiceStats.size() > 0) { |
| 5262 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5263 | = p.mServiceStats.entrySet().iterator(); |
| 5264 | while (it2.hasNext()) { |
| 5265 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5266 | servEntry.getValue().detach(); |
| 5267 | } |
| 5268 | } |
| 5269 | } |
| 5270 | mPackageStats.clear(); |
| 5271 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5272 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5273 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5274 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5275 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5276 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5277 | if (mWifiRunningTimer != null) { |
| 5278 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5279 | } |
| 5280 | if (mFullWifiLockTimer != null) { |
| 5281 | mFullWifiLockTimer.detach(); |
| 5282 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5283 | if (mWifiScanTimer != null) { |
| 5284 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5285 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5286 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5287 | if (mWifiBatchedScanTimer[i] != null) { |
| 5288 | mWifiBatchedScanTimer[i].detach(); |
| 5289 | } |
| 5290 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5291 | if (mWifiMulticastTimer != null) { |
| 5292 | mWifiMulticastTimer.detach(); |
| 5293 | } |
| 5294 | if (mAudioTurnedOnTimer != null) { |
| 5295 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5296 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5297 | } |
| 5298 | if (mVideoTurnedOnTimer != null) { |
| 5299 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5300 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5301 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5302 | if (mFlashlightTurnedOnTimer != null) { |
| 5303 | mFlashlightTurnedOnTimer.detach(); |
| 5304 | mFlashlightTurnedOnTimer = null; |
| 5305 | } |
| 5306 | if (mCameraTurnedOnTimer != null) { |
| 5307 | mCameraTurnedOnTimer.detach(); |
| 5308 | mCameraTurnedOnTimer = null; |
| 5309 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5310 | if (mForegroundActivityTimer != null) { |
| 5311 | mForegroundActivityTimer.detach(); |
| 5312 | mForegroundActivityTimer = null; |
| 5313 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5314 | if (mUserActivityCounters != null) { |
| 5315 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5316 | mUserActivityCounters[i].detach(); |
| 5317 | } |
| 5318 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5319 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5320 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5321 | mNetworkByteActivityCounters[i].detach(); |
| 5322 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5323 | } |
| 5324 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5325 | |
| 5326 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5327 | if (mWifiControllerTime[i] != null) { |
| 5328 | mWifiControllerTime[i].detach(); |
| 5329 | } |
| 5330 | |
| 5331 | if (mBluetoothControllerTime[i] != null) { |
| 5332 | mBluetoothControllerTime[i].detach(); |
| 5333 | } |
| 5334 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5335 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5336 | |
| 5337 | mUserCpuTime.detach(); |
| 5338 | mSystemCpuTime.detach(); |
| 5339 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5340 | LongSamplingCounter c = mSpeedBins[i]; |
| 5341 | if (c != null) { |
| 5342 | c.detach(); |
| 5343 | } |
| 5344 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5345 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5346 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5347 | return !active; |
| 5348 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5349 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5350 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5351 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5352 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5353 | out.writeInt(NW); |
| 5354 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5355 | out.writeString(wakeStats.keyAt(iw)); |
| 5356 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5357 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5358 | } |
| 5359 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5360 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5361 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5362 | out.writeInt(NS); |
| 5363 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5364 | out.writeString(syncStats.keyAt(is)); |
| 5365 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5366 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5367 | } |
| 5368 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5369 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5370 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5371 | out.writeInt(NJ); |
| 5372 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5373 | out.writeString(jobStats.keyAt(ij)); |
| 5374 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5375 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5376 | } |
| 5377 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5378 | int NSE = mSensorStats.size(); |
| 5379 | out.writeInt(NSE); |
| 5380 | for (int ise=0; ise<NSE; ise++) { |
| 5381 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5382 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5383 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5384 | } |
| 5385 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5386 | int NP = mProcessStats.size(); |
| 5387 | out.writeInt(NP); |
| 5388 | for (int ip=0; ip<NP; ip++) { |
| 5389 | out.writeString(mProcessStats.keyAt(ip)); |
| 5390 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | proc.writeToParcelLocked(out); |
| 5392 | } |
| 5393 | |
| 5394 | out.writeInt(mPackageStats.size()); |
| 5395 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5396 | out.writeString(pkgEntry.getKey()); |
| 5397 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5398 | pkg.writeToParcelLocked(out); |
| 5399 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5400 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5401 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5402 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5403 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5404 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5405 | out.writeInt(0); |
| 5406 | } |
| 5407 | if (mFullWifiLockTimer != null) { |
| 5408 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5409 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5410 | } else { |
| 5411 | out.writeInt(0); |
| 5412 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5413 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5414 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5415 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5416 | } else { |
| 5417 | out.writeInt(0); |
| 5418 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5419 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5420 | if (mWifiBatchedScanTimer[i] != null) { |
| 5421 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5422 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5423 | } else { |
| 5424 | out.writeInt(0); |
| 5425 | } |
| 5426 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5427 | if (mWifiMulticastTimer != null) { |
| 5428 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5429 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5430 | } else { |
| 5431 | out.writeInt(0); |
| 5432 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5433 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5434 | if (mAudioTurnedOnTimer != null) { |
| 5435 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5436 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5437 | } else { |
| 5438 | out.writeInt(0); |
| 5439 | } |
| 5440 | if (mVideoTurnedOnTimer != null) { |
| 5441 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5442 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5443 | } else { |
| 5444 | out.writeInt(0); |
| 5445 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5446 | if (mFlashlightTurnedOnTimer != null) { |
| 5447 | out.writeInt(1); |
| 5448 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5449 | } else { |
| 5450 | out.writeInt(0); |
| 5451 | } |
| 5452 | if (mCameraTurnedOnTimer != null) { |
| 5453 | out.writeInt(1); |
| 5454 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5455 | } else { |
| 5456 | out.writeInt(0); |
| 5457 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5458 | if (mForegroundActivityTimer != null) { |
| 5459 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5460 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5461 | } else { |
| 5462 | out.writeInt(0); |
| 5463 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5464 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5465 | if (mProcessStateTimer[i] != null) { |
| 5466 | out.writeInt(1); |
| 5467 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 5468 | } else { |
| 5469 | out.writeInt(0); |
| 5470 | } |
| 5471 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5472 | if (mVibratorOnTimer != null) { |
| 5473 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5474 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5475 | } else { |
| 5476 | out.writeInt(0); |
| 5477 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5478 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5479 | out.writeInt(1); |
| 5480 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5481 | mUserActivityCounters[i].writeToParcel(out); |
| 5482 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5483 | } else { |
| 5484 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5485 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5486 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5487 | out.writeInt(1); |
| 5488 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5489 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 5490 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5491 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5492 | mMobileRadioActiveTime.writeToParcel(out); |
| 5493 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5494 | } else { |
| 5495 | out.writeInt(0); |
| 5496 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5497 | |
| 5498 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5499 | if (mWifiControllerTime[i] != null) { |
| 5500 | out.writeInt(1); |
| 5501 | mWifiControllerTime[i].writeToParcel(out); |
| 5502 | } else { |
| 5503 | out.writeInt(0); |
| 5504 | } |
| 5505 | } |
| 5506 | |
| 5507 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5508 | if (mBluetoothControllerTime[i] != null) { |
| 5509 | out.writeInt(1); |
| 5510 | mBluetoothControllerTime[i].writeToParcel(out); |
| 5511 | } else { |
| 5512 | out.writeInt(0); |
| 5513 | } |
| 5514 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5515 | |
| 5516 | mUserCpuTime.writeToParcel(out); |
| 5517 | mSystemCpuTime.writeToParcel(out); |
| 5518 | |
| 5519 | out.writeInt(mSpeedBins.length); |
| 5520 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5521 | LongSamplingCounter c = mSpeedBins[i]; |
| 5522 | if (c != null) { |
| 5523 | out.writeInt(1); |
| 5524 | c.writeToParcel(out); |
| 5525 | } else { |
| 5526 | out.writeInt(0); |
| 5527 | } |
| 5528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | } |
| 5530 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5531 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | int numWakelocks = in.readInt(); |
| 5533 | mWakelockStats.clear(); |
| 5534 | for (int j = 0; j < numWakelocks; j++) { |
| 5535 | String wakelockName = in.readString(); |
| 5536 | Uid.Wakelock wakelock = new Wakelock(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5537 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5538 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | } |
| 5540 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5541 | int numSyncs = in.readInt(); |
| 5542 | mSyncStats.clear(); |
| 5543 | for (int j = 0; j < numSyncs; j++) { |
| 5544 | String syncName = in.readString(); |
| 5545 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5546 | mSyncStats.add(syncName, |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5547 | new StopwatchTimer(Uid.this, SYNC, null, timeBase, in)); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | int numJobs = in.readInt(); |
| 5552 | mJobStats.clear(); |
| 5553 | for (int j = 0; j < numJobs; j++) { |
| 5554 | String jobName = in.readString(); |
| 5555 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5556 | mJobStats.add(jobName, new StopwatchTimer(Uid.this, JOB, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5557 | } |
| 5558 | } |
| 5559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | int numSensors = in.readInt(); |
| 5561 | mSensorStats.clear(); |
| 5562 | for (int k = 0; k < numSensors; k++) { |
| 5563 | int sensorNumber = in.readInt(); |
| 5564 | Uid.Sensor sensor = new Sensor(sensorNumber); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5565 | sensor.readFromParcelLocked(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5566 | mSensorStats.put(sensorNumber, sensor); |
| 5567 | } |
| 5568 | |
| 5569 | int numProcs = in.readInt(); |
| 5570 | mProcessStats.clear(); |
| 5571 | for (int k = 0; k < numProcs; k++) { |
| 5572 | String processName = in.readString(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5573 | Uid.Proc proc = new Proc(processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | proc.readFromParcelLocked(in); |
| 5575 | mProcessStats.put(processName, proc); |
| 5576 | } |
| 5577 | |
| 5578 | int numPkgs = in.readInt(); |
| 5579 | mPackageStats.clear(); |
| 5580 | for (int l = 0; l < numPkgs; l++) { |
| 5581 | String packageName = in.readString(); |
| 5582 | Uid.Pkg pkg = new Pkg(); |
| 5583 | pkg.readFromParcelLocked(in); |
| 5584 | mPackageStats.put(packageName, pkg); |
| 5585 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5586 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5587 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5588 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5589 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5590 | mWifiRunningTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5591 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5592 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5593 | } |
| 5594 | mFullWifiLockOut = false; |
| 5595 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5596 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5597 | mFullWifiLockTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5598 | } else { |
| 5599 | mFullWifiLockTimer = null; |
| 5600 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5601 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5602 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5603 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5604 | mWifiScanTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5605 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5606 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5607 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5608 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5609 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5610 | if (in.readInt() != 0) { |
| 5611 | makeWifiBatchedScanBin(i, in); |
| 5612 | } else { |
| 5613 | mWifiBatchedScanTimer[i] = null; |
| 5614 | } |
| 5615 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5616 | mWifiMulticastEnabled = false; |
| 5617 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5618 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5619 | mWifiMulticastTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5620 | } else { |
| 5621 | mWifiMulticastTimer = null; |
| 5622 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5623 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5624 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5625 | mAudioTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5626 | } else { |
| 5627 | mAudioTurnedOnTimer = null; |
| 5628 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5629 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5630 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5631 | mVideoTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5632 | } else { |
| 5633 | mVideoTurnedOnTimer = null; |
| 5634 | } |
| 5635 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5636 | mFlashlightTurnedOnTimer = new StopwatchTimer(Uid.this, FLASHLIGHT_TURNED_ON, |
| 5637 | mFlashlightTurnedOnTimers, mOnBatteryTimeBase, in); |
| 5638 | } else { |
| 5639 | mFlashlightTurnedOnTimer = null; |
| 5640 | } |
| 5641 | if (in.readInt() != 0) { |
| 5642 | mCameraTurnedOnTimer = new StopwatchTimer(Uid.this, CAMERA_TURNED_ON, |
| 5643 | mCameraTurnedOnTimers, mOnBatteryTimeBase, in); |
| 5644 | } else { |
| 5645 | mCameraTurnedOnTimer = null; |
| 5646 | } |
| 5647 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5648 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5649 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5650 | } else { |
| 5651 | mForegroundActivityTimer = null; |
| 5652 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5653 | mProcessState = PROCESS_STATE_NONE; |
| 5654 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5655 | if (in.readInt() != 0) { |
| 5656 | makeProcessState(i, in); |
| 5657 | } else { |
| 5658 | mProcessStateTimer[i] = null; |
| 5659 | } |
| 5660 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5661 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5662 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5663 | } else { |
| 5664 | mVibratorOnTimer = null; |
| 5665 | } |
| 5666 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5667 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5668 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5669 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5670 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5671 | } else { |
| 5672 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5673 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5674 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5675 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5676 | mNetworkPacketActivityCounters |
| 5677 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5678 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5679 | mNetworkByteActivityCounters[i] |
| 5680 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5681 | mNetworkPacketActivityCounters[i] |
| 5682 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5683 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5684 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5685 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5686 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5687 | mNetworkByteActivityCounters = null; |
| 5688 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5689 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5690 | |
| 5691 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5692 | if (in.readInt() != 0) { |
| 5693 | mWifiControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5694 | } else { |
| 5695 | mWifiControllerTime[i] = null; |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5700 | if (in.readInt() != 0) { |
| 5701 | mBluetoothControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5702 | } else { |
| 5703 | mBluetoothControllerTime[i] = null; |
| 5704 | } |
| 5705 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5706 | |
| 5707 | mUserCpuTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5708 | mSystemCpuTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5709 | |
| 5710 | int bins = in.readInt(); |
| 5711 | int steps = getCpuSpeedSteps(); |
| 5712 | mSpeedBins = new LongSamplingCounter[bins >= steps ? bins : steps]; |
| 5713 | for (int i = 0; i < bins; i++) { |
| 5714 | if (in.readInt() != 0) { |
| 5715 | mSpeedBins[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5716 | } |
| 5717 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | /** |
| 5721 | * The statistics associated with a particular wake lock. |
| 5722 | */ |
| 5723 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 5724 | /** |
| 5725 | * How long (in ms) this uid has been keeping the device partially awake. |
| 5726 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5727 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5728 | |
| 5729 | /** |
| 5730 | * How long (in ms) this uid has been keeping the device fully awake. |
| 5731 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5732 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | |
| 5734 | /** |
| 5735 | * How long (in ms) this uid has had a window keeping the device awake. |
| 5736 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5737 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | |
| 5739 | /** |
| 5740 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 5741 | * proper timer pool from the given BatteryStatsImpl object. |
| 5742 | * |
| 5743 | * @param in the Parcel to be read from. |
| 5744 | * return a new Timer, or null. |
| 5745 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5746 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5747 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | if (in.readInt() == 0) { |
| 5749 | return null; |
| 5750 | } |
| 5751 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5752 | return new StopwatchTimer(Uid.this, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | } |
| 5754 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5755 | boolean reset() { |
| 5756 | boolean wlactive = false; |
| 5757 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5758 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5759 | } |
| 5760 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5761 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5762 | } |
| 5763 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5764 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5765 | } |
| 5766 | if (!wlactive) { |
| 5767 | if (mTimerFull != null) { |
| 5768 | mTimerFull.detach(); |
| 5769 | mTimerFull = null; |
| 5770 | } |
| 5771 | if (mTimerPartial != null) { |
| 5772 | mTimerPartial.detach(); |
| 5773 | mTimerPartial = null; |
| 5774 | } |
| 5775 | if (mTimerWindow != null) { |
| 5776 | mTimerWindow.detach(); |
| 5777 | mTimerWindow = null; |
| 5778 | } |
| 5779 | } |
| 5780 | return !wlactive; |
| 5781 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5782 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5783 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5785 | mPartialTimers, screenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5786 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5787 | mFullTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5788 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5789 | mWindowTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5790 | } |
| 5791 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5792 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5793 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 5794 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 5795 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | @Override |
| 5799 | public Timer getWakeTime(int type) { |
| 5800 | switch (type) { |
| 5801 | case WAKE_TYPE_FULL: return mTimerFull; |
| 5802 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 5803 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
| 5804 | default: throw new IllegalArgumentException("type = " + type); |
| 5805 | } |
| 5806 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5807 | |
| 5808 | public StopwatchTimer getStopwatchTimer(int type) { |
| 5809 | StopwatchTimer t; |
| 5810 | switch (type) { |
| 5811 | case WAKE_TYPE_PARTIAL: |
| 5812 | t = mTimerPartial; |
| 5813 | if (t == null) { |
| 5814 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
| 5815 | mPartialTimers, mOnBatteryScreenOffTimeBase); |
| 5816 | mTimerPartial = t; |
| 5817 | } |
| 5818 | return t; |
| 5819 | case WAKE_TYPE_FULL: |
| 5820 | t = mTimerFull; |
| 5821 | if (t == null) { |
| 5822 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
| 5823 | mFullTimers, mOnBatteryTimeBase); |
| 5824 | mTimerFull = t; |
| 5825 | } |
| 5826 | return t; |
| 5827 | case WAKE_TYPE_WINDOW: |
| 5828 | t = mTimerWindow; |
| 5829 | if (t == null) { |
| 5830 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
| 5831 | mWindowTimers, mOnBatteryTimeBase); |
| 5832 | mTimerWindow = t; |
| 5833 | } |
| 5834 | return t; |
| 5835 | default: |
| 5836 | throw new IllegalArgumentException("type=" + type); |
| 5837 | } |
| 5838 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 5842 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5843 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5845 | public Sensor(int handle) { |
| 5846 | mHandle = handle; |
| 5847 | } |
| 5848 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5849 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | if (in.readInt() == 0) { |
| 5851 | return null; |
| 5852 | } |
| 5853 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5854 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5856 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | mSensorTimers.put(mHandle, pool); |
| 5858 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5859 | return new StopwatchTimer(Uid.this, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | } |
| 5861 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5862 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5863 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5864 | mTimer = null; |
| 5865 | return true; |
| 5866 | } |
| 5867 | return false; |
| 5868 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5869 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5870 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 5871 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | } |
| 5873 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5874 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5875 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | @Override |
| 5879 | public Timer getSensorTime() { |
| 5880 | return mTimer; |
| 5881 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5882 | |
| 5883 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5884 | public int getHandle() { |
| 5885 | return mHandle; |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | /** |
| 5890 | * The statistics associated with a particular process. |
| 5891 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5892 | public final class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5894 | * The name of this process. |
| 5895 | */ |
| 5896 | final String mName; |
| 5897 | |
| 5898 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5899 | * Remains true until removed from the stats. |
| 5900 | */ |
| 5901 | boolean mActive = true; |
| 5902 | |
| 5903 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5904 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5905 | */ |
| 5906 | long mUserTime; |
| 5907 | |
| 5908 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5909 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | */ |
| 5911 | long mSystemTime; |
| 5912 | |
| 5913 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5914 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5915 | */ |
| 5916 | long mForegroundTime; |
| 5917 | |
| 5918 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5919 | * Number of times the process has been started. |
| 5920 | */ |
| 5921 | int mStarts; |
| 5922 | |
| 5923 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5924 | * Number of times the process has crashed. |
| 5925 | */ |
| 5926 | int mNumCrashes; |
| 5927 | |
| 5928 | /** |
| 5929 | * Number of times the process has had an ANR. |
| 5930 | */ |
| 5931 | int mNumAnrs; |
| 5932 | |
| 5933 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | * The amount of user time loaded from a previous save. |
| 5935 | */ |
| 5936 | long mLoadedUserTime; |
| 5937 | |
| 5938 | /** |
| 5939 | * The amount of system time loaded from a previous save. |
| 5940 | */ |
| 5941 | long mLoadedSystemTime; |
| 5942 | |
| 5943 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5944 | * The amount of foreground time loaded from a previous save. |
| 5945 | */ |
| 5946 | long mLoadedForegroundTime; |
| 5947 | |
| 5948 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5949 | * The number of times the process has started from a previous save. |
| 5950 | */ |
| 5951 | int mLoadedStarts; |
| 5952 | |
| 5953 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5954 | * Number of times the process has crashed from a previous save. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5955 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5956 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5957 | |
| 5958 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5959 | * Number of times the process has had an ANR from a previous save. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5961 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5962 | |
| 5963 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5964 | * The amount of user time when last unplugged. |
| 5965 | */ |
| 5966 | long mUnpluggedUserTime; |
| 5967 | |
| 5968 | /** |
| 5969 | * The amount of system time when last unplugged. |
| 5970 | */ |
| 5971 | long mUnpluggedSystemTime; |
| 5972 | |
| 5973 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5974 | * The amount of foreground time since unplugged. |
| 5975 | */ |
| 5976 | long mUnpluggedForegroundTime; |
| 5977 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5978 | /** |
| 5979 | * The number of times the process has started before unplugged. |
| 5980 | */ |
| 5981 | int mUnpluggedStarts; |
| 5982 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5983 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5984 | * Number of times the process has crashed before unplugged. |
| 5985 | */ |
| 5986 | int mUnpluggedNumCrashes; |
| 5987 | |
| 5988 | /** |
| 5989 | * Number of times the process has had an ANR before unplugged. |
| 5990 | */ |
| 5991 | int mUnpluggedNumAnrs; |
| 5992 | |
| 5993 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5994 | * Current process state. |
| 5995 | */ |
| 5996 | int mProcessState = PROCESS_STATE_NONE; |
| 5997 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5998 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5999 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6000 | Proc(String name) { |
| 6001 | mName = name; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6002 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6004 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6005 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | mUnpluggedUserTime = mUserTime; |
| 6007 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6008 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6009 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6010 | mUnpluggedNumCrashes = mNumCrashes; |
| 6011 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6012 | } |
| 6013 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6014 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6015 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6016 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6017 | void reset() { |
| 6018 | mUserTime = mSystemTime = mForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6019 | mStarts = mNumCrashes = mNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6020 | mLoadedUserTime = mLoadedSystemTime = mLoadedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6021 | mLoadedStarts = mLoadedNumCrashes = mLoadedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6022 | mUnpluggedUserTime = mUnpluggedSystemTime = mUnpluggedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6023 | mUnpluggedStarts = mUnpluggedNumCrashes = mUnpluggedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6024 | mExcessivePower = null; |
| 6025 | } |
| 6026 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6027 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6028 | mActive = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6029 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6030 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6031 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6032 | public int countExcessivePowers() { |
| 6033 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6036 | public ExcessivePower getExcessivePower(int i) { |
| 6037 | if (mExcessivePower != null) { |
| 6038 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6039 | } |
| 6040 | return null; |
| 6041 | } |
| 6042 | |
| 6043 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6044 | if (mExcessivePower == null) { |
| 6045 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6046 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6047 | ExcessivePower ew = new ExcessivePower(); |
| 6048 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6049 | ew.overTime = overTime; |
| 6050 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6051 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6052 | } |
| 6053 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6054 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 6055 | if (mExcessivePower == null) { |
| 6056 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 6057 | } |
| 6058 | ExcessivePower ew = new ExcessivePower(); |
| 6059 | ew.type = ExcessivePower.TYPE_CPU; |
| 6060 | ew.overTime = overTime; |
| 6061 | ew.usedTime = usedTime; |
| 6062 | mExcessivePower.add(ew); |
| 6063 | } |
| 6064 | |
| 6065 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 6066 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6067 | out.writeInt(0); |
| 6068 | return; |
| 6069 | } |
| 6070 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6071 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6072 | out.writeInt(N); |
| 6073 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6074 | ExcessivePower ew = mExcessivePower.get(i); |
| 6075 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6076 | out.writeLong(ew.overTime); |
| 6077 | out.writeLong(ew.usedTime); |
| 6078 | } |
| 6079 | } |
| 6080 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6081 | boolean readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6082 | final int N = in.readInt(); |
| 6083 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6084 | mExcessivePower = null; |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6085 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6086 | } |
| 6087 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6088 | if (N > 10000) { |
| 6089 | Slog.w(TAG, "File corrupt: too many excessive power entries " + N); |
| 6090 | return false; |
| 6091 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6092 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6093 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6094 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6095 | ExcessivePower ew = new ExcessivePower(); |
| 6096 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6097 | ew.overTime = in.readLong(); |
| 6098 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6099 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6100 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6101 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6102 | } |
| 6103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6104 | void writeToParcelLocked(Parcel out) { |
| 6105 | out.writeLong(mUserTime); |
| 6106 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6107 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6109 | out.writeInt(mNumCrashes); |
| 6110 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | out.writeLong(mLoadedUserTime); |
| 6112 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6113 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6114 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6115 | out.writeInt(mLoadedNumCrashes); |
| 6116 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6117 | out.writeLong(mUnpluggedUserTime); |
| 6118 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6119 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6121 | out.writeInt(mUnpluggedNumCrashes); |
| 6122 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6123 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | void readFromParcelLocked(Parcel in) { |
| 6127 | mUserTime = in.readLong(); |
| 6128 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6129 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6130 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6131 | mNumCrashes = in.readInt(); |
| 6132 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6133 | mLoadedUserTime = in.readLong(); |
| 6134 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6135 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6136 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6137 | mLoadedNumCrashes = in.readInt(); |
| 6138 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6139 | mUnpluggedUserTime = in.readLong(); |
| 6140 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6141 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6142 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6143 | mUnpluggedNumCrashes = in.readInt(); |
| 6144 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6145 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6148 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6149 | mUserTime += utime; |
| 6150 | mSystemTime += stime; |
| 6151 | } |
| 6152 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6153 | public void addForegroundTimeLocked(long ttime) { |
| 6154 | mForegroundTime += ttime; |
| 6155 | } |
| 6156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6157 | public void incStartsLocked() { |
| 6158 | mStarts++; |
| 6159 | } |
| 6160 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6161 | public void incNumCrashesLocked() { |
| 6162 | mNumCrashes++; |
| 6163 | } |
| 6164 | |
| 6165 | public void incNumAnrsLocked() { |
| 6166 | mNumAnrs++; |
| 6167 | } |
| 6168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6169 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6170 | public boolean isActive() { |
| 6171 | return mActive; |
| 6172 | } |
| 6173 | |
| 6174 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6176 | long val = mUserTime; |
| 6177 | if (which == STATS_CURRENT) { |
| 6178 | val -= mLoadedUserTime; |
| 6179 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6180 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6181 | } |
| 6182 | return val; |
| 6183 | } |
| 6184 | |
| 6185 | @Override |
| 6186 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6187 | long val = mSystemTime; |
| 6188 | if (which == STATS_CURRENT) { |
| 6189 | val -= mLoadedSystemTime; |
| 6190 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6191 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6192 | } |
| 6193 | return val; |
| 6194 | } |
| 6195 | |
| 6196 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6197 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6198 | long val = mForegroundTime; |
| 6199 | if (which == STATS_CURRENT) { |
| 6200 | val -= mLoadedForegroundTime; |
| 6201 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6202 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6203 | } |
| 6204 | return val; |
| 6205 | } |
| 6206 | |
| 6207 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6208 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6209 | int val = mStarts; |
| 6210 | if (which == STATS_CURRENT) { |
| 6211 | val -= mLoadedStarts; |
| 6212 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6213 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6214 | } |
| 6215 | return val; |
| 6216 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6217 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6218 | @Override |
| 6219 | public int getNumCrashes(int which) { |
| 6220 | int val = mNumCrashes; |
| 6221 | if (which == STATS_CURRENT) { |
| 6222 | val -= mLoadedNumCrashes; |
| 6223 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6224 | val -= mUnpluggedNumCrashes; |
| 6225 | } |
| 6226 | return val; |
| 6227 | } |
| 6228 | |
| 6229 | @Override |
| 6230 | public int getNumAnrs(int which) { |
| 6231 | int val = mNumAnrs; |
| 6232 | if (which == STATS_CURRENT) { |
| 6233 | val -= mLoadedNumAnrs; |
| 6234 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6235 | val -= mUnpluggedNumAnrs; |
| 6236 | } |
| 6237 | return val; |
| 6238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | /** |
| 6242 | * The statistics associated with a particular package. |
| 6243 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6244 | public final class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6246 | * Number of times wakeup alarms have occurred for this app. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6248 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6249 | |
| 6250 | /** |
| 6251 | * The statics we have collected for this package's services. |
| 6252 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6253 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | |
| 6255 | Pkg() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6256 | mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6258 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6259 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6260 | } |
| 6261 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6262 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6264 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6265 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6266 | mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6267 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6269 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6270 | int numWA = in.readInt(); |
| 6271 | mWakeupAlarms.clear(); |
| 6272 | for (int i=0; i<numWA; i++) { |
| 6273 | String tag = in.readString(); |
| 6274 | mWakeupAlarms.put(tag, new Counter(mOnBatteryTimeBase, in)); |
| 6275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | |
| 6277 | int numServs = in.readInt(); |
| 6278 | mServiceStats.clear(); |
| 6279 | for (int m = 0; m < numServs; m++) { |
| 6280 | String serviceName = in.readString(); |
| 6281 | Uid.Pkg.Serv serv = new Serv(); |
| 6282 | mServiceStats.put(serviceName, serv); |
| 6283 | |
| 6284 | serv.readFromParcelLocked(in); |
| 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6289 | int numWA = mWakeupAlarms.size(); |
| 6290 | out.writeInt(numWA); |
| 6291 | for (int i=0; i<numWA; i++) { |
| 6292 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6293 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6295 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6296 | final int NS = mServiceStats.size(); |
| 6297 | out.writeInt(NS); |
| 6298 | for (int i=0; i<NS; i++) { |
| 6299 | out.writeString(mServiceStats.keyAt(i)); |
| 6300 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6301 | serv.writeToParcelLocked(out); |
| 6302 | } |
| 6303 | } |
| 6304 | |
| 6305 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6306 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6307 | return mWakeupAlarms; |
| 6308 | } |
| 6309 | |
| 6310 | public void noteWakeupAlarmLocked(String tag) { |
| 6311 | Counter c = mWakeupAlarms.get(tag); |
| 6312 | if (c == null) { |
| 6313 | c = new Counter(mOnBatteryTimeBase); |
| 6314 | mWakeupAlarms.put(tag, c); |
| 6315 | } |
| 6316 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6317 | } |
| 6318 | |
| 6319 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6320 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6321 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | /** |
| 6325 | * The statistics associated with a particular service. |
| 6326 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6327 | public final class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6328 | /** |
| 6329 | * Total time (ms in battery uptime) the service has been left started. |
| 6330 | */ |
| 6331 | long mStartTime; |
| 6332 | |
| 6333 | /** |
| 6334 | * If service has been started and not yet stopped, this is |
| 6335 | * when it was started. |
| 6336 | */ |
| 6337 | long mRunningSince; |
| 6338 | |
| 6339 | /** |
| 6340 | * True if we are currently running. |
| 6341 | */ |
| 6342 | boolean mRunning; |
| 6343 | |
| 6344 | /** |
| 6345 | * Total number of times startService() has been called. |
| 6346 | */ |
| 6347 | int mStarts; |
| 6348 | |
| 6349 | /** |
| 6350 | * Total time (ms in battery uptime) the service has been left launched. |
| 6351 | */ |
| 6352 | long mLaunchedTime; |
| 6353 | |
| 6354 | /** |
| 6355 | * If service has been launched and not yet exited, this is |
| 6356 | * when it was launched (ms in battery uptime). |
| 6357 | */ |
| 6358 | long mLaunchedSince; |
| 6359 | |
| 6360 | /** |
| 6361 | * True if we are currently launched. |
| 6362 | */ |
| 6363 | boolean mLaunched; |
| 6364 | |
| 6365 | /** |
| 6366 | * Total number times the service has been launched. |
| 6367 | */ |
| 6368 | int mLaunches; |
| 6369 | |
| 6370 | /** |
| 6371 | * The amount of time spent started loaded from a previous save |
| 6372 | * (ms in battery uptime). |
| 6373 | */ |
| 6374 | long mLoadedStartTime; |
| 6375 | |
| 6376 | /** |
| 6377 | * The number of starts loaded from a previous save. |
| 6378 | */ |
| 6379 | int mLoadedStarts; |
| 6380 | |
| 6381 | /** |
| 6382 | * The number of launches loaded from a previous save. |
| 6383 | */ |
| 6384 | int mLoadedLaunches; |
| 6385 | |
| 6386 | /** |
| 6387 | * The amount of time spent started as of the last run (ms |
| 6388 | * in battery uptime). |
| 6389 | */ |
| 6390 | long mLastStartTime; |
| 6391 | |
| 6392 | /** |
| 6393 | * The number of starts as of the last run. |
| 6394 | */ |
| 6395 | int mLastStarts; |
| 6396 | |
| 6397 | /** |
| 6398 | * The number of launches as of the last run. |
| 6399 | */ |
| 6400 | int mLastLaunches; |
| 6401 | |
| 6402 | /** |
| 6403 | * The amount of time spent started when last unplugged (ms |
| 6404 | * in battery uptime). |
| 6405 | */ |
| 6406 | long mUnpluggedStartTime; |
| 6407 | |
| 6408 | /** |
| 6409 | * The number of starts when last unplugged. |
| 6410 | */ |
| 6411 | int mUnpluggedStarts; |
| 6412 | |
| 6413 | /** |
| 6414 | * The number of launches when last unplugged. |
| 6415 | */ |
| 6416 | int mUnpluggedLaunches; |
| 6417 | |
| 6418 | Serv() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6419 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6421 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6422 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 6423 | long baseRealtime) { |
| 6424 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6425 | mUnpluggedStarts = mStarts; |
| 6426 | mUnpluggedLaunches = mLaunches; |
| 6427 | } |
| 6428 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6429 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 6430 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6432 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6433 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6434 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6435 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | void readFromParcelLocked(Parcel in) { |
| 6438 | mStartTime = in.readLong(); |
| 6439 | mRunningSince = in.readLong(); |
| 6440 | mRunning = in.readInt() != 0; |
| 6441 | mStarts = in.readInt(); |
| 6442 | mLaunchedTime = in.readLong(); |
| 6443 | mLaunchedSince = in.readLong(); |
| 6444 | mLaunched = in.readInt() != 0; |
| 6445 | mLaunches = in.readInt(); |
| 6446 | mLoadedStartTime = in.readLong(); |
| 6447 | mLoadedStarts = in.readInt(); |
| 6448 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6449 | mLastStartTime = 0; |
| 6450 | mLastStarts = 0; |
| 6451 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | mUnpluggedStartTime = in.readLong(); |
| 6453 | mUnpluggedStarts = in.readInt(); |
| 6454 | mUnpluggedLaunches = in.readInt(); |
| 6455 | } |
| 6456 | |
| 6457 | void writeToParcelLocked(Parcel out) { |
| 6458 | out.writeLong(mStartTime); |
| 6459 | out.writeLong(mRunningSince); |
| 6460 | out.writeInt(mRunning ? 1 : 0); |
| 6461 | out.writeInt(mStarts); |
| 6462 | out.writeLong(mLaunchedTime); |
| 6463 | out.writeLong(mLaunchedSince); |
| 6464 | out.writeInt(mLaunched ? 1 : 0); |
| 6465 | out.writeInt(mLaunches); |
| 6466 | out.writeLong(mLoadedStartTime); |
| 6467 | out.writeInt(mLoadedStarts); |
| 6468 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6469 | out.writeLong(mUnpluggedStartTime); |
| 6470 | out.writeInt(mUnpluggedStarts); |
| 6471 | out.writeInt(mUnpluggedLaunches); |
| 6472 | } |
| 6473 | |
| 6474 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 6475 | if (!mLaunched) return mLaunchedTime; |
| 6476 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 6477 | } |
| 6478 | |
| 6479 | long getStartTimeToNowLocked(long batteryUptime) { |
| 6480 | if (!mRunning) return mStartTime; |
| 6481 | return mStartTime + batteryUptime - mRunningSince; |
| 6482 | } |
| 6483 | |
| 6484 | public void startLaunchedLocked() { |
| 6485 | if (!mLaunched) { |
| 6486 | mLaunches++; |
| 6487 | mLaunchedSince = getBatteryUptimeLocked(); |
| 6488 | mLaunched = true; |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | public void stopLaunchedLocked() { |
| 6493 | if (mLaunched) { |
| 6494 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 6495 | if (time > 0) { |
| 6496 | mLaunchedTime += time; |
| 6497 | } else { |
| 6498 | mLaunches--; |
| 6499 | } |
| 6500 | mLaunched = false; |
| 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | public void startRunningLocked() { |
| 6505 | if (!mRunning) { |
| 6506 | mStarts++; |
| 6507 | mRunningSince = getBatteryUptimeLocked(); |
| 6508 | mRunning = true; |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | public void stopRunningLocked() { |
| 6513 | if (mRunning) { |
| 6514 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 6515 | if (time > 0) { |
| 6516 | mStartTime += time; |
| 6517 | } else { |
| 6518 | mStarts--; |
| 6519 | } |
| 6520 | mRunning = false; |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | public BatteryStatsImpl getBatteryStats() { |
| 6525 | return BatteryStatsImpl.this; |
| 6526 | } |
| 6527 | |
| 6528 | @Override |
| 6529 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6530 | int val = mLaunches; |
| 6531 | if (which == STATS_CURRENT) { |
| 6532 | val -= mLoadedLaunches; |
| 6533 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6534 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6536 | return val; |
| 6537 | } |
| 6538 | |
| 6539 | @Override |
| 6540 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6541 | long val = getStartTimeToNowLocked(now); |
| 6542 | if (which == STATS_CURRENT) { |
| 6543 | val -= mLoadedStartTime; |
| 6544 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6545 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | return val; |
| 6548 | } |
| 6549 | |
| 6550 | @Override |
| 6551 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6552 | int val = mStarts; |
| 6553 | if (which == STATS_CURRENT) { |
| 6554 | val -= mLoadedStarts; |
| 6555 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6556 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6557 | } |
| 6558 | |
| 6559 | return val; |
| 6560 | } |
| 6561 | } |
| 6562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6563 | final Serv newServiceStatsLocked() { |
| 6564 | return new Serv(); |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | /** |
| 6569 | * Retrieve the statistics object for a particular process, creating |
| 6570 | * if needed. |
| 6571 | */ |
| 6572 | public Proc getProcessStatsLocked(String name) { |
| 6573 | Proc ps = mProcessStats.get(name); |
| 6574 | if (ps == null) { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6575 | ps = new Proc(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6576 | mProcessStats.put(name, ps); |
| 6577 | } |
| 6578 | |
| 6579 | return ps; |
| 6580 | } |
| 6581 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6582 | public void updateProcessStateLocked(String procName, int state, long elapsedRealtimeMs) { |
| 6583 | int procState; |
| 6584 | if (state <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 6585 | procState = PROCESS_STATE_FOREGROUND; |
| 6586 | } else if (state <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 6587 | procState = PROCESS_STATE_ACTIVE; |
| 6588 | } else { |
| 6589 | procState = PROCESS_STATE_RUNNING; |
| 6590 | } |
| 6591 | updateRealProcessStateLocked(procName, procState, elapsedRealtimeMs); |
| 6592 | } |
| 6593 | |
| 6594 | public void updateRealProcessStateLocked(String procName, int procState, |
| 6595 | long elapsedRealtimeMs) { |
| 6596 | Proc proc = getProcessStatsLocked(procName); |
| 6597 | if (proc.mProcessState != procState) { |
| 6598 | boolean changed; |
| 6599 | if (procState < proc.mProcessState) { |
| 6600 | // Has this process become more important? If so, |
| 6601 | // we may need to change the uid if the currrent uid proc state |
| 6602 | // is not as important as what we are now setting. |
| 6603 | changed = mProcessState > procState; |
| 6604 | } else { |
| 6605 | // Has this process become less important? If so, |
| 6606 | // we may need to change the uid if the current uid proc state |
| 6607 | // is the same importance as the old setting. |
| 6608 | changed = mProcessState == proc.mProcessState; |
| 6609 | } |
| 6610 | proc.mProcessState = procState; |
| 6611 | if (changed) { |
| 6612 | // uid's state may have changed; compute what the new state should be. |
| 6613 | int uidProcState = PROCESS_STATE_NONE; |
| 6614 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6615 | proc = mProcessStats.valueAt(ip); |
| 6616 | if (proc.mProcessState < uidProcState) { |
| 6617 | uidProcState = proc.mProcessState; |
| 6618 | } |
| 6619 | } |
| 6620 | updateUidProcessStateLocked(uidProcState, elapsedRealtimeMs); |
| 6621 | } |
| 6622 | } |
| 6623 | } |
| 6624 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6625 | public SparseArray<? extends Pid> getPidStats() { |
| 6626 | return mPids; |
| 6627 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6628 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6629 | public Pid getPidStatsLocked(int pid) { |
| 6630 | Pid p = mPids.get(pid); |
| 6631 | if (p == null) { |
| 6632 | p = new Pid(); |
| 6633 | mPids.put(pid, p); |
| 6634 | } |
| 6635 | return p; |
| 6636 | } |
| 6637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6638 | /** |
| 6639 | * Retrieve the statistics object for a particular service, creating |
| 6640 | * if needed. |
| 6641 | */ |
| 6642 | public Pkg getPackageStatsLocked(String name) { |
| 6643 | Pkg ps = mPackageStats.get(name); |
| 6644 | if (ps == null) { |
| 6645 | ps = new Pkg(); |
| 6646 | mPackageStats.put(name, ps); |
| 6647 | } |
| 6648 | |
| 6649 | return ps; |
| 6650 | } |
| 6651 | |
| 6652 | /** |
| 6653 | * Retrieve the statistics object for a particular service, creating |
| 6654 | * if needed. |
| 6655 | */ |
| 6656 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 6657 | Pkg ps = getPackageStatsLocked(pkg); |
| 6658 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 6659 | if (ss == null) { |
| 6660 | ss = ps.newServiceStatsLocked(); |
| 6661 | ps.mServiceStats.put(serv, ss); |
| 6662 | } |
| 6663 | |
| 6664 | return ss; |
| 6665 | } |
| 6666 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6667 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 6668 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 6669 | timer.readSummaryFromParcelLocked(in); |
| 6670 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6671 | } |
| 6672 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6673 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 6674 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 6675 | timer.readSummaryFromParcelLocked(in); |
| 6676 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6677 | } |
| 6678 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6679 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
| 6680 | Wakelock wl = new Wakelock(); |
| 6681 | mWakelockStats.add(wlName, wl); |
| 6682 | if (in.readInt() != 0) { |
| 6683 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6684 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6685 | if (in.readInt() != 0) { |
| 6686 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 6687 | } |
| 6688 | if (in.readInt() != 0) { |
| 6689 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6690 | } |
| 6691 | } |
| 6692 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6693 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | Sensor se = mSensorStats.get(sensor); |
| 6695 | if (se == null) { |
| 6696 | if (!create) { |
| 6697 | return null; |
| 6698 | } |
| 6699 | se = new Sensor(sensor); |
| 6700 | mSensorStats.put(sensor, se); |
| 6701 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6702 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6703 | if (t != null) { |
| 6704 | return t; |
| 6705 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6706 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6707 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6708 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | mSensorTimers.put(sensor, timers); |
| 6710 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6711 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | se.mTimer = t; |
| 6713 | return t; |
| 6714 | } |
| 6715 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6716 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6717 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6718 | if (t != null) { |
| 6719 | t.startRunningLocked(elapsedRealtimeMs); |
| 6720 | } |
| 6721 | } |
| 6722 | |
| 6723 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6724 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6725 | if (t != null) { |
| 6726 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 6731 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6732 | if (t != null) { |
| 6733 | t.startRunningLocked(elapsedRealtimeMs); |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6738 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6739 | if (t != null) { |
| 6740 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6741 | } |
| 6742 | } |
| 6743 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6744 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6745 | Wakelock wl = mWakelockStats.startObject(name); |
| 6746 | if (wl != null) { |
| 6747 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6749 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6750 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6751 | if (p.mWakeNesting++ == 0) { |
| 6752 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 6753 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6754 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6755 | } |
| 6756 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6757 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6758 | Wakelock wl = mWakelockStats.stopObject(name); |
| 6759 | if (wl != null) { |
| 6760 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6761 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6762 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6763 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6764 | if (p != null && p.mWakeNesting > 0) { |
| 6765 | if (p.mWakeNesting-- == 1) { |
| 6766 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 6767 | p.mWakeStartMs = 0; |
| 6768 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6769 | } |
| 6770 | } |
| 6771 | } |
| 6772 | |
| 6773 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 6774 | Proc p = getProcessStatsLocked(proc); |
| 6775 | if (p != null) { |
| 6776 | p.addExcessiveWake(overTime, usedTime); |
| 6777 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6779 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6780 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 6781 | Proc p = getProcessStatsLocked(proc); |
| 6782 | if (p != null) { |
| 6783 | p.addExcessiveCpu(overTime, usedTime); |
| 6784 | } |
| 6785 | } |
| 6786 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6787 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6788 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6789 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6790 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6791 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6792 | } |
| 6793 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6794 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6796 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6798 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6801 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6802 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6803 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6805 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6806 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6808 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6809 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6810 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6812 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | } |
| 6815 | |
| 6816 | public BatteryStatsImpl getBatteryStats() { |
| 6817 | return BatteryStatsImpl.this; |
| 6818 | } |
| 6819 | } |
| 6820 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6821 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6822 | if (systemDir != null) { |
| 6823 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 6824 | new File(systemDir, "batterystats.bin.tmp")); |
| 6825 | } else { |
| 6826 | mFile = null; |
| 6827 | } |
| 6828 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6829 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6830 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 6831 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6832 | mStartCount++; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6833 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6834 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6835 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6836 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6837 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase); |
| 6838 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase); |
| 6839 | mDeviceIdleModeEnabledTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6840 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6841 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6842 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6843 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, |
| 6844 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6845 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6846 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6847 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6848 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, |
| 6849 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6850 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6851 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6852 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6853 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6854 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6855 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 6856 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6857 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6858 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6859 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); |
| 6860 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6861 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6862 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6863 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6864 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase); |
| 6865 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6866 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6867 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6868 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6869 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 6870 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, null, mOnBatteryTimeBase); |
| 6871 | } |
| 6872 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 6873 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, null, |
| 6874 | mOnBatteryTimeBase); |
| 6875 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6876 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
| 6877 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6878 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6879 | mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6881 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 6882 | long realtime = SystemClock.elapsedRealtime() * 1000; |
| 6883 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6884 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6885 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6886 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6887 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6888 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6889 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6890 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6891 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6892 | updateDailyDeadlineLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6896 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6897 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6898 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6899 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6900 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6901 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | readFromParcel(p); |
| 6903 | } |
| 6904 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6905 | public void setPowerProfile(PowerProfile profile) { |
| 6906 | synchronized (this) { |
| 6907 | mPowerProfile = profile; |
| 6908 | } |
| 6909 | } |
| 6910 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6911 | public void setCallback(BatteryCallback cb) { |
| 6912 | mCallback = cb; |
| 6913 | } |
| 6914 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6915 | public void setNumSpeedSteps(int steps) { |
| 6916 | if (sNumSpeedSteps == 0) sNumSpeedSteps = steps; |
| 6917 | } |
| 6918 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6919 | public void setRadioScanningTimeout(long timeout) { |
| 6920 | if (mPhoneSignalScanningTimer != null) { |
| 6921 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 6922 | } |
| 6923 | } |
| 6924 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6925 | public void updateDailyDeadlineLocked() { |
| 6926 | // Get the current time. |
| 6927 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 6928 | Calendar calDeadline = Calendar.getInstance(); |
| 6929 | calDeadline.setTimeInMillis(currentTime); |
| 6930 | |
| 6931 | // Move time up to the next day, ranging from 1am to 3pm. |
| 6932 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 6933 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 6934 | calDeadline.set(Calendar.SECOND, 0); |
| 6935 | calDeadline.set(Calendar.MINUTE, 0); |
| 6936 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 6937 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 6938 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 6939 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 6940 | } |
| 6941 | |
| 6942 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 6943 | long currentTime = System.currentTimeMillis(); |
| 6944 | if (currentTime >= mNextMaxDailyDeadline) { |
| 6945 | recordDailyStatsLocked(); |
| 6946 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 6947 | recordDailyStatsLocked(); |
| 6948 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 6949 | recordDailyStatsLocked(); |
| 6950 | } |
| 6951 | } |
| 6952 | |
| 6953 | public void recordDailyStatsLocked() { |
| 6954 | DailyItem item = new DailyItem(); |
| 6955 | item.mStartTime = mDailyStartTime; |
| 6956 | item.mEndTime = System.currentTimeMillis(); |
| 6957 | boolean hasData = false; |
| 6958 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 6959 | hasData = true; |
| 6960 | item.mDischargeSteps = new LevelStepTracker( |
| 6961 | mDailyDischargeStepTracker.mNumStepDurations, |
| 6962 | mDailyDischargeStepTracker.mStepDurations); |
| 6963 | } |
| 6964 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 6965 | hasData = true; |
| 6966 | item.mChargeSteps = new LevelStepTracker( |
| 6967 | mDailyChargeStepTracker.mNumStepDurations, |
| 6968 | mDailyChargeStepTracker.mStepDurations); |
| 6969 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6970 | if (mDailyPackageChanges != null) { |
| 6971 | hasData = true; |
| 6972 | item.mPackageChanges = mDailyPackageChanges; |
| 6973 | mDailyPackageChanges = null; |
| 6974 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6975 | mDailyDischargeStepTracker.init(); |
| 6976 | mDailyChargeStepTracker.init(); |
| 6977 | updateDailyDeadlineLocked(); |
| 6978 | |
| 6979 | if (hasData) { |
| 6980 | mDailyItems.add(item); |
| 6981 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 6982 | mDailyItems.remove(0); |
| 6983 | } |
| 6984 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 6985 | try { |
| 6986 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 6987 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6988 | writeDailyItemsLocked(out); |
| 6989 | BackgroundThread.getHandler().post(new Runnable() { |
| 6990 | @Override |
| 6991 | public void run() { |
| 6992 | synchronized (mCheckinFile) { |
| 6993 | FileOutputStream stream = null; |
| 6994 | try { |
| 6995 | stream = mDailyFile.startWrite(); |
| 6996 | memStream.writeTo(stream); |
| 6997 | stream.flush(); |
| 6998 | FileUtils.sync(stream); |
| 6999 | stream.close(); |
| 7000 | mDailyFile.finishWrite(stream); |
| 7001 | } catch (IOException e) { |
| 7002 | Slog.w("BatteryStats", |
| 7003 | "Error writing battery daily items", e); |
| 7004 | mDailyFile.failWrite(stream); |
| 7005 | } |
| 7006 | } |
| 7007 | } |
| 7008 | }); |
| 7009 | } catch (IOException e) { |
| 7010 | } |
| 7011 | } |
| 7012 | } |
| 7013 | |
| 7014 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 7015 | StringBuilder sb = new StringBuilder(64); |
| 7016 | out.startDocument(null, true); |
| 7017 | out.startTag(null, "daily-items"); |
| 7018 | for (int i=0; i<mDailyItems.size(); i++) { |
| 7019 | final DailyItem dit = mDailyItems.get(i); |
| 7020 | out.startTag(null, "item"); |
| 7021 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 7022 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 7023 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 7024 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7025 | if (dit.mPackageChanges != null) { |
| 7026 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 7027 | PackageChange pc = dit.mPackageChanges.get(j); |
| 7028 | if (pc.mUpdate) { |
| 7029 | out.startTag(null, "upd"); |
| 7030 | out.attribute(null, "pkg", pc.mPackageName); |
| 7031 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 7032 | out.endTag(null, "upd"); |
| 7033 | } else { |
| 7034 | out.startTag(null, "rem"); |
| 7035 | out.attribute(null, "pkg", pc.mPackageName); |
| 7036 | out.endTag(null, "rem"); |
| 7037 | } |
| 7038 | } |
| 7039 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7040 | out.endTag(null, "item"); |
| 7041 | } |
| 7042 | out.endTag(null, "daily-items"); |
| 7043 | out.endDocument(); |
| 7044 | } |
| 7045 | |
| 7046 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 7047 | StringBuilder tmpBuilder) throws IOException { |
| 7048 | if (steps != null) { |
| 7049 | out.startTag(null, tag); |
| 7050 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 7051 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 7052 | out.startTag(null, "s"); |
| 7053 | tmpBuilder.setLength(0); |
| 7054 | steps.encodeEntryAt(i, tmpBuilder); |
| 7055 | out.attribute(null, "v", tmpBuilder.toString()); |
| 7056 | out.endTag(null, "s"); |
| 7057 | } |
| 7058 | out.endTag(null, tag); |
| 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | public void readDailyStatsLocked() { |
| 7063 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 7064 | mDailyItems.clear(); |
| 7065 | FileInputStream stream; |
| 7066 | try { |
| 7067 | stream = mDailyFile.openRead(); |
| 7068 | } catch (FileNotFoundException e) { |
| 7069 | return; |
| 7070 | } |
| 7071 | try { |
| 7072 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7073 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7074 | readDailyItemsLocked(parser); |
| 7075 | } catch (XmlPullParserException e) { |
| 7076 | } finally { |
| 7077 | try { |
| 7078 | stream.close(); |
| 7079 | } catch (IOException e) { |
| 7080 | } |
| 7081 | } |
| 7082 | } |
| 7083 | |
| 7084 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7085 | try { |
| 7086 | int type; |
| 7087 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7088 | && type != XmlPullParser.END_DOCUMENT) { |
| 7089 | ; |
| 7090 | } |
| 7091 | |
| 7092 | if (type != XmlPullParser.START_TAG) { |
| 7093 | throw new IllegalStateException("no start tag found"); |
| 7094 | } |
| 7095 | |
| 7096 | int outerDepth = parser.getDepth(); |
| 7097 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7098 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7099 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7100 | continue; |
| 7101 | } |
| 7102 | |
| 7103 | String tagName = parser.getName(); |
| 7104 | if (tagName.equals("item")) { |
| 7105 | readDailyItemTagLocked(parser); |
| 7106 | } else { |
| 7107 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7108 | + parser.getName()); |
| 7109 | XmlUtils.skipCurrentTag(parser); |
| 7110 | } |
| 7111 | } |
| 7112 | |
| 7113 | } catch (IllegalStateException e) { |
| 7114 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7115 | } catch (NullPointerException e) { |
| 7116 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7117 | } catch (NumberFormatException e) { |
| 7118 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7119 | } catch (XmlPullParserException e) { |
| 7120 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7121 | } catch (IOException e) { |
| 7122 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7123 | } catch (IndexOutOfBoundsException e) { |
| 7124 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7125 | } |
| 7126 | } |
| 7127 | |
| 7128 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7129 | XmlPullParserException, IOException { |
| 7130 | DailyItem dit = new DailyItem(); |
| 7131 | String attr = parser.getAttributeValue(null, "start"); |
| 7132 | if (attr != null) { |
| 7133 | dit.mStartTime = Long.parseLong(attr); |
| 7134 | } |
| 7135 | attr = parser.getAttributeValue(null, "end"); |
| 7136 | if (attr != null) { |
| 7137 | dit.mEndTime = Long.parseLong(attr); |
| 7138 | } |
| 7139 | int outerDepth = parser.getDepth(); |
| 7140 | int type; |
| 7141 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7142 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7143 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7144 | continue; |
| 7145 | } |
| 7146 | |
| 7147 | String tagName = parser.getName(); |
| 7148 | if (tagName.equals("dis")) { |
| 7149 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7150 | } else if (tagName.equals("chg")) { |
| 7151 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7152 | } else if (tagName.equals("upd")) { |
| 7153 | if (dit.mPackageChanges == null) { |
| 7154 | dit.mPackageChanges = new ArrayList<>(); |
| 7155 | } |
| 7156 | PackageChange pc = new PackageChange(); |
| 7157 | pc.mUpdate = true; |
| 7158 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7159 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7160 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7161 | dit.mPackageChanges.add(pc); |
| 7162 | XmlUtils.skipCurrentTag(parser); |
| 7163 | } else if (tagName.equals("rem")) { |
| 7164 | if (dit.mPackageChanges == null) { |
| 7165 | dit.mPackageChanges = new ArrayList<>(); |
| 7166 | } |
| 7167 | PackageChange pc = new PackageChange(); |
| 7168 | pc.mUpdate = false; |
| 7169 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7170 | dit.mPackageChanges.add(pc); |
| 7171 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7172 | } else { |
| 7173 | Slog.w(TAG, "Unknown element under <item>: " |
| 7174 | + parser.getName()); |
| 7175 | XmlUtils.skipCurrentTag(parser); |
| 7176 | } |
| 7177 | } |
| 7178 | mDailyItems.add(dit); |
| 7179 | } |
| 7180 | |
| 7181 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7182 | String tag) |
| 7183 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7184 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7185 | if (numAttr == null) { |
| 7186 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7187 | XmlUtils.skipCurrentTag(parser); |
| 7188 | return; |
| 7189 | } |
| 7190 | final int num = Integer.parseInt(numAttr); |
| 7191 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7192 | if (isCharge) { |
| 7193 | dit.mChargeSteps = steps; |
| 7194 | } else { |
| 7195 | dit.mDischargeSteps = steps; |
| 7196 | } |
| 7197 | int i = 0; |
| 7198 | int outerDepth = parser.getDepth(); |
| 7199 | int type; |
| 7200 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7201 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7202 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7203 | continue; |
| 7204 | } |
| 7205 | |
| 7206 | String tagName = parser.getName(); |
| 7207 | if ("s".equals(tagName)) { |
| 7208 | if (i < num) { |
| 7209 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7210 | if (valueAttr != null) { |
| 7211 | steps.decodeEntryAt(i, valueAttr); |
| 7212 | i++; |
| 7213 | } |
| 7214 | } |
| 7215 | } else { |
| 7216 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7217 | + parser.getName()); |
| 7218 | XmlUtils.skipCurrentTag(parser); |
| 7219 | } |
| 7220 | } |
| 7221 | steps.mNumStepDurations = i; |
| 7222 | } |
| 7223 | |
| 7224 | @Override |
| 7225 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7226 | int index = mDailyItems.size()-1-daysAgo; |
| 7227 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7228 | } |
| 7229 | |
| 7230 | @Override |
| 7231 | public long getCurrentDailyStartTime() { |
| 7232 | return mDailyStartTime; |
| 7233 | } |
| 7234 | |
| 7235 | @Override |
| 7236 | public long getNextMinDailyDeadline() { |
| 7237 | return mNextMinDailyDeadline; |
| 7238 | } |
| 7239 | |
| 7240 | @Override |
| 7241 | public long getNextMaxDailyDeadline() { |
| 7242 | return mNextMaxDailyDeadline; |
| 7243 | } |
| 7244 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7245 | @Override |
| 7246 | public boolean startIteratingOldHistoryLocked() { |
| 7247 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7248 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7249 | if ((mHistoryIterator = mHistory) == null) { |
| 7250 | return false; |
| 7251 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7252 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7253 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7254 | mReadOverflow = false; |
| 7255 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7256 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7257 | } |
| 7258 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7259 | @Override |
| 7260 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7261 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7262 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7263 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7264 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7265 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7266 | HistoryItem cur = mHistoryIterator; |
| 7267 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7268 | if (!mReadOverflow && !end) { |
| 7269 | Slog.w(TAG, "Old history ends before new history!"); |
| 7270 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7271 | return false; |
| 7272 | } |
| 7273 | out.setTo(cur); |
| 7274 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7275 | if (!mReadOverflow) { |
| 7276 | if (end) { |
| 7277 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7278 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7279 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7280 | pw.println("Histories differ!"); |
| 7281 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7282 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7283 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7284 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7285 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7286 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7287 | } |
| 7288 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7289 | return true; |
| 7290 | } |
| 7291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7293 | public void finishIteratingOldHistoryLocked() { |
| 7294 | mIteratingHistory = false; |
| 7295 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7296 | mHistoryIterator = null; |
| 7297 | } |
| 7298 | |
| 7299 | public int getHistoryTotalSize() { |
| 7300 | return MAX_HISTORY_BUFFER; |
| 7301 | } |
| 7302 | |
| 7303 | public int getHistoryUsedSize() { |
| 7304 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7305 | } |
| 7306 | |
| 7307 | @Override |
| 7308 | public boolean startIteratingHistoryLocked() { |
| 7309 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7310 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7311 | if (mHistoryBuffer.dataSize() <= 0) { |
| 7312 | return false; |
| 7313 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7314 | mHistoryBuffer.setDataPosition(0); |
| 7315 | mReadOverflow = false; |
| 7316 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7317 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 7318 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 7319 | mReadHistoryChars = 0; |
| 7320 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7321 | final HistoryTag tag = ent.getKey(); |
| 7322 | final int idx = ent.getValue(); |
| 7323 | mReadHistoryStrings[idx] = tag.string; |
| 7324 | mReadHistoryUids[idx] = tag.uid; |
| 7325 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7326 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7327 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7331 | public int getHistoryStringPoolSize() { |
| 7332 | return mReadHistoryStrings.length; |
| 7333 | } |
| 7334 | |
| 7335 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7336 | public int getHistoryStringPoolBytes() { |
| 7337 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 7338 | // Each string character is 2 bytes. |
| 7339 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 7340 | } |
| 7341 | |
| 7342 | @Override |
| 7343 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7344 | return mReadHistoryStrings[index]; |
| 7345 | } |
| 7346 | |
| 7347 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7348 | public int getHistoryTagPoolUid(int index) { |
| 7349 | return mReadHistoryUids[index]; |
| 7350 | } |
| 7351 | |
| 7352 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7353 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7354 | final int pos = mHistoryBuffer.dataPosition(); |
| 7355 | if (pos == 0) { |
| 7356 | out.clear(); |
| 7357 | } |
| 7358 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7359 | if (end) { |
| 7360 | return false; |
| 7361 | } |
| 7362 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7363 | final long lastRealtime = out.time; |
| 7364 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7365 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7366 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 7367 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7368 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 7369 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7370 | return true; |
| 7371 | } |
| 7372 | |
| 7373 | @Override |
| 7374 | public void finishIteratingHistoryLocked() { |
| 7375 | mIteratingHistory = false; |
| 7376 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7377 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7378 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7379 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7380 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7381 | public long getHistoryBaseTime() { |
| 7382 | return mHistoryBaseTime; |
| 7383 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7384 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7385 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | public int getStartCount() { |
| 7387 | return mStartCount; |
| 7388 | } |
| 7389 | |
| 7390 | public boolean isOnBattery() { |
| 7391 | return mOnBattery; |
| 7392 | } |
| 7393 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7394 | public boolean isCharging() { |
| 7395 | return mCharging; |
| 7396 | } |
| 7397 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7398 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7399 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7400 | } |
| 7401 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7402 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7403 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7404 | mOnBatteryTimeBase.init(uptime, realtime); |
| 7405 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7406 | mRealtime = 0; |
| 7407 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7408 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7409 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7410 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7411 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7412 | void initDischarge() { |
| 7413 | mLowDischargeAmountSinceCharge = 0; |
| 7414 | mHighDischargeAmountSinceCharge = 0; |
| 7415 | mDischargeAmountScreenOn = 0; |
| 7416 | mDischargeAmountScreenOnSinceCharge = 0; |
| 7417 | mDischargeAmountScreenOff = 0; |
| 7418 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7419 | mDischargeStepTracker.init(); |
| 7420 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7421 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7422 | |
| 7423 | public void resetAllStatsCmdLocked() { |
| 7424 | resetAllStatsLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7425 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 7426 | long uptime = mSecUptime * 1000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7427 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 7428 | long realtime = mSecRealtime * 1000; |
| 7429 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 7430 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7431 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7432 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 7433 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7434 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 7435 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 7436 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7437 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7438 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 7439 | mDischargeScreenOffUnplugLevel = 0; |
| 7440 | } else { |
| 7441 | mDischargeScreenOnUnplugLevel = 0; |
| 7442 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 7443 | } |
| 7444 | mDischargeAmountScreenOn = 0; |
| 7445 | mDischargeAmountScreenOff = 0; |
| 7446 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7447 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7448 | } |
| 7449 | |
| 7450 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7451 | mStartCount = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7452 | initTimes(SystemClock.uptimeMillis() * 1000, SystemClock.elapsedRealtime() * 1000); |
| 7453 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7454 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7455 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7456 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7457 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 7458 | mPowerSaveModeEnabledTimer.reset(false); |
| 7459 | mDeviceIdleModeEnabledTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7460 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7461 | mPhoneOnTimer.reset(false); |
| 7462 | mAudioOnTimer.reset(false); |
| 7463 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 7464 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7465 | mCameraOnTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7466 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7467 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7468 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7469 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7470 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7471 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7472 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7473 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7474 | mNetworkByteActivityCounters[i].reset(false); |
| 7475 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7476 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7477 | mMobileRadioActiveTimer.reset(false); |
| 7478 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7479 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7480 | mMobileRadioActiveUnknownTime.reset(false); |
| 7481 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7482 | mWifiOnTimer.reset(false); |
| 7483 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7484 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7485 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7486 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7487 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7488 | mWifiSupplStateTimer[i].reset(false); |
| 7489 | } |
| 7490 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7491 | mWifiSignalStrengthsTimer[i].reset(false); |
| 7492 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 7493 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 7494 | mBluetoothActivityCounters[i].reset(false); |
| 7495 | mWifiActivityCounters[i].reset(false); |
| 7496 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7497 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7498 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7499 | for (int i=0; i<mUidStats.size(); i++) { |
| 7500 | if (mUidStats.valueAt(i).reset()) { |
| 7501 | mUidStats.remove(mUidStats.keyAt(i)); |
| 7502 | i--; |
| 7503 | } |
| 7504 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7505 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7506 | if (mKernelWakelockStats.size() > 0) { |
| 7507 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7508 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7509 | } |
| 7510 | mKernelWakelockStats.clear(); |
| 7511 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7512 | |
| 7513 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7514 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 7515 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7516 | } |
| 7517 | mWakeupReasonStats.clear(); |
| 7518 | } |
| 7519 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 7520 | mLastHistoryStepDetails = null; |
| 7521 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 7522 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 7523 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 7524 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 7525 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 7526 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 7527 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 7528 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 7529 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 7530 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 7531 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7532 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7533 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7534 | clearHistoryLocked(); |
| 7535 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7536 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7537 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7538 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7539 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 7540 | // Not recording process starts/stops. |
| 7541 | continue; |
| 7542 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7543 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7544 | if (active == null) { |
| 7545 | continue; |
| 7546 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7547 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 7548 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7549 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7550 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 7551 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7552 | } |
| 7553 | } |
| 7554 | } |
| 7555 | } |
| 7556 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7557 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7558 | if (oldScreenOn) { |
| 7559 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 7560 | if (diff > 0) { |
| 7561 | mDischargeAmountScreenOn += diff; |
| 7562 | mDischargeAmountScreenOnSinceCharge += diff; |
| 7563 | } |
| 7564 | } else { |
| 7565 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 7566 | if (diff > 0) { |
| 7567 | mDischargeAmountScreenOff += diff; |
| 7568 | mDischargeAmountScreenOffSinceCharge += diff; |
| 7569 | } |
| 7570 | } |
| 7571 | if (newScreenOn) { |
| 7572 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 7573 | mDischargeScreenOffUnplugLevel = 0; |
| 7574 | } else { |
| 7575 | mDischargeScreenOnUnplugLevel = 0; |
| 7576 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 7577 | } |
| 7578 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7579 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7580 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7581 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7582 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 7583 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7584 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7585 | } |
| 7586 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7587 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 7588 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 7589 | |
| 7590 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 7591 | |
| 7592 | private static final int NETWORK_STATS_LAST = 0; |
| 7593 | private static final int NETWORK_STATS_NEXT = 1; |
| 7594 | private static final int NETWORK_STATS_DELTA = 2; |
| 7595 | |
| 7596 | private final NetworkStats[] mMobileNetworkStats = new NetworkStats[] { |
| 7597 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7598 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7599 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7600 | }; |
| 7601 | |
| 7602 | private final NetworkStats[] mWifiNetworkStats = new NetworkStats[] { |
| 7603 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7604 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7605 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7606 | }; |
| 7607 | |
| 7608 | /** |
| 7609 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 7610 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 7611 | */ |
| 7612 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 7613 | NetworkStats[] networkStatsBuffer) |
| 7614 | throws IOException { |
| 7615 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 7616 | false)) { |
| 7617 | return null; |
| 7618 | } |
| 7619 | |
| 7620 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 7621 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 7622 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 7623 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 7624 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 7625 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 7626 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 7627 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 7628 | } |
| 7629 | |
| 7630 | /** |
| 7631 | * Distribute WiFi energy info and network traffic to apps. |
| 7632 | * @param info The energy information from the WiFi controller. |
| 7633 | */ |
| 7634 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7635 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 7636 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7637 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7638 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 7639 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 7640 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7641 | } catch (IOException e) { |
| 7642 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 7643 | return; |
| 7644 | } |
| 7645 | |
| 7646 | if (!mOnBatteryInternal) { |
| 7647 | return; |
| 7648 | } |
| 7649 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7650 | SparseLongArray rxPackets = new SparseLongArray(); |
| 7651 | SparseLongArray txPackets = new SparseLongArray(); |
| 7652 | long totalTxPackets = 0; |
| 7653 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7654 | if (delta != null) { |
| 7655 | final int size = delta.size(); |
| 7656 | for (int i = 0; i < size; i++) { |
| 7657 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7658 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7659 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7660 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7661 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7662 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7663 | } |
| 7664 | |
| 7665 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7666 | continue; |
| 7667 | } |
| 7668 | |
| 7669 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7670 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 7671 | entry.rxPackets); |
| 7672 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 7673 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7674 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 7675 | txPackets.put(u.getUid(), entry.txPackets); |
| 7676 | |
| 7677 | // Sum the total number of packets so that the Rx Power and Tx Power can |
| 7678 | // be evenly distributed amongst the apps. |
| 7679 | totalRxPackets += entry.rxPackets; |
| 7680 | totalTxPackets += entry.txPackets; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7681 | |
| 7682 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7683 | entry.rxBytes); |
| 7684 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7685 | entry.txBytes); |
| 7686 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7687 | entry.rxPackets); |
| 7688 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7689 | entry.txPackets); |
| 7690 | } |
| 7691 | } |
| 7692 | |
| 7693 | if (info != null) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7694 | mHasWifiEnergyReporting = true; |
| 7695 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7696 | // Measured in mAms |
| 7697 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 7698 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 7699 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 7700 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 7701 | |
| 7702 | long leftOverRxTimeMs = rxTimeMs; |
| 7703 | |
| 7704 | if (DEBUG_ENERGY) { |
| 7705 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 7706 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 7707 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 7708 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 7709 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 7710 | } |
| 7711 | |
| 7712 | long totalWifiLockTimeMs = 0; |
| 7713 | long totalScanTimeMs = 0; |
| 7714 | |
| 7715 | // On the first pass, collect some totals so that we can normalize power |
| 7716 | // calculations if we need to. |
| 7717 | final int uidStatsSize = mUidStats.size(); |
| 7718 | for (int i = 0; i < uidStatsSize; i++) { |
| 7719 | final Uid uid = mUidStats.valueAt(i); |
| 7720 | |
| 7721 | // Sum the total scan power for all apps. |
| 7722 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7723 | elapsedRealtimeMs * 1000) / 1000; |
| 7724 | |
| 7725 | // Sum the total time holding wifi lock for all apps. |
| 7726 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7727 | elapsedRealtimeMs * 1000) / 1000; |
| 7728 | } |
| 7729 | |
| 7730 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 7731 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 7732 | + rxTimeMs + " ms). Normalizing scan time."); |
| 7733 | } |
| 7734 | |
| 7735 | // Actually assign and distribute power usage to apps. |
| 7736 | for (int i = 0; i < uidStatsSize; i++) { |
| 7737 | final Uid uid = mUidStats.valueAt(i); |
| 7738 | |
| 7739 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7740 | elapsedRealtimeMs * 1000) / 1000; |
| 7741 | if (scanTimeSinceMarkMs > 0) { |
| 7742 | // Set the new mark so that next time we get new data since this point. |
| 7743 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 7744 | |
| 7745 | if (totalScanTimeMs > rxTimeMs) { |
| 7746 | // Our total scan time is more than the reported Rx time. |
| 7747 | // This is possible because the cost of a scan is approximate. |
| 7748 | // Let's normalize the result so that we evenly blame each app |
| 7749 | // scanning. |
| 7750 | // |
| 7751 | // This means that we may have apps that received packets not be blamed |
| 7752 | // for this, but this is fine as scans are relatively more expensive. |
| 7753 | scanTimeSinceMarkMs = (rxTimeMs * scanTimeSinceMarkMs) / totalScanTimeMs; |
| 7754 | } |
| 7755 | |
| 7756 | if (DEBUG_ENERGY) { |
| 7757 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": " |
| 7758 | + scanTimeSinceMarkMs + " ms)"); |
| 7759 | } |
| 7760 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, scanTimeSinceMarkMs); |
| 7761 | leftOverRxTimeMs -= scanTimeSinceMarkMs; |
| 7762 | } |
| 7763 | |
| 7764 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 7765 | // lock. |
| 7766 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7767 | elapsedRealtimeMs * 1000) / 1000; |
| 7768 | if (wifiLockTimeSinceMarkMs > 0) { |
| 7769 | // Set the new mark so that next time we get new data since this point. |
| 7770 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 7771 | |
| 7772 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 7773 | / totalWifiLockTimeMs; |
| 7774 | if (DEBUG_ENERGY) { |
| 7775 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 7776 | + myIdleTimeMs + " ms"); |
| 7777 | } |
| 7778 | uid.noteWifiControllerActivityLocked(CONTROLLER_IDLE_TIME, myIdleTimeMs); |
| 7779 | } |
| 7780 | } |
| 7781 | |
| 7782 | if (DEBUG_ENERGY) { |
| 7783 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 7784 | } |
| 7785 | |
| 7786 | // Distribute the Tx power appropriately between all apps that transmitted packets. |
| 7787 | for (int i = 0; i < txPackets.size(); i++) { |
| 7788 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 7789 | final long myTxTimeMs = (txPackets.valueAt(i) * txTimeMs) / totalTxPackets; |
| 7790 | if (DEBUG_ENERGY) { |
| 7791 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 7792 | } |
| 7793 | uid.noteWifiControllerActivityLocked(CONTROLLER_TX_TIME, myTxTimeMs); |
| 7794 | } |
| 7795 | |
| 7796 | // Distribute the remaining Rx power appropriately between all apps that received |
| 7797 | // packets. |
| 7798 | for (int i = 0; i < rxPackets.size(); i++) { |
| 7799 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 7800 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 7801 | if (DEBUG_ENERGY) { |
| 7802 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 7803 | } |
| 7804 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, myRxTimeMs); |
| 7805 | } |
| 7806 | |
| 7807 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 7808 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7809 | // Update WiFi controller stats. |
| 7810 | mWifiActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7811 | info.getControllerRxTimeMillis()); |
| 7812 | mWifiActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7813 | info.getControllerTxTimeMillis()); |
| 7814 | mWifiActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7815 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7816 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7817 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 7818 | final double opVolt = mPowerProfile.getAveragePower( |
| 7819 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 7820 | if (opVolt != 0) { |
| 7821 | // We store the power drain as mAms. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7822 | mWifiActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7823 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7824 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7825 | } |
| 7826 | } |
| 7827 | |
| 7828 | /** |
| 7829 | * Distribute Cell radio energy info and network traffic to apps. |
| 7830 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7831 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs) { |
| 7832 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7833 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7834 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 7835 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 7836 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7837 | } catch (IOException e) { |
| 7838 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 7839 | return; |
| 7840 | } |
| 7841 | |
| 7842 | if (delta == null || !mOnBatteryInternal) { |
| 7843 | return; |
| 7844 | } |
| 7845 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7846 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 7847 | elapsedRealtimeMs * 1000); |
| 7848 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7849 | long totalPackets = delta.getTotalPackets(); |
| 7850 | |
| 7851 | final int size = delta.size(); |
| 7852 | for (int i = 0; i < size; i++) { |
| 7853 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7854 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7855 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7856 | continue; |
| 7857 | } |
| 7858 | |
| 7859 | if (DEBUG_ENERGY) { |
| 7860 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 7861 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7862 | + " txPackets=" + entry.txPackets); |
| 7863 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7864 | |
| 7865 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7866 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 7867 | entry.rxPackets); |
| 7868 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 7869 | entry.txPackets); |
| 7870 | |
| 7871 | if (radioTime > 0) { |
| 7872 | // Distribute total radio active time in to this app. |
| 7873 | long appPackets = entry.rxPackets + entry.txPackets; |
| 7874 | long appRadioTime = (radioTime*appPackets)/totalPackets; |
| 7875 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 7876 | // Remove this app from the totals, so that we don't lose any time |
| 7877 | // due to rounding. |
| 7878 | radioTime -= appRadioTime; |
| 7879 | totalPackets -= appPackets; |
| 7880 | } |
| 7881 | |
| 7882 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 7883 | entry.rxBytes); |
| 7884 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 7885 | entry.txBytes); |
| 7886 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 7887 | entry.rxPackets); |
| 7888 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 7889 | entry.txPackets); |
| 7890 | } |
| 7891 | |
| 7892 | if (radioTime > 0) { |
| 7893 | // Whoops, there is some radio time we can't blame on an app! |
| 7894 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 7895 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 7896 | } |
| 7897 | } |
| 7898 | |
| 7899 | /** |
| 7900 | * Distribute Bluetooth energy info and network traffic to apps. |
| 7901 | * @param info The energy information from the bluetooth controller. |
| 7902 | */ |
| 7903 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | 719e61f | 2015-05-15 15:49:24 -0700 | [diff] [blame] | 7904 | if (info != null && mOnBatteryInternal) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7905 | mHasBluetoothEnergyReporting = true; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7906 | mBluetoothActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7907 | info.getControllerRxTimeMillis()); |
| 7908 | mBluetoothActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7909 | info.getControllerTxTimeMillis()); |
| 7910 | mBluetoothActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7911 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7912 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7913 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 7914 | final double opVolt = mPowerProfile.getAveragePower( |
| 7915 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 7916 | if (opVolt != 0) { |
| 7917 | // We store the power drain as mAms. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7918 | mBluetoothActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7919 | (long) (info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7920 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7921 | } |
| 7922 | } |
| 7923 | |
| 7924 | /** |
| 7925 | * Read and distribute kernel wake lock use across apps. |
| 7926 | */ |
| 7927 | public void updateKernelWakelocksLocked() { |
| 7928 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 7929 | mTmpWakelockStats); |
| 7930 | if (wakelockStats == null) { |
| 7931 | // Not crashing might make board bringup easier. |
| 7932 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 7933 | return; |
| 7934 | } |
| 7935 | |
| 7936 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 7937 | String name = ent.getKey(); |
| 7938 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 7939 | |
| 7940 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 7941 | if (kwlt == null) { |
| 7942 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, |
| 7943 | true /* track reported val */); |
| 7944 | mKernelWakelockStats.put(name, kwlt); |
| 7945 | } |
| 7946 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 7947 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 7948 | kwlt.setUpdateVersion(kws.mVersion); |
| 7949 | } |
| 7950 | |
| 7951 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 7952 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 7953 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 7954 | SamplingTimer st = ent.getValue(); |
| 7955 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 7956 | st.setStale(); |
| 7957 | } |
| 7958 | } |
| 7959 | } |
| 7960 | } |
| 7961 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7962 | /** |
| 7963 | * Read and distribute CPU usage across apps. |
| 7964 | */ |
| 7965 | public void updateCpuTimeLocked(boolean firstTime) { |
| 7966 | final int cpuSpeedSteps = getCpuSpeedSteps(); |
| 7967 | final long[] cpuSpeeds = mKernelCpuSpeedReader.readDelta(); |
| 7968 | KernelUidCpuTimeReader.Callback callback = null; |
| 7969 | if (mOnBatteryInternal && !firstTime) { |
| 7970 | callback = new KernelUidCpuTimeReader.Callback() { |
| 7971 | @Override |
| 7972 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs) { |
| 7973 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 7974 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 7975 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 7976 | for (int i = 0; i < cpuSpeedSteps; i++) { |
| 7977 | if (u.mSpeedBins[i] == null) { |
| 7978 | u.mSpeedBins[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7979 | } |
| 7980 | u.mSpeedBins[i].addCountLocked(cpuSpeeds[i]); |
| 7981 | } |
| 7982 | } |
| 7983 | }; |
| 7984 | } |
| 7985 | mKernelUidCpuTimeReader.readDelta(callback); |
| 7986 | } |
| 7987 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7988 | boolean setChargingLocked(boolean charging) { |
| 7989 | if (mCharging != charging) { |
| 7990 | mCharging = charging; |
| 7991 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 7992 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7993 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 7994 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7995 | } |
| 7996 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 7997 | return true; |
| 7998 | } |
| 7999 | return false; |
| 8000 | } |
| 8001 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8002 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 8003 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8004 | boolean doWrite = false; |
| 8005 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 8006 | m.arg1 = onBattery ? 1 : 0; |
| 8007 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8008 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8009 | final long uptime = mSecUptime * 1000; |
| 8010 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8011 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8012 | if (onBattery) { |
| 8013 | // We will reset our status if we are unplugging after the |
| 8014 | // battery was last full, or the level is at 100, or |
| 8015 | // we have gone through a significant charge (from a very low |
| 8016 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8017 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 8018 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8019 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 8020 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 8021 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 8022 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 8023 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 8024 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 8025 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 8026 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8027 | // Before we write, collect a snapshot of the final aggregated |
| 8028 | // stats to be reported in the next checkin. Only do this if we have |
| 8029 | // a sufficient amount of data to make it interesting. |
| 8030 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 8031 | final Parcel parcel = Parcel.obtain(); |
| 8032 | writeSummaryToParcel(parcel, true); |
| 8033 | BackgroundThread.getHandler().post(new Runnable() { |
| 8034 | @Override public void run() { |
| 8035 | synchronized (mCheckinFile) { |
| 8036 | FileOutputStream stream = null; |
| 8037 | try { |
| 8038 | stream = mCheckinFile.startWrite(); |
| 8039 | stream.write(parcel.marshall()); |
| 8040 | stream.flush(); |
| 8041 | FileUtils.sync(stream); |
| 8042 | stream.close(); |
| 8043 | mCheckinFile.finishWrite(stream); |
| 8044 | } catch (IOException e) { |
| 8045 | Slog.w("BatteryStats", |
| 8046 | "Error writing checkin battery statistics", e); |
| 8047 | mCheckinFile.failWrite(stream); |
| 8048 | } finally { |
| 8049 | parcel.recycle(); |
| 8050 | } |
| 8051 | } |
| 8052 | } |
| 8053 | }); |
| 8054 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8055 | doWrite = true; |
| 8056 | resetAllStatsLocked(); |
| 8057 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8058 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8059 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8060 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8061 | if (mCharging) { |
| 8062 | setChargingLocked(false); |
| 8063 | } |
| 8064 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8065 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8066 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8067 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8068 | mDischargeStepTracker.clearTime(); |
| 8069 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8070 | mInitStepMode = mCurStepMode; |
| 8071 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8072 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8073 | mHistoryCur.batteryLevel = (byte)level; |
| 8074 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 8075 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 8076 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8077 | if (reset) { |
| 8078 | mRecordingHistory = true; |
| 8079 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 8080 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8081 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8082 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8083 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8084 | mDischargeScreenOnUnplugLevel = level; |
| 8085 | mDischargeScreenOffUnplugLevel = 0; |
| 8086 | } else { |
| 8087 | mDischargeScreenOnUnplugLevel = 0; |
| 8088 | mDischargeScreenOffUnplugLevel = level; |
| 8089 | } |
| 8090 | mDischargeAmountScreenOn = 0; |
| 8091 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8092 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8093 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8094 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8095 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8096 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8097 | mHistoryCur.batteryLevel = (byte)level; |
| 8098 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 8099 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 8100 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8101 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8102 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8103 | if (level < mDischargeUnplugLevel) { |
| 8104 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 8105 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 8106 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8107 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 8108 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8109 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8110 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8111 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8112 | mInitStepMode = mCurStepMode; |
| 8113 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8114 | } |
| 8115 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 8116 | if (mFile != null) { |
| 8117 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8118 | } |
| 8119 | } |
| 8120 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8121 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8122 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 8123 | boolean reset) { |
| 8124 | mRecordingHistory = true; |
| 8125 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8126 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 8127 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8128 | mHistoryCur); |
| 8129 | mHistoryCur.currentTime = 0; |
| 8130 | if (reset) { |
| 8131 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 8132 | } |
| 8133 | } |
| 8134 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 8135 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 8136 | final long uptimeMs) { |
| 8137 | if (mRecordingHistory) { |
| 8138 | mHistoryCur.currentTime = currentTime; |
| 8139 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 8140 | mHistoryCur); |
| 8141 | mHistoryCur.currentTime = 0; |
| 8142 | } |
| 8143 | } |
| 8144 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8145 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 8146 | if (mRecordingHistory) { |
| 8147 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8148 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 8149 | mHistoryCur); |
| 8150 | mHistoryCur.currentTime = 0; |
| 8151 | } |
| 8152 | } |
| 8153 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8154 | private void scheduleSyncExternalStatsLocked(String reason) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8155 | if (mExternalSync != null) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8156 | mExternalSync.scheduleSync(reason); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8157 | } |
| 8158 | } |
| 8159 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8160 | // This should probably be exposed in the API, though it's not critical |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8161 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8162 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8163 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8164 | int temp, int volt) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8165 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 8166 | final long uptime = SystemClock.uptimeMillis(); |
| 8167 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8168 | if (!mHaveBatteryLevel) { |
| 8169 | mHaveBatteryLevel = true; |
| 8170 | // We start out assuming that the device is plugged in (not |
| 8171 | // on battery). If our first report is now that we are indeed |
| 8172 | // plugged in, then twiddle our state to correctly reflect that |
| 8173 | // since we won't be going through the full setOnBattery(). |
| 8174 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8175 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8176 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8177 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8178 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8179 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8180 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8181 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8182 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8183 | mHistoryCur.batteryStatus = (byte)status; |
| 8184 | mHistoryCur.batteryLevel = (byte)level; |
| 8185 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 8186 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8187 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8188 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 8189 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 8190 | } |
| 8191 | int oldStatus = mHistoryCur.batteryStatus; |
| 8192 | if (onBattery) { |
| 8193 | mDischargeCurrentLevel = level; |
| 8194 | if (!mRecordingHistory) { |
| 8195 | mRecordingHistory = true; |
| 8196 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 8197 | } |
| 8198 | } else if (level < 96) { |
| 8199 | if (!mRecordingHistory) { |
| 8200 | mRecordingHistory = true; |
| 8201 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8202 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8203 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8204 | mCurrentBatteryLevel = level; |
| 8205 | if (mDischargePlugLevel < 0) { |
| 8206 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8207 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8208 | if (onBattery != mOnBattery) { |
| 8209 | mHistoryCur.batteryLevel = (byte)level; |
| 8210 | mHistoryCur.batteryStatus = (byte)status; |
| 8211 | mHistoryCur.batteryHealth = (byte)health; |
| 8212 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8213 | mHistoryCur.batteryTemperature = (short)temp; |
| 8214 | mHistoryCur.batteryVoltage = (char)volt; |
| 8215 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 8216 | } else { |
| 8217 | boolean changed = false; |
| 8218 | if (mHistoryCur.batteryLevel != level) { |
| 8219 | mHistoryCur.batteryLevel = (byte)level; |
| 8220 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8221 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8222 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 8223 | // which will pull external stats. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8224 | scheduleSyncExternalStatsLocked("battery-level"); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8225 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8226 | if (mHistoryCur.batteryStatus != status) { |
| 8227 | mHistoryCur.batteryStatus = (byte)status; |
| 8228 | changed = true; |
| 8229 | } |
| 8230 | if (mHistoryCur.batteryHealth != health) { |
| 8231 | mHistoryCur.batteryHealth = (byte)health; |
| 8232 | changed = true; |
| 8233 | } |
| 8234 | if (mHistoryCur.batteryPlugType != plugType) { |
| 8235 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8236 | changed = true; |
| 8237 | } |
| 8238 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 8239 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 8240 | mHistoryCur.batteryTemperature = (short)temp; |
| 8241 | changed = true; |
| 8242 | } |
| 8243 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 8244 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 8245 | mHistoryCur.batteryVoltage = (char)volt; |
| 8246 | changed = true; |
| 8247 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8248 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 8249 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 8250 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 8251 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8252 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8253 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 8254 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8255 | modeBits, elapsedRealtime); |
| 8256 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8257 | modeBits, elapsedRealtime); |
| 8258 | mLastDischargeStepLevel = level; |
| 8259 | mMinDischargeStepLevel = level; |
| 8260 | mInitStepMode = mCurStepMode; |
| 8261 | mModStepMode = 0; |
| 8262 | } |
| 8263 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8264 | if (level >= 90) { |
| 8265 | // If the battery level is at least 90%, always consider the device to be |
| 8266 | // charging even if it happens to go down a level. |
| 8267 | changed |= setChargingLocked(true); |
| 8268 | mLastChargeStepLevel = level; |
| 8269 | } if (!mCharging) { |
| 8270 | if (mLastChargeStepLevel < level) { |
| 8271 | // We have not reporting that we are charging, but the level has now |
| 8272 | // gone up, so consider the state to be charging. |
| 8273 | changed |= setChargingLocked(true); |
| 8274 | mLastChargeStepLevel = level; |
| 8275 | } |
| 8276 | } else { |
| 8277 | if (mLastChargeStepLevel > level) { |
| 8278 | // We had reported that the device was charging, but here we are with |
| 8279 | // power connected and the level going down. Looks like the current |
| 8280 | // power supplied isn't enough, so consider the device to now be |
| 8281 | // discharging. |
| 8282 | changed |= setChargingLocked(false); |
| 8283 | mLastChargeStepLevel = level; |
| 8284 | } |
| 8285 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8286 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 8287 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8288 | modeBits, elapsedRealtime); |
| 8289 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8290 | modeBits, elapsedRealtime); |
| 8291 | mLastChargeStepLevel = level; |
| 8292 | mMaxChargeStepLevel = level; |
| 8293 | mInitStepMode = mCurStepMode; |
| 8294 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8295 | } |
| 8296 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8297 | if (changed) { |
| 8298 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 8299 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8300 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8301 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 8302 | // We don't record history while we are plugged in and fully charged. |
| 8303 | // The next time we are unplugged, history will be cleared. |
| 8304 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 8305 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8306 | } |
| 8307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8308 | public long getAwakeTimeBattery() { |
| 8309 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 8310 | } |
| 8311 | |
| 8312 | public long getAwakeTimePlugged() { |
| 8313 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 8314 | } |
| 8315 | |
| 8316 | @Override |
| 8317 | public long computeUptime(long curTime, int which) { |
| 8318 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8319 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8321 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8322 | } |
| 8323 | return 0; |
| 8324 | } |
| 8325 | |
| 8326 | @Override |
| 8327 | public long computeRealtime(long curTime, int which) { |
| 8328 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8329 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8330 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8331 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | } |
| 8333 | return 0; |
| 8334 | } |
| 8335 | |
| 8336 | @Override |
| 8337 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8338 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8339 | } |
| 8340 | |
| 8341 | @Override |
| 8342 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8343 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | } |
| 8345 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8346 | @Override |
| 8347 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 8348 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 8349 | } |
| 8350 | |
| 8351 | @Override |
| 8352 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 8353 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8354 | } |
| 8355 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8356 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 8357 | // For now we'll do a simple average across all steps. |
| 8358 | if (numSteps <= 0) { |
| 8359 | return -1; |
| 8360 | } |
| 8361 | long total = 0; |
| 8362 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8363 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8364 | } |
| 8365 | return total / numSteps; |
| 8366 | /* |
| 8367 | long[] buckets = new long[numSteps]; |
| 8368 | int numBuckets = 0; |
| 8369 | int numToAverage = 4; |
| 8370 | int i = 0; |
| 8371 | while (i < numSteps) { |
| 8372 | long totalTime = 0; |
| 8373 | int num = 0; |
| 8374 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8375 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8376 | num++; |
| 8377 | } |
| 8378 | buckets[numBuckets] = totalTime / num; |
| 8379 | numBuckets++; |
| 8380 | numToAverage *= 2; |
| 8381 | i += num; |
| 8382 | } |
| 8383 | if (numBuckets < 1) { |
| 8384 | return -1; |
| 8385 | } |
| 8386 | long averageTime = buckets[numBuckets-1]; |
| 8387 | for (i=numBuckets-2; i>=0; i--) { |
| 8388 | averageTime = (averageTime + buckets[i]) / 2; |
| 8389 | } |
| 8390 | return averageTime; |
| 8391 | */ |
| 8392 | } |
| 8393 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8394 | @Override |
| 8395 | public long computeBatteryTimeRemaining(long curTime) { |
| 8396 | if (!mOnBattery) { |
| 8397 | return -1; |
| 8398 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8399 | /* Simple implementation just looks at the average discharge per level across the |
| 8400 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8401 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 8402 | if (discharge < 2) { |
| 8403 | return -1; |
| 8404 | } |
| 8405 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 8406 | if (duration < 1000*1000) { |
| 8407 | return -1; |
| 8408 | } |
| 8409 | long usPerLevel = duration/discharge; |
| 8410 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8411 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8412 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8413 | return -1; |
| 8414 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8415 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8416 | if (msPerLevel <= 0) { |
| 8417 | return -1; |
| 8418 | } |
| 8419 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8420 | } |
| 8421 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8422 | @Override |
| 8423 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 8424 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8425 | } |
| 8426 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8427 | @Override |
| 8428 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 8429 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8430 | } |
| 8431 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8432 | @Override |
| 8433 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8434 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8435 | // Not yet working. |
| 8436 | return -1; |
| 8437 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8438 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8439 | int curLevel = mCurrentBatteryLevel; |
| 8440 | int plugLevel = mDischargePlugLevel; |
| 8441 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 8442 | return -1; |
| 8443 | } |
| 8444 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 8445 | if (duration < 1000*1000) { |
| 8446 | return -1; |
| 8447 | } |
| 8448 | long usPerLevel = duration/(curLevel-plugLevel); |
| 8449 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8450 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8451 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8452 | return -1; |
| 8453 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8454 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8455 | if (msPerLevel <= 0) { |
| 8456 | return -1; |
| 8457 | } |
| 8458 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8459 | } |
| 8460 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8461 | @Override |
| 8462 | public LevelStepTracker getChargeLevelStepTracker() { |
| 8463 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8464 | } |
| 8465 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8466 | @Override |
| 8467 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 8468 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8469 | } |
| 8470 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8471 | @Override |
| 8472 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 8473 | return mDailyPackageChanges; |
| 8474 | } |
| 8475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8476 | long getBatteryUptimeLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8477 | return mOnBatteryTimeBase.getUptime(SystemClock.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | @Override |
| 8481 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8482 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | } |
| 8484 | |
| 8485 | @Override |
| 8486 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8487 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8488 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 8489 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8490 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8491 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8492 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8493 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8494 | } |
| 8495 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8496 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8497 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8498 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8499 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8500 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8501 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8502 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8503 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8504 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8505 | } |
| 8506 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8507 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8508 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8509 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8511 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8512 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8513 | public int getLowDischargeAmountSinceCharge() { |
| 8514 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8515 | int val = mLowDischargeAmountSinceCharge; |
| 8516 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8517 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 8518 | } |
| 8519 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8520 | } |
| 8521 | } |
| 8522 | |
| 8523 | @Override |
| 8524 | public int getHighDischargeAmountSinceCharge() { |
| 8525 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8526 | int val = mHighDischargeAmountSinceCharge; |
| 8527 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8528 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 8529 | } |
| 8530 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8531 | } |
| 8532 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8533 | |
| 8534 | @Override |
| 8535 | public int getDischargeAmount(int which) { |
| 8536 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 8537 | ? getHighDischargeAmountSinceCharge() |
| 8538 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 8539 | if (dischargeAmount < 0) { |
| 8540 | dischargeAmount = 0; |
| 8541 | } |
| 8542 | return dischargeAmount; |
| 8543 | } |
| 8544 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8545 | public int getDischargeAmountScreenOn() { |
| 8546 | synchronized(this) { |
| 8547 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8548 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8549 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8550 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8551 | } |
| 8552 | return val; |
| 8553 | } |
| 8554 | } |
| 8555 | |
| 8556 | public int getDischargeAmountScreenOnSinceCharge() { |
| 8557 | synchronized(this) { |
| 8558 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8559 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8560 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8561 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8562 | } |
| 8563 | return val; |
| 8564 | } |
| 8565 | } |
| 8566 | |
| 8567 | public int getDischargeAmountScreenOff() { |
| 8568 | synchronized(this) { |
| 8569 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8570 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8571 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8572 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8573 | } |
| 8574 | return val; |
| 8575 | } |
| 8576 | } |
| 8577 | |
| 8578 | public int getDischargeAmountScreenOffSinceCharge() { |
| 8579 | synchronized(this) { |
| 8580 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8581 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8582 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8583 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8584 | } |
| 8585 | return val; |
| 8586 | } |
| 8587 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8588 | |
| 8589 | @Override |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8590 | public int getCpuSpeedSteps() { |
| 8591 | return sNumSpeedSteps; |
| 8592 | } |
| 8593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8594 | /** |
| 8595 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 8596 | */ |
| 8597 | public Uid getUidStatsLocked(int uid) { |
| 8598 | Uid u = mUidStats.get(uid); |
| 8599 | if (u == null) { |
| 8600 | u = new Uid(uid); |
| 8601 | mUidStats.put(uid, u); |
| 8602 | } |
| 8603 | return u; |
| 8604 | } |
| 8605 | |
| 8606 | /** |
| 8607 | * Remove the statistics object for a particular uid. |
| 8608 | */ |
| 8609 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 8610 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8611 | mUidStats.remove(uid); |
| 8612 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 8613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8614 | /** |
| 8615 | * Retrieve the statistics object for a particular process, creating |
| 8616 | * if needed. |
| 8617 | */ |
| 8618 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8619 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | Uid u = getUidStatsLocked(uid); |
| 8621 | return u.getProcessStatsLocked(name); |
| 8622 | } |
| 8623 | |
| 8624 | /** |
| 8625 | * Retrieve the statistics object for a particular process, creating |
| 8626 | * if needed. |
| 8627 | */ |
| 8628 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8629 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8630 | Uid u = getUidStatsLocked(uid); |
| 8631 | return u.getPackageStatsLocked(pkg); |
| 8632 | } |
| 8633 | |
| 8634 | /** |
| 8635 | * Retrieve the statistics object for a particular service, creating |
| 8636 | * if needed. |
| 8637 | */ |
| 8638 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8639 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | Uid u = getUidStatsLocked(uid); |
| 8641 | return u.getServiceStatsLocked(pkg, name); |
| 8642 | } |
| 8643 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8644 | public void shutdownLocked() { |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8645 | recordShutdownLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8646 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8647 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8648 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8649 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8650 | Parcel mPendingWrite = null; |
| 8651 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 8652 | |
| 8653 | public void writeAsyncLocked() { |
| 8654 | writeLocked(false); |
| 8655 | } |
| 8656 | |
| 8657 | public void writeSyncLocked() { |
| 8658 | writeLocked(true); |
| 8659 | } |
| 8660 | |
| 8661 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8662 | if (mFile == null) { |
| 8663 | 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] | 8664 | return; |
| 8665 | } |
| 8666 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8667 | if (mShuttingDown) { |
| 8668 | return; |
| 8669 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8670 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8671 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8672 | writeSummaryToParcel(out, true); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8673 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 8674 | |
| 8675 | if (mPendingWrite != null) { |
| 8676 | mPendingWrite.recycle(); |
| 8677 | } |
| 8678 | mPendingWrite = out; |
| 8679 | |
| 8680 | if (sync) { |
| 8681 | commitPendingDataToDisk(); |
| 8682 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8683 | BackgroundThread.getHandler().post(new Runnable() { |
| 8684 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8685 | commitPendingDataToDisk(); |
| 8686 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8687 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8688 | } |
| 8689 | } |
| 8690 | |
| 8691 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 8692 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8693 | synchronized (this) { |
| 8694 | next = mPendingWrite; |
| 8695 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 8696 | if (next == null) { |
| 8697 | return; |
| 8698 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8699 | |
| 8700 | mWriteLock.lock(); |
| 8701 | } |
| 8702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8703 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8704 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8705 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8706 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 8707 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8708 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8709 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8710 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8711 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8712 | mFile.rollback(); |
| 8713 | } finally { |
| 8714 | next.recycle(); |
| 8715 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8716 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8717 | } |
| 8718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8719 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8720 | if (mDailyFile != null) { |
| 8721 | readDailyStatsLocked(); |
| 8722 | } |
| 8723 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8724 | if (mFile == null) { |
| 8725 | 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] | 8726 | return; |
| 8727 | } |
| 8728 | |
| 8729 | mUidStats.clear(); |
| 8730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8732 | File file = mFile.chooseForRead(); |
| 8733 | if (!file.exists()) { |
| 8734 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8735 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8736 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8737 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8738 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8739 | Parcel in = Parcel.obtain(); |
| 8740 | in.unmarshall(raw, 0, raw.length); |
| 8741 | in.setDataPosition(0); |
| 8742 | stream.close(); |
| 8743 | |
| 8744 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 8745 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8746 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8747 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8748 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8749 | mEndPlatformVersion = Build.ID; |
| 8750 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8751 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8752 | mRecordingHistory = true; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8753 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8754 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8755 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8756 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8757 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8758 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 8759 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8760 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8761 | |
| 8762 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8763 | } |
| 8764 | |
| 8765 | public int describeContents() { |
| 8766 | return 0; |
| 8767 | } |
| 8768 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8769 | void readHistory(Parcel in, boolean andOldHistory) { |
| 8770 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8771 | |
| 8772 | mHistoryBuffer.setDataSize(0); |
| 8773 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8774 | mHistoryTagPool.clear(); |
| 8775 | mNextHistoryTagIdx = 0; |
| 8776 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8777 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8778 | int numTags = in.readInt(); |
| 8779 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8780 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8781 | String str = in.readString(); |
| 8782 | int uid = in.readInt(); |
| 8783 | HistoryTag tag = new HistoryTag(); |
| 8784 | tag.string = str; |
| 8785 | tag.uid = uid; |
| 8786 | tag.poolIdx = idx; |
| 8787 | mHistoryTagPool.put(tag, idx); |
| 8788 | if (idx >= mNextHistoryTagIdx) { |
| 8789 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8790 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8791 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8792 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8793 | |
| 8794 | int bufSize = in.readInt(); |
| 8795 | int curPos = in.dataPosition(); |
| 8796 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
| 8797 | Slog.w(TAG, "File corrupt: history data buffer too large " + bufSize); |
| 8798 | } else if ((bufSize&~3) != bufSize) { |
| 8799 | Slog.w(TAG, "File corrupt: history data buffer not aligned " + bufSize); |
| 8800 | } else { |
| 8801 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 8802 | + " bytes at " + curPos); |
| 8803 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 8804 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8805 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8806 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8807 | if (andOldHistory) { |
| 8808 | readOldHistory(in); |
| 8809 | } |
| 8810 | |
| 8811 | if (DEBUG_HISTORY) { |
| 8812 | StringBuilder sb = new StringBuilder(128); |
| 8813 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 8814 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8815 | Slog.i(TAG, sb.toString()); |
| 8816 | } |
| 8817 | mHistoryBaseTime = historyBaseTime; |
| 8818 | if (DEBUG_HISTORY) { |
| 8819 | StringBuilder sb = new StringBuilder(128); |
| 8820 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 8821 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8822 | Slog.i(TAG, sb.toString()); |
| 8823 | } |
| 8824 | |
| 8825 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 8826 | // the last run until samples in this run. |
| 8827 | if (mHistoryBaseTime > 0) { |
| 8828 | long oldnow = SystemClock.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8829 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8830 | if (DEBUG_HISTORY) { |
| 8831 | StringBuilder sb = new StringBuilder(128); |
| 8832 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 8833 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8834 | Slog.i(TAG, sb.toString()); |
| 8835 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 8836 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8837 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8838 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8839 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8840 | if (!USE_OLD_HISTORY) { |
| 8841 | return; |
| 8842 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8843 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 8844 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 8845 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8846 | HistoryItem rec = new HistoryItem(time, in); |
| 8847 | addHistoryRecordLocked(rec); |
| 8848 | } |
| 8849 | } |
| 8850 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8851 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8852 | if (DEBUG_HISTORY) { |
| 8853 | StringBuilder sb = new StringBuilder(128); |
| 8854 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 8855 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8856 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 8857 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8858 | Slog.i(TAG, sb.toString()); |
| 8859 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8860 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8861 | if (!inclData) { |
| 8862 | out.writeInt(0); |
| 8863 | out.writeInt(0); |
| 8864 | return; |
| 8865 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8866 | out.writeInt(mHistoryTagPool.size()); |
| 8867 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8868 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8869 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8870 | out.writeString(tag.string); |
| 8871 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8872 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8873 | out.writeInt(mHistoryBuffer.dataSize()); |
| 8874 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 8875 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 8876 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8877 | |
| 8878 | if (andOldHistory) { |
| 8879 | writeOldHistory(out); |
| 8880 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8881 | } |
| 8882 | |
| 8883 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8884 | if (!USE_OLD_HISTORY) { |
| 8885 | return; |
| 8886 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8887 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8888 | while (rec != null) { |
| 8889 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 8890 | rec = rec.next; |
| 8891 | } |
| 8892 | out.writeLong(-1); |
| 8893 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8894 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8895 | public void readSummaryFromParcel(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8896 | final int version = in.readInt(); |
| 8897 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8898 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8899 | + ", expected " + VERSION + "; erasing old stats"); |
| 8900 | return; |
| 8901 | } |
| 8902 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8903 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8906 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8907 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8908 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8909 | mStartPlatformVersion = in.readString(); |
| 8910 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8911 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 8912 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8913 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8914 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8915 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8916 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8917 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 8918 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8919 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 8920 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8921 | mDischargeStepTracker.readFromParcel(in); |
| 8922 | mChargeStepTracker.readFromParcel(in); |
| 8923 | mDailyDischargeStepTracker.readFromParcel(in); |
| 8924 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8925 | int NPKG = in.readInt(); |
| 8926 | if (NPKG > 0) { |
| 8927 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 8928 | while (NPKG > 0) { |
| 8929 | NPKG--; |
| 8930 | PackageChange pc = new PackageChange(); |
| 8931 | pc.mPackageName = in.readString(); |
| 8932 | pc.mUpdate = in.readInt() != 0; |
| 8933 | pc.mVersionCode = in.readInt(); |
| 8934 | mDailyPackageChanges.add(pc); |
| 8935 | } |
| 8936 | } else { |
| 8937 | mDailyPackageChanges = null; |
| 8938 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8939 | mDailyStartTime = in.readLong(); |
| 8940 | mNextMinDailyDeadline = in.readLong(); |
| 8941 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8944 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8945 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8946 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8947 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 8948 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 8949 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8950 | mInteractive = false; |
| 8951 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8953 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
| 8954 | mDeviceIdleModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8955 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8956 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8957 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8958 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 8959 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8960 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8961 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 8962 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 8963 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8964 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8965 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 8966 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8967 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8968 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 8969 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8970 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8971 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8972 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 8973 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8974 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8975 | mWifiOn = false; |
| 8976 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8977 | mGlobalWifiRunning = false; |
| 8978 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8979 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 8980 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 8981 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8982 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8983 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 8984 | } |
| 8985 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8986 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 8987 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8988 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 8989 | mBluetoothActivityCounters[i].readSummaryFromParcelLocked(in); |
| 8990 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8991 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 8992 | mWifiActivityCounters[i].readSummaryFromParcelLocked(in); |
| 8993 | } |
| 8994 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8995 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8996 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8997 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8998 | mCameraOnNesting = 0; |
| 8999 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9001 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9002 | if (NKW > 10000) { |
| 9003 | Slog.w(TAG, "File corrupt: too many kernel wake locks " + NKW); |
| 9004 | return; |
| 9005 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9006 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 9007 | if (in.readInt() != 0) { |
| 9008 | String kwltName = in.readString(); |
| 9009 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 9010 | } |
| 9011 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9012 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9013 | int NWR = in.readInt(); |
| 9014 | if (NWR > 10000) { |
| 9015 | Slog.w(TAG, "File corrupt: too many wakeup reasons " + NWR); |
| 9016 | return; |
| 9017 | } |
| 9018 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 9019 | if (in.readInt() != 0) { |
| 9020 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9021 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9022 | } |
| 9023 | } |
| 9024 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9025 | sNumSpeedSteps = in.readInt(); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 9026 | if (sNumSpeedSteps < 0 || sNumSpeedSteps > 100) { |
| 9027 | throw new BadParcelableException("Bad speed steps in data: " + sNumSpeedSteps); |
| 9028 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9030 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9031 | if (NU > 10000) { |
| 9032 | Slog.w(TAG, "File corrupt: too many uids " + NU); |
| 9033 | return; |
| 9034 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9035 | for (int iu = 0; iu < NU; iu++) { |
| 9036 | int uid = in.readInt(); |
| 9037 | Uid u = new Uid(uid); |
| 9038 | mUidStats.put(uid, u); |
| 9039 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9040 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9041 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9042 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9043 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9044 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9045 | if (in.readInt() != 0) { |
| 9046 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 9047 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9048 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9049 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9050 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9051 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9052 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 9053 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9054 | if (in.readInt() != 0) { |
| 9055 | u.makeWifiBatchedScanBin(i, null); |
| 9056 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 9057 | } |
| 9058 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9059 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9060 | if (in.readInt() != 0) { |
| 9061 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 9062 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9063 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9064 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9065 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9066 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9067 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9068 | } |
| 9069 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9070 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9071 | } |
| 9072 | if (in.readInt() != 0) { |
| 9073 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9074 | } |
| 9075 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9076 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 9077 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9078 | u.mProcessState = Uid.PROCESS_STATE_NONE; |
| 9079 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9080 | if (in.readInt() != 0) { |
| 9081 | u.makeProcessState(i, null); |
| 9082 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 9083 | } |
| 9084 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9085 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9086 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9087 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9088 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9089 | if (in.readInt() != 0) { |
| 9090 | if (u.mUserActivityCounters == null) { |
| 9091 | u.initUserActivityLocked(); |
| 9092 | } |
| 9093 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9094 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9095 | } |
| 9096 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9097 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9098 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9099 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9100 | u.initNetworkActivityLocked(); |
| 9101 | } |
| 9102 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9103 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9104 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9105 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9106 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 9107 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9108 | } |
| 9109 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9110 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 9111 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 9112 | |
| 9113 | int NSB = in.readInt(); |
| 9114 | if (NSB > 100) { |
| 9115 | Slog.w(TAG, "File corrupt: too many speed bins " + NSB); |
| 9116 | return; |
| 9117 | } |
| 9118 | |
| 9119 | u.mSpeedBins = new LongSamplingCounter[NSB]; |
| 9120 | for (int i=0; i<NSB; i++) { |
| 9121 | if (in.readInt() != 0) { |
| 9122 | u.mSpeedBins[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 9123 | u.mSpeedBins[i].readSummaryFromParcelLocked(in); |
| 9124 | } |
| 9125 | } |
| 9126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9127 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9128 | if (NW > 100) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9129 | Slog.w(TAG, "File corrupt: too many wake locks " + NW); |
| 9130 | return; |
| 9131 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9132 | for (int iw = 0; iw < NW; iw++) { |
| 9133 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9134 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9135 | } |
| 9136 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9137 | int NS = in.readInt(); |
| 9138 | if (NS > 100) { |
| 9139 | Slog.w(TAG, "File corrupt: too many syncs " + NS); |
| 9140 | return; |
| 9141 | } |
| 9142 | for (int is = 0; is < NS; is++) { |
| 9143 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9144 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9145 | } |
| 9146 | |
| 9147 | int NJ = in.readInt(); |
| 9148 | if (NJ > 100) { |
| 9149 | Slog.w(TAG, "File corrupt: too many job timers " + NJ); |
| 9150 | return; |
| 9151 | } |
| 9152 | for (int ij = 0; ij < NJ; ij++) { |
| 9153 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9154 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9155 | } |
| 9156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9157 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9158 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9159 | Slog.w(TAG, "File corrupt: too many sensors " + NP); |
| 9160 | return; |
| 9161 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9162 | for (int is = 0; is < NP; is++) { |
| 9163 | int seNumber = in.readInt(); |
| 9164 | if (in.readInt() != 0) { |
| 9165 | u.getSensorTimerLocked(seNumber, true) |
| 9166 | .readSummaryFromParcelLocked(in); |
| 9167 | } |
| 9168 | } |
| 9169 | |
| 9170 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9171 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9172 | Slog.w(TAG, "File corrupt: too many processes " + NP); |
| 9173 | return; |
| 9174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9175 | for (int ip = 0; ip < NP; ip++) { |
| 9176 | String procName = in.readString(); |
| 9177 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 9178 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9179 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9180 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9181 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9182 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 9183 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9184 | if (!p.readExcessivePowerFromParcelLocked(in)) { |
| 9185 | return; |
| 9186 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9187 | } |
| 9188 | |
| 9189 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9190 | if (NP > 10000) { |
| 9191 | Slog.w(TAG, "File corrupt: too many packages " + NP); |
| 9192 | return; |
| 9193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9194 | for (int ip = 0; ip < NP; ip++) { |
| 9195 | String pkgName = in.readString(); |
| 9196 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9197 | final int NWA = in.readInt(); |
| 9198 | if (NWA > 1000) { |
| 9199 | Slog.w(TAG, "File corrupt: too many wakeup alarms " + NWA); |
| 9200 | return; |
| 9201 | } |
| 9202 | p.mWakeupAlarms.clear(); |
| 9203 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9204 | String tag = in.readString(); |
| 9205 | Counter c = new Counter(mOnBatteryTimeBase); |
| 9206 | c.readSummaryFromParcelLocked(in); |
| 9207 | p.mWakeupAlarms.put(tag, c); |
| 9208 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9209 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9210 | if (NS > 1000) { |
| 9211 | Slog.w(TAG, "File corrupt: too many services " + NS); |
| 9212 | return; |
| 9213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9214 | for (int is = 0; is < NS; is++) { |
| 9215 | String servName = in.readString(); |
| 9216 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 9217 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9219 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9220 | } |
| 9221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | } |
| 9223 | } |
| 9224 | |
| 9225 | /** |
| 9226 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 9227 | * disk. This format does not allow a lossless round-trip. |
| 9228 | * |
| 9229 | * @param out the Parcel to be written to. |
| 9230 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9231 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9232 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9233 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9234 | // Pull the clock time. This may update the time and make a new history entry |
| 9235 | // if we had originally pulled a time before the RTC was set. |
| 9236 | long startClockTime = getStartClockTime(); |
| 9237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 9239 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9240 | |
| 9241 | out.writeInt(VERSION); |
| 9242 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9243 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9246 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9247 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9248 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9249 | out.writeString(mStartPlatformVersion); |
| 9250 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9251 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 9252 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9253 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9254 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9255 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9256 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9257 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 9258 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9259 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 9260 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9261 | mDischargeStepTracker.writeToParcel(out); |
| 9262 | mChargeStepTracker.writeToParcel(out); |
| 9263 | mDailyDischargeStepTracker.writeToParcel(out); |
| 9264 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9265 | if (mDailyPackageChanges != null) { |
| 9266 | final int NPKG = mDailyPackageChanges.size(); |
| 9267 | out.writeInt(NPKG); |
| 9268 | for (int i=0; i<NPKG; i++) { |
| 9269 | PackageChange pc = mDailyPackageChanges.get(i); |
| 9270 | out.writeString(pc.mPackageName); |
| 9271 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 9272 | out.writeInt(pc.mVersionCode); |
| 9273 | } |
| 9274 | } else { |
| 9275 | out.writeInt(0); |
| 9276 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9277 | out.writeLong(mDailyStartTime); |
| 9278 | out.writeLong(mNextMinDailyDeadline); |
| 9279 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9280 | |
| 9281 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9282 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9283 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9284 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9285 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9286 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9287 | mDeviceIdleModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9288 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9289 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9290 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9291 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9292 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9293 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9294 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9295 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9296 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9297 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9298 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9299 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9300 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9301 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9302 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9303 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9304 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 9305 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9306 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9307 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9308 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9309 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9310 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9311 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9312 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9313 | } |
| 9314 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9315 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9316 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9317 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9318 | mBluetoothActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9319 | } |
| 9320 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9321 | mWifiActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9322 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9323 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9324 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9325 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9326 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9327 | out.writeInt(mKernelWakelockStats.size()); |
| 9328 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9329 | Timer kwlt = ent.getValue(); |
| 9330 | if (kwlt != null) { |
| 9331 | out.writeInt(1); |
| 9332 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9333 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9334 | } else { |
| 9335 | out.writeInt(0); |
| 9336 | } |
| 9337 | } |
| 9338 | |
| 9339 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9340 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9341 | SamplingTimer timer = ent.getValue(); |
| 9342 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9343 | out.writeInt(1); |
| 9344 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9345 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9346 | } else { |
| 9347 | out.writeInt(0); |
| 9348 | } |
| 9349 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9350 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9351 | out.writeInt(sNumSpeedSteps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | final int NU = mUidStats.size(); |
| 9353 | out.writeInt(NU); |
| 9354 | for (int iu = 0; iu < NU; iu++) { |
| 9355 | out.writeInt(mUidStats.keyAt(iu)); |
| 9356 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9357 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9358 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9359 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9360 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9361 | } else { |
| 9362 | out.writeInt(0); |
| 9363 | } |
| 9364 | if (u.mFullWifiLockTimer != null) { |
| 9365 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9366 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9367 | } else { |
| 9368 | out.writeInt(0); |
| 9369 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9370 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9371 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9372 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9373 | } else { |
| 9374 | out.writeInt(0); |
| 9375 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9376 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9377 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 9378 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9379 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9380 | } else { |
| 9381 | out.writeInt(0); |
| 9382 | } |
| 9383 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9384 | if (u.mWifiMulticastTimer != null) { |
| 9385 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9386 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9387 | } else { |
| 9388 | out.writeInt(0); |
| 9389 | } |
| 9390 | if (u.mAudioTurnedOnTimer != null) { |
| 9391 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9392 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9393 | } else { |
| 9394 | out.writeInt(0); |
| 9395 | } |
| 9396 | if (u.mVideoTurnedOnTimer != null) { |
| 9397 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9398 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9399 | } else { |
| 9400 | out.writeInt(0); |
| 9401 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9402 | if (u.mFlashlightTurnedOnTimer != null) { |
| 9403 | out.writeInt(1); |
| 9404 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9405 | } else { |
| 9406 | out.writeInt(0); |
| 9407 | } |
| 9408 | if (u.mCameraTurnedOnTimer != null) { |
| 9409 | out.writeInt(1); |
| 9410 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9411 | } else { |
| 9412 | out.writeInt(0); |
| 9413 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9414 | if (u.mForegroundActivityTimer != null) { |
| 9415 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9416 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9417 | } else { |
| 9418 | out.writeInt(0); |
| 9419 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9420 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9421 | if (u.mProcessStateTimer[i] != null) { |
| 9422 | out.writeInt(1); |
| 9423 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9424 | } else { |
| 9425 | out.writeInt(0); |
| 9426 | } |
| 9427 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9428 | if (u.mVibratorOnTimer != null) { |
| 9429 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9430 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9431 | } else { |
| 9432 | out.writeInt(0); |
| 9433 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9434 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9435 | if (u.mUserActivityCounters == null) { |
| 9436 | out.writeInt(0); |
| 9437 | } else { |
| 9438 | out.writeInt(1); |
| 9439 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9440 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9441 | } |
| 9442 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9443 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9444 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9445 | out.writeInt(0); |
| 9446 | } else { |
| 9447 | out.writeInt(1); |
| 9448 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9449 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9450 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9451 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9452 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 9453 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9454 | } |
| 9455 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9456 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 9457 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 9458 | |
| 9459 | out.writeInt(u.mSpeedBins.length); |
| 9460 | for (int i = 0; i < u.mSpeedBins.length; i++) { |
| 9461 | LongSamplingCounter speedBin = u.mSpeedBins[i]; |
| 9462 | if (speedBin != null) { |
| 9463 | out.writeInt(1); |
| 9464 | speedBin.writeSummaryFromParcelLocked(out); |
| 9465 | } else { |
| 9466 | out.writeInt(0); |
| 9467 | } |
| 9468 | } |
| 9469 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9470 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 9471 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9472 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9473 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9474 | out.writeString(wakeStats.keyAt(iw)); |
| 9475 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9476 | if (wl.mTimerFull != null) { |
| 9477 | out.writeInt(1); |
| 9478 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9479 | } else { |
| 9480 | out.writeInt(0); |
| 9481 | } |
| 9482 | if (wl.mTimerPartial != null) { |
| 9483 | out.writeInt(1); |
| 9484 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9485 | } else { |
| 9486 | out.writeInt(0); |
| 9487 | } |
| 9488 | if (wl.mTimerWindow != null) { |
| 9489 | out.writeInt(1); |
| 9490 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9491 | } else { |
| 9492 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9493 | } |
| 9494 | } |
| 9495 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9496 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 9497 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9498 | out.writeInt(NS); |
| 9499 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9500 | out.writeString(syncStats.keyAt(is)); |
| 9501 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9502 | } |
| 9503 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9504 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 9505 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9506 | out.writeInt(NJ); |
| 9507 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9508 | out.writeString(jobStats.keyAt(ij)); |
| 9509 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9510 | } |
| 9511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9512 | int NSE = u.mSensorStats.size(); |
| 9513 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9514 | for (int ise=0; ise<NSE; ise++) { |
| 9515 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 9516 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 9517 | if (se.mTimer != null) { |
| 9518 | out.writeInt(1); |
| 9519 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9520 | } else { |
| 9521 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9522 | } |
| 9523 | } |
| 9524 | |
| 9525 | int NP = u.mProcessStats.size(); |
| 9526 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9527 | for (int ip=0; ip<NP; ip++) { |
| 9528 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 9529 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 9530 | out.writeLong(ps.mUserTime); |
| 9531 | out.writeLong(ps.mSystemTime); |
| 9532 | out.writeLong(ps.mForegroundTime); |
| 9533 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9534 | out.writeInt(ps.mNumCrashes); |
| 9535 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9536 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9537 | } |
| 9538 | |
| 9539 | NP = u.mPackageStats.size(); |
| 9540 | out.writeInt(NP); |
| 9541 | if (NP > 0) { |
| 9542 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 9543 | : u.mPackageStats.entrySet()) { |
| 9544 | out.writeString(ent.getKey()); |
| 9545 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9546 | final int NWA = ps.mWakeupAlarms.size(); |
| 9547 | out.writeInt(NWA); |
| 9548 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9549 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 9550 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 9551 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9552 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9554 | for (int is=0; is<NS; is++) { |
| 9555 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 9556 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 9557 | long time = ss.getStartTimeToNowLocked( |
| 9558 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 9559 | out.writeLong(time); |
| 9560 | out.writeInt(ss.mStarts); |
| 9561 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9562 | } |
| 9563 | } |
| 9564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | public void readFromParcel(Parcel in) { |
| 9569 | readFromParcelLocked(in); |
| 9570 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9572 | void readFromParcelLocked(Parcel in) { |
| 9573 | int magic = in.readInt(); |
| 9574 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9575 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9576 | } |
| 9577 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9578 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9580 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9581 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9582 | mStartPlatformVersion = in.readString(); |
| 9583 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9584 | mUptime = in.readLong(); |
| 9585 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9586 | mRealtime = in.readLong(); |
| 9587 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9588 | mOnBattery = in.readInt() != 0; |
| 9589 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9590 | mOnBatteryTimeBase.readFromParcel(in); |
| 9591 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 9592 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9593 | mScreenState = Display.STATE_UNKNOWN; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9594 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in); |
| 9595 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9596 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, |
| 9597 | in); |
| 9598 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9599 | mInteractive = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9600 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9601 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9602 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in); |
| 9603 | mDeviceIdleModeEnabledTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9604 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9605 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9606 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9607 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 9608 | null, mOnBatteryTimeBase, in); |
| 9609 | } |
| 9610 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase, in); |
| 9611 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9612 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 9613 | null, mOnBatteryTimeBase, in); |
| 9614 | } |
| 9615 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9616 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9617 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9618 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9619 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9620 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); |
| 9621 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, |
| 9622 | in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9623 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9624 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9625 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9626 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9627 | mWifiOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9628 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9629 | mGlobalWifiRunning = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9630 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9631 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9632 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, |
| 9633 | null, mOnBatteryTimeBase, in); |
| 9634 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9635 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9636 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, |
| 9637 | null, mOnBatteryTimeBase, in); |
| 9638 | } |
| 9639 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9640 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, |
| 9641 | null, mOnBatteryTimeBase, in); |
| 9642 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9643 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9644 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9645 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9646 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9647 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9648 | } |
| 9649 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9650 | mHasWifiEnergyReporting = in.readInt() != 0; |
| 9651 | mHasBluetoothEnergyReporting = in.readInt() != 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9652 | mNumConnectivityChange = in.readInt(); |
| 9653 | mLoadedNumConnectivityChange = in.readInt(); |
| 9654 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9655 | mAudioOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9656 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9657 | mVideoOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9658 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9659 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9660 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9661 | mCameraOnNesting = 0; |
| 9662 | mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9663 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9664 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9665 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9666 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9667 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9668 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9669 | mDischargeAmountScreenOn = in.readInt(); |
| 9670 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9671 | mDischargeAmountScreenOff = in.readInt(); |
| 9672 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9673 | mDischargeStepTracker.readFromParcel(in); |
| 9674 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9675 | mLastWriteTime = in.readLong(); |
| 9676 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9677 | mKernelWakelockStats.clear(); |
| 9678 | int NKW = in.readInt(); |
| 9679 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 9680 | if (in.readInt() != 0) { |
| 9681 | String wakelockName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9682 | SamplingTimer kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9683 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 9684 | } |
| 9685 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9686 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9687 | mWakeupReasonStats.clear(); |
| 9688 | int NWR = in.readInt(); |
| 9689 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 9690 | if (in.readInt() != 0) { |
| 9691 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9692 | SamplingTimer timer = new SamplingTimer(mOnBatteryTimeBase, in); |
| 9693 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9694 | } |
| 9695 | } |
| 9696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9697 | mPartialTimers.clear(); |
| 9698 | mFullTimers.clear(); |
| 9699 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9700 | mWifiRunningTimers.clear(); |
| 9701 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9702 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9703 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9704 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9705 | mAudioTurnedOnTimers.clear(); |
| 9706 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9707 | mFlashlightTurnedOnTimers.clear(); |
| 9708 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9709 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9710 | sNumSpeedSteps = in.readInt(); |
| 9711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9712 | int numUids = in.readInt(); |
| 9713 | mUidStats.clear(); |
| 9714 | for (int i = 0; i < numUids; i++) { |
| 9715 | int uid = in.readInt(); |
| 9716 | Uid u = new Uid(uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9717 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9718 | mUidStats.append(uid, u); |
| 9719 | } |
| 9720 | } |
| 9721 | |
| 9722 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9723 | writeToParcelLocked(out, true, flags); |
| 9724 | } |
| 9725 | |
| 9726 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 9727 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9729 | |
| 9730 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9731 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9732 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9733 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9734 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9735 | // Pull the clock time. This may update the time and make a new history entry |
| 9736 | // if we had originally pulled a time before the RTC was set. |
| 9737 | long startClockTime = getStartClockTime(); |
| 9738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9739 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 9740 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9741 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 9742 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9744 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9745 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9746 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9748 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9749 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9750 | out.writeString(mStartPlatformVersion); |
| 9751 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9752 | out.writeLong(mUptime); |
| 9753 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9754 | out.writeLong(mRealtime); |
| 9755 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9756 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9757 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 9758 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 9759 | |
| 9760 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 9761 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9762 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 9763 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9764 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9765 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
| 9766 | mDeviceIdleModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9767 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9768 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 9769 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9770 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 9771 | } |
| 9772 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 9773 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9774 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 9775 | } |
| 9776 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9777 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 9778 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 9779 | } |
| 9780 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 9781 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9782 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9783 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 9784 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 9785 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 9786 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 9787 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9788 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9789 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9790 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9791 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9792 | } |
| 9793 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9794 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 9795 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9796 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9797 | mBluetoothActivityCounters[i].writeToParcel(out); |
| 9798 | } |
| 9799 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9800 | mWifiActivityCounters[i].writeToParcel(out); |
| 9801 | } |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9802 | out.writeInt(mHasWifiEnergyReporting ? 1 : 0); |
| 9803 | out.writeInt(mHasBluetoothEnergyReporting ? 1 : 0); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9804 | out.writeInt(mNumConnectivityChange); |
| 9805 | out.writeInt(mLoadedNumConnectivityChange); |
| 9806 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9807 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9808 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9809 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9810 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9811 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9812 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9813 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 9814 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9815 | out.writeInt(mDischargeAmountScreenOn); |
| 9816 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 9817 | out.writeInt(mDischargeAmountScreenOff); |
| 9818 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9819 | mDischargeStepTracker.writeToParcel(out); |
| 9820 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9821 | out.writeLong(mLastWriteTime); |
| 9822 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9823 | if (inclUids) { |
| 9824 | out.writeInt(mKernelWakelockStats.size()); |
| 9825 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9826 | SamplingTimer kwlt = ent.getValue(); |
| 9827 | if (kwlt != null) { |
| 9828 | out.writeInt(1); |
| 9829 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9830 | kwlt.writeToParcel(out, uSecRealtime); |
| 9831 | } else { |
| 9832 | out.writeInt(0); |
| 9833 | } |
| 9834 | } |
| 9835 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9836 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9837 | SamplingTimer timer = ent.getValue(); |
| 9838 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9839 | out.writeInt(1); |
| 9840 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9841 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9842 | } else { |
| 9843 | out.writeInt(0); |
| 9844 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9845 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9846 | } else { |
| 9847 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9848 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9849 | |
| 9850 | out.writeInt(sNumSpeedSteps); |
| 9851 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9852 | if (inclUids) { |
| 9853 | int size = mUidStats.size(); |
| 9854 | out.writeInt(size); |
| 9855 | for (int i = 0; i < size; i++) { |
| 9856 | out.writeInt(mUidStats.keyAt(i)); |
| 9857 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9858 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9859 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9860 | } |
| 9861 | } else { |
| 9862 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9863 | } |
| 9864 | } |
| 9865 | |
| 9866 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 9867 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 9868 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 9869 | return new BatteryStatsImpl(in); |
| 9870 | } |
| 9871 | |
| 9872 | public BatteryStatsImpl[] newArray(int size) { |
| 9873 | return new BatteryStatsImpl[size]; |
| 9874 | } |
| 9875 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9876 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9877 | public void prepareForDumpLocked() { |
| 9878 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9879 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9880 | |
| 9881 | // Pull the clock time. This may update the time and make a new history entry |
| 9882 | // if we had originally pulled a time before the RTC was set. |
| 9883 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9884 | } |
| 9885 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 9886 | public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9887 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9888 | pw.println("mOnBatteryTimeBase:"); |
| 9889 | mOnBatteryTimeBase.dump(pw, " "); |
| 9890 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 9891 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9892 | Printer pr = new PrintWriterPrinter(pw); |
| 9893 | pr.println("*** Screen timer:"); |
| 9894 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9895 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9896 | pr.println("*** Screen brightness #" + i + ":"); |
| 9897 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9898 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9899 | pr.println("*** Interactive timer:"); |
| 9900 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9901 | pr.println("*** Power save mode timer:"); |
| 9902 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
| 9903 | pr.println("*** Device idle mode timer:"); |
| 9904 | mDeviceIdleModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9905 | pr.println("*** Device idling timer:"); |
| 9906 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9907 | pr.println("*** Phone timer:"); |
| 9908 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9909 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9910 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9911 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9912 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 9913 | pr.println("*** Signal scanning :"); |
| 9914 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9915 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9916 | pr.println("*** Data connection type #" + i + ":"); |
| 9917 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9918 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9919 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9920 | pr.println("*** Mobile network active timer:"); |
| 9921 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9922 | pr.println("*** Mobile network active adjusted timer:"); |
| 9923 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9924 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9925 | pr.println("*** Wifi timer:"); |
| 9926 | mWifiOnTimer.logState(pr, " "); |
| 9927 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9928 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9929 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9930 | pr.println("*** Wifi state #" + i + ":"); |
| 9931 | mWifiStateTimer[i].logState(pr, " "); |
| 9932 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9933 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9934 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 9935 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 9936 | } |
| 9937 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9938 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 9939 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 9940 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9941 | pr.println("*** Flashlight timer:"); |
| 9942 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9943 | pr.println("*** Camera timer:"); |
| 9944 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9945 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 9946 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9947 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9948 | } |