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 | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 98 | public static final boolean DEBUG_ENERGY = false; |
| 99 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY || false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 100 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 101 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 102 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 103 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | // 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] | 106 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
| 108 | // Current on-disk Parcel version |
Adam Lesinski | df6235c | 2015-06-08 15:04:16 -0700 | [diff] [blame] | 109 | private static final int VERSION = 127 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 110 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 111 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 112 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 113 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 114 | // No, really, THIS is the maximum number of items we will record in the history. |
| 115 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 116 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 117 | // The maximum number of names wakelocks we will keep track of |
| 118 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 119 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 120 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 121 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 122 | private static int sNumSpeedSteps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 124 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 125 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 126 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 128 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 129 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 130 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 131 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 132 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 133 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 134 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 135 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 136 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 137 | private final KernelCpuSpeedReader mKernelCpuSpeedReader = new KernelCpuSpeedReader(); |
| 138 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 139 | public interface BatteryCallback { |
| 140 | public void batteryNeedsCpuUpdate(); |
| 141 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 142 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 146 | public MyHandler(Looper looper) { |
| 147 | super(looper, null, true); |
| 148 | } |
| 149 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 150 | @Override |
| 151 | public void handleMessage(Message msg) { |
| 152 | BatteryCallback cb = mCallback; |
| 153 | switch (msg.what) { |
| 154 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 155 | synchronized (BatteryStatsImpl.this) { |
| 156 | updateCpuTimeLocked(); |
| 157 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 158 | if (cb != null) { |
| 159 | cb.batteryNeedsCpuUpdate(); |
| 160 | } |
| 161 | break; |
| 162 | case MSG_REPORT_POWER_CHANGE: |
| 163 | if (cb != null) { |
| 164 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 165 | } |
| 166 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 167 | case MSG_REPORT_CHARGING: |
| 168 | if (cb != null) { |
| 169 | final String action; |
| 170 | synchronized (BatteryStatsImpl.this) { |
| 171 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 172 | : BatteryManager.ACTION_DISCHARGING; |
| 173 | } |
| 174 | Intent intent = new Intent(action); |
| 175 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 176 | cb.batterySendBroadcast(intent); |
| 177 | } |
| 178 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 183 | public interface ExternalStatsSync { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 184 | void scheduleSync(String reason); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 185 | void scheduleWifiSync(String reason); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 188 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 189 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 190 | |
| 191 | private BatteryCallback mCallback; |
| 192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 194 | * Mapping isolated uids to the actual owning app uid. |
| 195 | */ |
| 196 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 197 | |
| 198 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | * The statistics we have collected organized by uids. |
| 200 | */ |
| 201 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 202 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 203 | |
| 204 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 205 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 206 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 207 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 208 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 209 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 210 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
| 211 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 212 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 213 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 214 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 215 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 216 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 217 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 218 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 219 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 220 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 222 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 223 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | // These are the objects that will want to do something when the device |
| 226 | // is unplugged from power. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 227 | final TimeBase mOnBatteryTimeBase = new TimeBase(); |
| 228 | |
| 229 | // These are the objects that will want to do something when the device |
| 230 | // is unplugged from power *and* the screen is off. |
| 231 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 232 | |
| 233 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 234 | // CPU update, even if we aren't currently running wake locks. |
| 235 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 236 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 237 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 238 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 239 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 240 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 241 | long mHistoryBaseTime; |
| 242 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 243 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 244 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 245 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 246 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 247 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 248 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 249 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 250 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 251 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 252 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 253 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 254 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 255 | int[] mReadHistoryUids; |
| 256 | int mReadHistoryChars; |
| 257 | int mNextHistoryTagIdx = 0; |
| 258 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 259 | int mHistoryBufferLastPos = -1; |
| 260 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 261 | int mActiveHistoryStates = 0xffffffff; |
| 262 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 263 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 264 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 265 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 266 | |
| 267 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 268 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 269 | HistoryItem mHistory; |
| 270 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 271 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 272 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 273 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 274 | // Used by computeHistoryStepDetails |
| 275 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 276 | byte mLastHistoryStepLevel = 0; |
| 277 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 278 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 279 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 280 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 281 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 282 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 283 | */ |
| 284 | long mLastStepCpuUserTime; |
| 285 | long mCurStepCpuUserTime; |
| 286 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 287 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 288 | */ |
| 289 | long mLastStepCpuSystemTime; |
| 290 | long mCurStepCpuSystemTime; |
| 291 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 292 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 293 | */ |
| 294 | long mLastStepStatUserTime; |
| 295 | long mLastStepStatSystemTime; |
| 296 | long mLastStepStatIOWaitTime; |
| 297 | long mLastStepStatIrqTime; |
| 298 | long mLastStepStatSoftIrqTime; |
| 299 | long mLastStepStatIdleTime; |
| 300 | long mCurStepStatUserTime; |
| 301 | long mCurStepStatSystemTime; |
| 302 | long mCurStepStatIOWaitTime; |
| 303 | long mCurStepStatIrqTime; |
| 304 | long mCurStepStatSoftIrqTime; |
| 305 | long mCurStepStatIdleTime; |
| 306 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 307 | private HistoryItem mHistoryIterator; |
| 308 | private boolean mReadOverflow; |
| 309 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | int mStartCount; |
| 312 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 313 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 314 | String mStartPlatformVersion; |
| 315 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | long mUptime; |
| 318 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | long mRealtime; |
| 320 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 321 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 322 | int mWakeLockNesting; |
| 323 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 324 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 325 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 326 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 327 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 328 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 329 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 330 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 331 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 332 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 333 | boolean mInteractive; |
| 334 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 335 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 336 | boolean mPowerSaveModeEnabled; |
| 337 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 338 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 339 | boolean mDeviceIdling; |
| 340 | StopwatchTimer mDeviceIdlingTimer; |
| 341 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 342 | boolean mDeviceIdleModeEnabled; |
| 343 | StopwatchTimer mDeviceIdleModeEnabledTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 346 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 347 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 348 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 349 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 350 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 351 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 352 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 353 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 354 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 355 | StopwatchTimer mFlashlightOnTimer; |
| 356 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 357 | int mCameraOnNesting; |
| 358 | StopwatchTimer mCameraOnTimer; |
| 359 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 360 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 361 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 362 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 363 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 364 | |
| 365 | StopwatchTimer mPhoneSignalScanningTimer; |
| 366 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 367 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 368 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 369 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 370 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 371 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 372 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 373 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 374 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 375 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 376 | final LongSamplingCounter[] mBluetoothActivityCounters = |
| 377 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 378 | |
| 379 | final LongSamplingCounter[] mWifiActivityCounters = |
| 380 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 381 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 382 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 383 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 384 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 385 | boolean mGlobalWifiRunning; |
| 386 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 387 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 388 | int mWifiState = -1; |
| 389 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 390 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 391 | int mWifiSupplState = -1; |
| 392 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 393 | |
| 394 | int mWifiSignalStrengthBin = -1; |
| 395 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 396 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 397 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 398 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 399 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 400 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 401 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 402 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 403 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 404 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 405 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 406 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | /** |
| 409 | * These provide time bases that discount the time the device is plugged |
| 410 | * in to power. |
| 411 | */ |
| 412 | boolean mOnBattery; |
| 413 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 414 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 415 | /** |
| 416 | * External reporting of whether the device is actually charging. |
| 417 | */ |
| 418 | boolean mCharging = true; |
| 419 | int mLastChargingStateLevel; |
| 420 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 421 | /* |
| 422 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 423 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 424 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 425 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 426 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 427 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 428 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 429 | int mLowDischargeAmountSinceCharge; |
| 430 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 431 | int mDischargeScreenOnUnplugLevel; |
| 432 | int mDischargeScreenOffUnplugLevel; |
| 433 | int mDischargeAmountScreenOn; |
| 434 | int mDischargeAmountScreenOnSinceCharge; |
| 435 | int mDischargeAmountScreenOff; |
| 436 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 437 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 438 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 439 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 440 | int mInitStepMode = 0; |
| 441 | int mCurStepMode = 0; |
| 442 | int mModStepMode = 0; |
| 443 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 444 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 445 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 446 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 447 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 448 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 449 | |
| 450 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 451 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 452 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 453 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 454 | |
| 455 | static final int MAX_DAILY_ITEMS = 10; |
| 456 | |
| 457 | long mDailyStartTime = 0; |
| 458 | long mNextMinDailyDeadline = 0; |
| 459 | long mNextMaxDailyDeadline = 0; |
| 460 | |
| 461 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 464 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 465 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 466 | private int mPhoneServiceStateRaw = -1; |
| 467 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 468 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 469 | private int mNumConnectivityChange; |
| 470 | private int mLoadedNumConnectivityChange; |
| 471 | private int mUnpluggedNumConnectivityChange; |
| 472 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 473 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 474 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 475 | private PowerProfile mPowerProfile; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 476 | private boolean mHasWifiEnergyReporting = false; |
| 477 | private boolean mHasBluetoothEnergyReporting = false; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 478 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 479 | /* |
| 480 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 481 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 482 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 483 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 484 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 485 | return mKernelWakelockStats; |
| 486 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 487 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 488 | String mLastWakeupReason = null; |
| 489 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 490 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 491 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 492 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 493 | return mWakeupReasonStats; |
| 494 | } |
| 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 497 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 498 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 499 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 500 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 501 | mExternalSync = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 502 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 505 | public static interface TimeBaseObs { |
| 506 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 507 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 508 | } |
| 509 | |
| 510 | static class TimeBase { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 511 | private final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 512 | |
| 513 | private long mUptime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 514 | private long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 515 | |
| 516 | private boolean mRunning; |
| 517 | |
| 518 | private long mPastUptime; |
| 519 | private long mUptimeStart; |
| 520 | private long mPastRealtime; |
| 521 | private long mRealtimeStart; |
| 522 | private long mUnpluggedUptime; |
| 523 | private long mUnpluggedRealtime; |
| 524 | |
| 525 | public void dump(PrintWriter pw, String prefix) { |
| 526 | StringBuilder sb = new StringBuilder(128); |
| 527 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 528 | sb.setLength(0); |
| 529 | sb.append(prefix); |
| 530 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 531 | formatTimeMs(sb, mUptime / 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("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 536 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 537 | pw.println(sb.toString()); |
| 538 | sb.setLength(0); |
| 539 | sb.append(prefix); |
| 540 | sb.append("mPastUptime="); |
| 541 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 542 | formatTimeMs(sb, mUptimeStart / 1000); |
| 543 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 544 | pw.println(sb.toString()); |
| 545 | sb.setLength(0); |
| 546 | sb.append(prefix); |
| 547 | sb.append("mPastRealtime="); |
| 548 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 549 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 550 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 551 | pw.println(sb.toString()); |
| 552 | } |
| 553 | |
| 554 | public void add(TimeBaseObs observer) { |
| 555 | mObservers.add(observer); |
| 556 | } |
| 557 | |
| 558 | public void remove(TimeBaseObs observer) { |
| 559 | if (!mObservers.remove(observer)) { |
| 560 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | public void init(long uptime, long realtime) { |
| 565 | mRealtime = 0; |
| 566 | mUptime = 0; |
| 567 | mPastUptime = 0; |
| 568 | mPastRealtime = 0; |
| 569 | mUptimeStart = uptime; |
| 570 | mRealtimeStart = realtime; |
| 571 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 572 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 573 | } |
| 574 | |
| 575 | public void reset(long uptime, long realtime) { |
| 576 | if (!mRunning) { |
| 577 | mPastUptime = 0; |
| 578 | mPastRealtime = 0; |
| 579 | } else { |
| 580 | mUptimeStart = uptime; |
| 581 | mRealtimeStart = realtime; |
| 582 | mUnpluggedUptime = getUptime(uptime); |
| 583 | mUnpluggedRealtime = getRealtime(realtime); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | public long computeUptime(long curTime, int which) { |
| 588 | switch (which) { |
| 589 | case STATS_SINCE_CHARGED: |
| 590 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 591 | case STATS_CURRENT: |
| 592 | return getUptime(curTime); |
| 593 | case STATS_SINCE_UNPLUGGED: |
| 594 | return getUptime(curTime) - mUnpluggedUptime; |
| 595 | } |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | public long computeRealtime(long curTime, int which) { |
| 600 | switch (which) { |
| 601 | case STATS_SINCE_CHARGED: |
| 602 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 603 | case STATS_CURRENT: |
| 604 | return getRealtime(curTime); |
| 605 | case STATS_SINCE_UNPLUGGED: |
| 606 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 607 | } |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | public long getUptime(long curTime) { |
| 612 | long time = mPastUptime; |
| 613 | if (mRunning) { |
| 614 | time += curTime - mUptimeStart; |
| 615 | } |
| 616 | return time; |
| 617 | } |
| 618 | |
| 619 | public long getRealtime(long curTime) { |
| 620 | long time = mPastRealtime; |
| 621 | if (mRunning) { |
| 622 | time += curTime - mRealtimeStart; |
| 623 | } |
| 624 | return time; |
| 625 | } |
| 626 | |
| 627 | public long getUptimeStart() { |
| 628 | return mUptimeStart; |
| 629 | } |
| 630 | |
| 631 | public long getRealtimeStart() { |
| 632 | return mRealtimeStart; |
| 633 | } |
| 634 | |
| 635 | public boolean isRunning() { |
| 636 | return mRunning; |
| 637 | } |
| 638 | |
| 639 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 640 | if (mRunning != running) { |
| 641 | mRunning = running; |
| 642 | if (running) { |
| 643 | mUptimeStart = uptime; |
| 644 | mRealtimeStart = realtime; |
| 645 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 646 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 647 | |
| 648 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 649 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 650 | } |
| 651 | } else { |
| 652 | mPastUptime += uptime - mUptimeStart; |
| 653 | mPastRealtime += realtime - mRealtimeStart; |
| 654 | |
| 655 | long batteryUptime = getUptime(uptime); |
| 656 | long batteryRealtime = getRealtime(realtime); |
| 657 | |
| 658 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 659 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 660 | } |
| 661 | } |
| 662 | return true; |
| 663 | } |
| 664 | return false; |
| 665 | } |
| 666 | |
| 667 | public void readSummaryFromParcel(Parcel in) { |
| 668 | mUptime = in.readLong(); |
| 669 | mRealtime = in.readLong(); |
| 670 | } |
| 671 | |
| 672 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 673 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 674 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 675 | } |
| 676 | |
| 677 | public void readFromParcel(Parcel in) { |
| 678 | mRunning = false; |
| 679 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 680 | mPastUptime = in.readLong(); |
| 681 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 682 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 683 | mPastRealtime = in.readLong(); |
| 684 | mRealtimeStart = in.readLong(); |
| 685 | mUnpluggedUptime = in.readLong(); |
| 686 | mUnpluggedRealtime = in.readLong(); |
| 687 | } |
| 688 | |
| 689 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 690 | final long runningUptime = getUptime(uptime); |
| 691 | final long runningRealtime = getRealtime(realtime); |
| 692 | out.writeLong(mUptime); |
| 693 | out.writeLong(runningUptime); |
| 694 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 695 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 696 | out.writeLong(runningRealtime); |
| 697 | out.writeLong(mRealtimeStart); |
| 698 | out.writeLong(mUnpluggedUptime); |
| 699 | out.writeLong(mUnpluggedRealtime); |
| 700 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 704 | * State for keeping track of counting information. |
| 705 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 706 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 707 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 708 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 709 | int mLoadedCount; |
| 710 | int mLastCount; |
| 711 | int mUnpluggedCount; |
| 712 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 713 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 714 | Counter(TimeBase timeBase, Parcel in) { |
| 715 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 716 | mPluggedCount = in.readInt(); |
| 717 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 718 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 719 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 720 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 721 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 724 | Counter(TimeBase timeBase) { |
| 725 | mTimeBase = timeBase; |
| 726 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 727 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 728 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 729 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 730 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 731 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 732 | out.writeInt(mUnpluggedCount); |
| 733 | } |
| 734 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 735 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 736 | mUnpluggedCount = mPluggedCount; |
| 737 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 740 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 741 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 742 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 743 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 744 | /** |
| 745 | * Writes a possibly null Counter to a Parcel. |
| 746 | * |
| 747 | * @param out the Parcel to be written to. |
| 748 | * @param counter a Counter, or null. |
| 749 | */ |
| 750 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 751 | if (counter == null) { |
| 752 | out.writeInt(0); // indicates null |
| 753 | return; |
| 754 | } |
| 755 | out.writeInt(1); // indicates non-null |
| 756 | |
| 757 | counter.writeToParcel(out); |
| 758 | } |
| 759 | |
| 760 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 761 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 762 | int val = mCount.get(); |
| 763 | if (which == STATS_SINCE_UNPLUGGED) { |
| 764 | val -= mUnpluggedCount; |
| 765 | } else if (which != STATS_SINCE_CHARGED) { |
| 766 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | return val; |
| 770 | } |
| 771 | |
| 772 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 773 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 774 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 775 | + " mUnpluggedCount=" + mUnpluggedCount |
| 776 | + " mPluggedCount=" + mPluggedCount); |
| 777 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 778 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 779 | void stepAtomic() { |
| 780 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 783 | /** |
| 784 | * Clear state of this counter. |
| 785 | */ |
| 786 | void reset(boolean detachIfReset) { |
| 787 | mCount.set(0); |
| 788 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 789 | if (detachIfReset) { |
| 790 | detach(); |
| 791 | } |
| 792 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 793 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 794 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 795 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 796 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 797 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 798 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 799 | int count = mCount.get(); |
| 800 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 804 | mLoadedCount = in.readInt(); |
| 805 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 806 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 807 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 810 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 811 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 812 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 813 | long mCount; |
| 814 | long mLoadedCount; |
| 815 | long mLastCount; |
| 816 | long mUnpluggedCount; |
| 817 | long mPluggedCount; |
| 818 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 819 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 820 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 821 | mPluggedCount = in.readLong(); |
| 822 | mCount = mPluggedCount; |
| 823 | mLoadedCount = in.readLong(); |
| 824 | mLastCount = 0; |
| 825 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 826 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 829 | LongSamplingCounter(TimeBase timeBase) { |
| 830 | mTimeBase = timeBase; |
| 831 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | public void writeToParcel(Parcel out) { |
| 835 | out.writeLong(mCount); |
| 836 | out.writeLong(mLoadedCount); |
| 837 | out.writeLong(mUnpluggedCount); |
| 838 | } |
| 839 | |
| 840 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 841 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 842 | mUnpluggedCount = mPluggedCount; |
| 843 | mCount = mPluggedCount; |
| 844 | } |
| 845 | |
| 846 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 847 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 848 | mPluggedCount = mCount; |
| 849 | } |
| 850 | |
| 851 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 852 | long val = mCount; |
| 853 | if (which == STATS_SINCE_UNPLUGGED) { |
| 854 | val -= mUnpluggedCount; |
| 855 | } else if (which != STATS_SINCE_CHARGED) { |
| 856 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | return val; |
| 860 | } |
| 861 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 862 | @Override |
| 863 | public void logState(Printer pw, String prefix) { |
| 864 | pw.println(prefix + "mCount=" + mCount |
| 865 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 866 | + " mUnpluggedCount=" + mUnpluggedCount |
| 867 | + " mPluggedCount=" + mPluggedCount); |
| 868 | } |
| 869 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 870 | void addCountLocked(long count) { |
| 871 | mCount += count; |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Clear state of this counter. |
| 876 | */ |
| 877 | void reset(boolean detachIfReset) { |
| 878 | mCount = 0; |
| 879 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 880 | if (detachIfReset) { |
| 881 | detach(); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 886 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | void writeSummaryFromParcelLocked(Parcel out) { |
| 890 | out.writeLong(mCount); |
| 891 | } |
| 892 | |
| 893 | void readSummaryFromParcelLocked(Parcel in) { |
| 894 | mLoadedCount = in.readLong(); |
| 895 | mCount = mLoadedCount; |
| 896 | mLastCount = 0; |
| 897 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 898 | } |
| 899 | } |
| 900 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 901 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | * State for keeping track of timing information. |
| 903 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 904 | 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] | 905 | final int mType; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 906 | final TimeBase mTimeBase; |
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 | int mCount; |
| 909 | int mLoadedCount; |
| 910 | int mLastCount; |
| 911 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | // Times are in microseconds for better accuracy when dividing by the |
| 914 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | /** |
| 917 | * The total time we have accumulated since the start of the original |
| 918 | * boot, to the last time something interesting happened in the |
| 919 | * current run. |
| 920 | */ |
| 921 | long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | /** |
| 924 | * The total time we loaded for the previous runs. Subtract this from |
| 925 | * mTotalTime to find the time for the current run of the system. |
| 926 | */ |
| 927 | long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | /** |
| 930 | * The run time of the last run of the system, as loaded from the |
| 931 | * saved data. |
| 932 | */ |
| 933 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | /** |
| 936 | * The value of mTotalTime when unplug() was last called. Subtract |
| 937 | * this from mTotalTime to find the time since the last unplug from |
| 938 | * power. |
| 939 | */ |
| 940 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 941 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 942 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 943 | * The total time this timer has been running until the latest mark has been set. |
| 944 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 945 | */ |
| 946 | long mTimeBeforeMark; |
| 947 | |
| 948 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 949 | * Constructs from a parcel. |
| 950 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 951 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 952 | * @param in |
| 953 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 954 | Timer(int type, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 956 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | mCount = in.readInt(); |
| 959 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 960 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | mUnpluggedCount = in.readInt(); |
| 962 | mTotalTime = in.readLong(); |
| 963 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 964 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 966 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 967 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 968 | 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] | 969 | } |
| 970 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 971 | Timer(int type, TimeBase timeBase) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 973 | mTimeBase = timeBase; |
| 974 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 976 | |
| 977 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 978 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 979 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 980 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 981 | /** |
| 982 | * Clear state of this timer. Returns true if the timer is inactive |
| 983 | * so can be completely dropped. |
| 984 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 985 | boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 986 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 987 | mCount = mLoadedCount = mLastCount = 0; |
| 988 | if (detachIfReset) { |
| 989 | detach(); |
| 990 | } |
| 991 | return true; |
| 992 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 993 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 994 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 995 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 996 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 997 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 998 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 999 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1000 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | out.writeInt(mCount); |
| 1002 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1004 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1007 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1010 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1011 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1013 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1015 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1016 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1017 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | mUnpluggedCount = mCount; |
| 1019 | if (DEBUG && mType < 0) { |
| 1020 | Log.v(TAG, "unplug #" + mType |
| 1021 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1022 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1023 | } |
| 1024 | } |
| 1025 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1026 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1027 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1028 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1029 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1030 | + " old mTotalTime=" + mTotalTime); |
| 1031 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1032 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1033 | mCount = computeCurrentCountLocked(); |
| 1034 | if (DEBUG && mType < 0) { |
| 1035 | Log.v(TAG, "plug #" + mType |
| 1036 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | } |
| 1038 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | /** |
| 1041 | * Writes a possibly null Timer to a Parcel. |
| 1042 | * |
| 1043 | * @param out the Parcel to be written to. |
| 1044 | * @param timer a Timer, or null. |
| 1045 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1046 | 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] | 1047 | if (timer == null) { |
| 1048 | out.writeInt(0); // indicates null |
| 1049 | return; |
| 1050 | } |
| 1051 | out.writeInt(1); // indicates non-null |
| 1052 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1053 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1057 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1058 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1059 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1060 | val -= mUnpluggedTime; |
| 1061 | } else if (which != STATS_SINCE_CHARGED) { |
| 1062 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | return val; |
| 1066 | } |
| 1067 | |
| 1068 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1069 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1070 | int val = computeCurrentCountLocked(); |
| 1071 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1072 | val -= mUnpluggedCount; |
| 1073 | } else if (which != STATS_SINCE_CHARGED) { |
| 1074 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | return val; |
| 1078 | } |
| 1079 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1080 | @Override |
| 1081 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1082 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1083 | return val - mTimeBeforeMark; |
| 1084 | } |
| 1085 | |
| 1086 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1087 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1088 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1090 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1091 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1093 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1095 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1096 | |
| 1097 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1098 | void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1099 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1100 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1101 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void readSummaryFromParcelLocked(Parcel in) { |
| 1105 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1106 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1107 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1108 | mUnpluggedTime = mTotalTime; |
| 1109 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1110 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1111 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1112 | |
| 1113 | // When reading the summary, we set the mark to be the latest information. |
| 1114 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1117 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1118 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1119 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1120 | /** |
| 1121 | * The most recent reported count from /proc/wakelocks. |
| 1122 | */ |
| 1123 | int mCurrentReportedCount; |
| 1124 | |
| 1125 | /** |
| 1126 | * The reported count from /proc/wakelocks when unplug() was last |
| 1127 | * called. |
| 1128 | */ |
| 1129 | int mUnpluggedReportedCount; |
| 1130 | |
| 1131 | /** |
| 1132 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1133 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1134 | long mCurrentReportedTotalTime; |
| 1135 | |
| 1136 | |
| 1137 | /** |
| 1138 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1139 | * called. |
| 1140 | */ |
| 1141 | long mUnpluggedReportedTotalTime; |
| 1142 | |
| 1143 | /** |
| 1144 | * Whether we are currently in a discharge cycle. |
| 1145 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1146 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1147 | |
| 1148 | /** |
| 1149 | * Whether we are currently recording reported values. |
| 1150 | */ |
| 1151 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1152 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1153 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1154 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1155 | */ |
| 1156 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1157 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1158 | SamplingTimer(TimeBase timeBase, Parcel in) { |
| 1159 | super(0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1160 | mCurrentReportedCount = in.readInt(); |
| 1161 | mUnpluggedReportedCount = in.readInt(); |
| 1162 | mCurrentReportedTotalTime = in.readLong(); |
| 1163 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1164 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1165 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1166 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1167 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1168 | SamplingTimer(TimeBase timeBase, boolean trackReportedValues) { |
| 1169 | super(0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1170 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1171 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1172 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1173 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1174 | public void setStale() { |
| 1175 | mTrackingReportedValues = false; |
| 1176 | mUnpluggedReportedTotalTime = 0; |
| 1177 | mUnpluggedReportedCount = 0; |
| 1178 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1179 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1180 | public void setUpdateVersion(int version) { |
| 1181 | mUpdateVersion = version; |
| 1182 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1183 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1184 | public int getUpdateVersion() { |
| 1185 | return mUpdateVersion; |
| 1186 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1187 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1188 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1189 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1190 | // Updating the reported value for the first time. |
| 1191 | mUnpluggedReportedCount = count; |
| 1192 | // If we are receiving an update update mTrackingReportedValues; |
| 1193 | mTrackingReportedValues = true; |
| 1194 | } |
| 1195 | mCurrentReportedCount = count; |
| 1196 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1197 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1198 | public void addCurrentReportedCount(int delta) { |
| 1199 | updateCurrentReportedCount(mCurrentReportedCount + delta); |
| 1200 | } |
| 1201 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1202 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1203 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1204 | // Updating the reported value for the first time. |
| 1205 | mUnpluggedReportedTotalTime = totalTime; |
| 1206 | // If we are receiving an update update mTrackingReportedValues; |
| 1207 | mTrackingReportedValues = true; |
| 1208 | } |
| 1209 | mCurrentReportedTotalTime = totalTime; |
| 1210 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1211 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1212 | public void addCurrentReportedTotalTime(long delta) { |
| 1213 | updateCurrentReportedTotalTime(mCurrentReportedTotalTime + delta); |
| 1214 | } |
| 1215 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1216 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1217 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1218 | if (mTrackingReportedValues) { |
| 1219 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1220 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1221 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1222 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1225 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1226 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1227 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1228 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1229 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1230 | public void logState(Printer pw, String prefix) { |
| 1231 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1232 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1233 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1234 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1235 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 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 long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1239 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1240 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1241 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1242 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1243 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1244 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1245 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1246 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1247 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1248 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1249 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1250 | out.writeInt(mCurrentReportedCount); |
| 1251 | out.writeInt(mUnpluggedReportedCount); |
| 1252 | out.writeLong(mCurrentReportedTotalTime); |
| 1253 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1254 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1256 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1257 | boolean reset(boolean detachIfReset) { |
| 1258 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1259 | setStale(); |
| 1260 | return true; |
| 1261 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1262 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1263 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 1264 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1265 | out.writeLong(mCurrentReportedTotalTime); |
| 1266 | out.writeInt(mCurrentReportedCount); |
| 1267 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1268 | } |
| 1269 | |
| 1270 | void readSummaryFromParcelLocked(Parcel in) { |
| 1271 | super.readSummaryFromParcelLocked(in); |
| 1272 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1273 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1274 | mTrackingReportedValues = in.readInt() == 1; |
| 1275 | } |
| 1276 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1277 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1278 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1279 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1280 | * for a pre-determined amount. |
| 1281 | */ |
| 1282 | public static final class BatchTimer extends Timer { |
| 1283 | final Uid mUid; |
| 1284 | |
| 1285 | /** |
| 1286 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1287 | */ |
| 1288 | long mLastAddedTime; |
| 1289 | |
| 1290 | /** |
| 1291 | * The last duration that we added to the timer. This is in microseconds. |
| 1292 | */ |
| 1293 | long mLastAddedDuration; |
| 1294 | |
| 1295 | /** |
| 1296 | * Whether we are currently in a discharge cycle. |
| 1297 | */ |
| 1298 | boolean mInDischarge; |
| 1299 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1300 | BatchTimer(Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1301 | super(type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1302 | mUid = uid; |
| 1303 | mLastAddedTime = in.readLong(); |
| 1304 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1305 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1308 | BatchTimer(Uid uid, int type, TimeBase timeBase) { |
| 1309 | super(type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1310 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1311 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1315 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1316 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1317 | out.writeLong(mLastAddedTime); |
| 1318 | out.writeLong(mLastAddedDuration); |
| 1319 | } |
| 1320 | |
| 1321 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1322 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1323 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 1324 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1325 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1329 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1330 | recomputeLastDuration(elapsedRealtime, false); |
| 1331 | mInDischarge = true; |
| 1332 | // If we are still within the last added duration, then re-added whatever remains. |
| 1333 | if (mLastAddedTime == elapsedRealtime) { |
| 1334 | mTotalTime += mLastAddedDuration; |
| 1335 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1336 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | @Override |
| 1340 | public void logState(Printer pw, String prefix) { |
| 1341 | super.logState(pw, prefix); |
| 1342 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1343 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1344 | } |
| 1345 | |
| 1346 | private long computeOverage(long curTime) { |
| 1347 | if (mLastAddedTime > 0) { |
| 1348 | return mLastTime + mLastAddedDuration - curTime; |
| 1349 | } |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1354 | final long overage = computeOverage(curTime); |
| 1355 | if (overage > 0) { |
| 1356 | // Aborting before the duration ran out -- roll back the remaining |
| 1357 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1358 | // actually add the time. |
| 1359 | if (mInDischarge) { |
| 1360 | mTotalTime -= overage; |
| 1361 | } |
| 1362 | if (abort) { |
| 1363 | mLastAddedTime = 0; |
| 1364 | } else { |
| 1365 | mLastAddedTime = curTime; |
| 1366 | mLastAddedDuration -= overage; |
| 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1372 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1373 | recomputeLastDuration(now, true); |
| 1374 | mLastAddedTime = now; |
| 1375 | mLastAddedDuration = durationMillis * 1000; |
| 1376 | if (mInDischarge) { |
| 1377 | mTotalTime += mLastAddedDuration; |
| 1378 | mCount++; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1383 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1384 | recomputeLastDuration(now, true); |
| 1385 | } |
| 1386 | |
| 1387 | @Override |
| 1388 | protected int computeCurrentCountLocked() { |
| 1389 | return mCount; |
| 1390 | } |
| 1391 | |
| 1392 | @Override |
| 1393 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1394 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1395 | if (overage > 0) { |
| 1396 | return mTotalTime = overage; |
| 1397 | } |
| 1398 | return mTotalTime; |
| 1399 | } |
| 1400 | |
| 1401 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1402 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1403 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1404 | recomputeLastDuration(now, true); |
| 1405 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1406 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1407 | return !stillActive; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1412 | * State for keeping track of timing information. |
| 1413 | */ |
| 1414 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1415 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1416 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1417 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1418 | int mNesting; |
| 1419 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1420 | /** |
| 1421 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1422 | * subtract this from the current battery time to find the amount of |
| 1423 | * time we have been running since we last computed an update. |
| 1424 | */ |
| 1425 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1426 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1427 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1428 | * 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] | 1429 | * was actually held for an interesting duration. |
| 1430 | */ |
| 1431 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1432 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1433 | long mTimeout; |
| 1434 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1435 | /** |
| 1436 | * For partial wake locks, keep track of whether we are in the list |
| 1437 | * to consume CPU cycles. |
| 1438 | */ |
| 1439 | boolean mInList; |
| 1440 | |
| 1441 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1442 | TimeBase timeBase, Parcel in) { |
| 1443 | super(type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1444 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1445 | mTimerPool = timerPool; |
| 1446 | mUpdateTime = in.readLong(); |
| 1447 | } |
| 1448 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1449 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1450 | TimeBase timeBase) { |
| 1451 | super(type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1452 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1453 | mTimerPool = timerPool; |
| 1454 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1455 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1456 | void setTimeout(long timeout) { |
| 1457 | mTimeout = timeout; |
| 1458 | } |
| 1459 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1460 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1461 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1462 | out.writeLong(mUpdateTime); |
| 1463 | } |
| 1464 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1465 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1466 | if (mNesting > 0) { |
| 1467 | if (DEBUG && mType < 0) { |
| 1468 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1469 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1470 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1471 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1472 | if (DEBUG && mType < 0) { |
| 1473 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | public void logState(Printer pw, String prefix) { |
| 1479 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1480 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | + " mAcquireTime=" + mAcquireTime); |
| 1482 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1483 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1484 | void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1486 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1487 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | if (mTimerPool != null) { |
| 1489 | // Accumulate time to all currently active timers before adding |
| 1490 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1491 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | // Add this timer to the active pool |
| 1493 | mTimerPool.add(this); |
| 1494 | } |
| 1495 | // Increment the count |
| 1496 | mCount++; |
| 1497 | mAcquireTime = mTotalTime; |
| 1498 | if (DEBUG && mType < 0) { |
| 1499 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1500 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1501 | + " mAcquireTime=" + mAcquireTime); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1506 | boolean isRunningLocked() { |
| 1507 | return mNesting > 0; |
| 1508 | } |
| 1509 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1510 | void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | // Ignore attempt to stop a timer that isn't running |
| 1512 | if (mNesting == 0) { |
| 1513 | return; |
| 1514 | } |
| 1515 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1516 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | if (mTimerPool != null) { |
| 1518 | // Accumulate time to all active counters, scaled by the total |
| 1519 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1520 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | // Remove this timer from the active pool |
| 1522 | mTimerPool.remove(this); |
| 1523 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | mNesting = 1; |
| 1525 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1526 | mNesting = 0; |
| 1527 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | if (DEBUG && mType < 0) { |
| 1530 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1531 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1532 | + " mAcquireTime=" + mAcquireTime); |
| 1533 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | if (mTotalTime == mAcquireTime) { |
| 1536 | // If there was no change in the time, then discard this |
| 1537 | // count. A somewhat cheezy strategy, but hey. |
| 1538 | mCount--; |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1543 | void stopAllRunningLocked(long elapsedRealtimeMs) { |
| 1544 | if (mNesting > 0) { |
| 1545 | mNesting = 1; |
| 1546 | stopRunningLocked(elapsedRealtimeMs); |
| 1547 | } |
| 1548 | } |
| 1549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | // Update the total time for all other running Timers with the same type as this Timer |
| 1551 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1552 | private static long refreshTimersLocked(long batteryRealtime, |
| 1553 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1554 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | final int N = pool.size(); |
| 1556 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1557 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1559 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1560 | final long myTime = heldTime / N; |
| 1561 | if (t == self) { |
| 1562 | selfTime = myTime; |
| 1563 | } |
| 1564 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | } |
| 1566 | t.mUpdateTime = batteryRealtime; |
| 1567 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1568 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | } |
| 1570 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1571 | @Override |
| 1572 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1573 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1574 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1575 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | return mTotalTime + (mNesting > 0 |
| 1577 | ? (curBatteryRealtime - mUpdateTime) |
| 1578 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1579 | : 0); |
| 1580 | } |
| 1581 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1582 | @Override |
| 1583 | protected int computeCurrentCountLocked() { |
| 1584 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | } |
| 1586 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1587 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1588 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1589 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1590 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1591 | if (mNesting > 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1592 | mUpdateTime = mTimeBase.getRealtime(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1593 | } |
| 1594 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1595 | return canDetach; |
| 1596 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1597 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1598 | @Override |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1599 | void detach() { |
| 1600 | super.detach(); |
| 1601 | if (mTimerPool != null) { |
| 1602 | mTimerPool.remove(this); |
| 1603 | } |
| 1604 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1605 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1606 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1608 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | mNesting = 0; |
| 1610 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1611 | |
| 1612 | /** |
| 1613 | * Set the mark so that we can query later for the total time the timer has |
| 1614 | * accumulated since this point. The timer can be running or not. |
| 1615 | * |
| 1616 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1617 | */ |
| 1618 | public void setMark(long elapsedRealtimeMs) { |
| 1619 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1620 | if (mNesting > 0) { |
| 1621 | // We are running. |
| 1622 | if (mTimerPool != null) { |
| 1623 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1624 | } else { |
| 1625 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1626 | mUpdateTime = batteryRealtime; |
| 1627 | } |
| 1628 | } |
| 1629 | mTimeBeforeMark = mTotalTime; |
| 1630 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1632 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1633 | public abstract class OverflowArrayMap<T> { |
| 1634 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1635 | |
| 1636 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1637 | T mCurOverflow; |
| 1638 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1639 | |
| 1640 | public OverflowArrayMap() { |
| 1641 | } |
| 1642 | |
| 1643 | public ArrayMap<String, T> getMap() { |
| 1644 | return mMap; |
| 1645 | } |
| 1646 | |
| 1647 | public void clear() { |
| 1648 | mMap.clear(); |
| 1649 | mCurOverflow = null; |
| 1650 | mActiveOverflow = null; |
| 1651 | } |
| 1652 | |
| 1653 | public void add(String name, T obj) { |
| 1654 | mMap.put(name, obj); |
| 1655 | if (OVERFLOW_NAME.equals(name)) { |
| 1656 | mCurOverflow = obj; |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | public void cleanup() { |
| 1661 | if (mActiveOverflow != null) { |
| 1662 | if (mActiveOverflow.size() == 0) { |
| 1663 | mActiveOverflow = null; |
| 1664 | } |
| 1665 | } |
| 1666 | if (mActiveOverflow == null) { |
| 1667 | // There is no currently active overflow, so we should no longer have |
| 1668 | // an overflow entry. |
| 1669 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1670 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1671 | + mMap.get(OVERFLOW_NAME)); |
| 1672 | mMap.remove(OVERFLOW_NAME); |
| 1673 | } |
| 1674 | mCurOverflow = null; |
| 1675 | } else { |
| 1676 | // There is currently active overflow, so we should still have an overflow entry. |
| 1677 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1678 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1679 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | public T startObject(String name) { |
| 1685 | T obj = mMap.get(name); |
| 1686 | if (obj != null) { |
| 1687 | return obj; |
| 1688 | } |
| 1689 | |
| 1690 | // No object exists for the given name, but do we currently have it |
| 1691 | // running as part of the overflow? |
| 1692 | if (mActiveOverflow != null) { |
| 1693 | MutableInt over = mActiveOverflow.get(name); |
| 1694 | if (over != null) { |
| 1695 | // We are already actively counting this name in the overflow object. |
| 1696 | obj = mCurOverflow; |
| 1697 | if (obj == null) { |
| 1698 | // Shouldn't be here, but we'll try to recover. |
| 1699 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1700 | obj = mCurOverflow = instantiateObject(); |
| 1701 | mMap.put(OVERFLOW_NAME, obj); |
| 1702 | } |
| 1703 | over.value++; |
| 1704 | return obj; |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | // No object exists for given name nor in the overflow; we need to make |
| 1709 | // a new one. |
| 1710 | final int N = mMap.size(); |
| 1711 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1712 | // Went over the limit on number of objects to track; this one goes |
| 1713 | // in to the overflow. |
| 1714 | obj = mCurOverflow; |
| 1715 | if (obj == null) { |
| 1716 | // Need to start overflow now... |
| 1717 | obj = mCurOverflow = instantiateObject(); |
| 1718 | mMap.put(OVERFLOW_NAME, obj); |
| 1719 | } |
| 1720 | if (mActiveOverflow == null) { |
| 1721 | mActiveOverflow = new ArrayMap<>(); |
| 1722 | } |
| 1723 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1724 | return obj; |
| 1725 | } |
| 1726 | |
| 1727 | // Normal case where we just need to make a new object. |
| 1728 | obj = instantiateObject(); |
| 1729 | mMap.put(name, obj); |
| 1730 | return obj; |
| 1731 | } |
| 1732 | |
| 1733 | public T stopObject(String name) { |
| 1734 | T obj = mMap.get(name); |
| 1735 | if (obj != null) { |
| 1736 | return obj; |
| 1737 | } |
| 1738 | |
| 1739 | // No object exists for the given name, but do we currently have it |
| 1740 | // running as part of the overflow? |
| 1741 | if (mActiveOverflow != null) { |
| 1742 | MutableInt over = mActiveOverflow.get(name); |
| 1743 | if (over != null) { |
| 1744 | // We are already actively counting this name in the overflow object. |
| 1745 | obj = mCurOverflow; |
| 1746 | if (obj != null) { |
| 1747 | over.value--; |
| 1748 | if (over.value <= 0) { |
| 1749 | mActiveOverflow.remove(name); |
| 1750 | } |
| 1751 | return obj; |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | // Huh, they are stopping an active operation but we can't find one! |
| 1757 | // That's not good. |
| 1758 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1759 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1760 | + " curoverflow=" + mCurOverflow); |
| 1761 | return null; |
| 1762 | } |
| 1763 | |
| 1764 | public abstract T instantiateObject(); |
| 1765 | } |
| 1766 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1767 | /* |
| 1768 | * Get the wakeup reason counter, and create a new one if one |
| 1769 | * doesn't already exist. |
| 1770 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1771 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 1772 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 1773 | if (timer == null) { |
| 1774 | timer = new SamplingTimer(mOnBatteryTimeBase, true); |
| 1775 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1776 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1777 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1780 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1781 | * 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] | 1782 | * doesn't already exist. |
| 1783 | */ |
| 1784 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1785 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1786 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1787 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1788 | mKernelWakelockStats.put(name, kwlt); |
| 1789 | } |
| 1790 | return kwlt; |
| 1791 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1792 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1793 | private int writeHistoryTag(HistoryTag tag) { |
| 1794 | Integer idxObj = mHistoryTagPool.get(tag); |
| 1795 | int idx; |
| 1796 | if (idxObj != null) { |
| 1797 | idx = idxObj; |
| 1798 | } else { |
| 1799 | idx = mNextHistoryTagIdx; |
| 1800 | HistoryTag key = new HistoryTag(); |
| 1801 | key.setTo(tag); |
| 1802 | tag.poolIdx = idx; |
| 1803 | mHistoryTagPool.put(key, idx); |
| 1804 | mNextHistoryTagIdx++; |
| 1805 | mNumHistoryTagChars += key.string.length() + 1; |
| 1806 | } |
| 1807 | return idx; |
| 1808 | } |
| 1809 | |
| 1810 | private void readHistoryTag(int index, HistoryTag tag) { |
| 1811 | tag.string = mReadHistoryStrings[index]; |
| 1812 | tag.uid = mReadHistoryUids[index]; |
| 1813 | tag.poolIdx = index; |
| 1814 | } |
| 1815 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1816 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1817 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 1818 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 1819 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 1820 | 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] | 1821 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1822 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1823 | // 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] | 1824 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 1825 | // Flag in delta int: a new full state2 int follows. |
| 1826 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1827 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1828 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1829 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1830 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1831 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1832 | static final int DELTA_STATE_MASK = 0xff000000; |
| 1833 | |
| 1834 | // These are the pieces of battery state that are packed in to the upper bits of |
| 1835 | // the state int that have been packed in to the first delta int. They must fit |
| 1836 | // in DELTA_STATE_MASK. |
| 1837 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 1838 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 1839 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 1840 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 1841 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 1842 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1843 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1844 | // We use the low bit of the battery state int to indicate that we have full details |
| 1845 | // from a battery level change. |
| 1846 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 1847 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1848 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1849 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1850 | dest.writeInt(DELTA_TIME_ABS); |
| 1851 | cur.writeToParcel(dest, 0); |
| 1852 | return; |
| 1853 | } |
| 1854 | |
| 1855 | final long deltaTime = cur.time - last.time; |
| 1856 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 1857 | final int lastStateInt = buildStateInt(last); |
| 1858 | |
| 1859 | int deltaTimeToken; |
| 1860 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 1861 | deltaTimeToken = DELTA_TIME_LONG; |
| 1862 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 1863 | deltaTimeToken = DELTA_TIME_INT; |
| 1864 | } else { |
| 1865 | deltaTimeToken = (int)deltaTime; |
| 1866 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1867 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1868 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 1869 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 1870 | final boolean computeStepDetails = includeStepDetails != 0 |
| 1871 | || mLastHistoryStepDetails == null; |
| 1872 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1873 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 1874 | if (batteryLevelIntChanged) { |
| 1875 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 1876 | } |
| 1877 | final int stateInt = buildStateInt(cur); |
| 1878 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 1879 | if (stateIntChanged) { |
| 1880 | firstToken |= DELTA_STATE_FLAG; |
| 1881 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1882 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 1883 | if (state2IntChanged) { |
| 1884 | firstToken |= DELTA_STATE2_FLAG; |
| 1885 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1886 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1887 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 1888 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1889 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 1890 | firstToken |= DELTA_EVENT_FLAG; |
| 1891 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1892 | dest.writeInt(firstToken); |
| 1893 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1894 | + " deltaTime=" + deltaTime); |
| 1895 | |
| 1896 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 1897 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 1898 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 1899 | dest.writeInt((int)deltaTime); |
| 1900 | } else { |
| 1901 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 1902 | dest.writeLong(deltaTime); |
| 1903 | } |
| 1904 | } |
| 1905 | if (batteryLevelIntChanged) { |
| 1906 | dest.writeInt(batteryLevelInt); |
| 1907 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 1908 | + Integer.toHexString(batteryLevelInt) |
| 1909 | + " batteryLevel=" + cur.batteryLevel |
| 1910 | + " batteryTemp=" + cur.batteryTemperature |
| 1911 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1912 | } |
| 1913 | if (stateIntChanged) { |
| 1914 | dest.writeInt(stateInt); |
| 1915 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 1916 | + Integer.toHexString(stateInt) |
| 1917 | + " batteryStatus=" + cur.batteryStatus |
| 1918 | + " batteryHealth=" + cur.batteryHealth |
| 1919 | + " batteryPlugType=" + cur.batteryPlugType |
| 1920 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1921 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1922 | if (state2IntChanged) { |
| 1923 | dest.writeInt(cur.states2); |
| 1924 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 1925 | + Integer.toHexString(cur.states2)); |
| 1926 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1927 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 1928 | int wakeLockIndex; |
| 1929 | int wakeReasonIndex; |
| 1930 | if (cur.wakelockTag != null) { |
| 1931 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 1932 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1933 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1934 | } else { |
| 1935 | wakeLockIndex = 0xffff; |
| 1936 | } |
| 1937 | if (cur.wakeReasonTag != null) { |
| 1938 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 1939 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1940 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1941 | } else { |
| 1942 | wakeReasonIndex = 0xffff; |
| 1943 | } |
| 1944 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1945 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1946 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1947 | int index = writeHistoryTag(cur.eventTag); |
| 1948 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1949 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1950 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 1951 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 1952 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1953 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1954 | if (computeStepDetails) { |
| 1955 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 1956 | if (includeStepDetails != 0) { |
| 1957 | mCurHistoryStepDetails.writeToParcel(dest); |
| 1958 | } |
| 1959 | cur.stepDetails = mCurHistoryStepDetails; |
| 1960 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 1961 | } else { |
| 1962 | cur.stepDetails = null; |
| 1963 | } |
| 1964 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 1965 | mLastHistoryStepDetails = null; |
| 1966 | } |
| 1967 | mLastHistoryStepLevel = cur.batteryLevel; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | private int buildBatteryLevelInt(HistoryItem h) { |
| 1971 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1972 | | ((((int)h.batteryTemperature)<<14)&0x01ff8000) |
| 1973 | | ((((int)h.batteryVoltage)<<1)&0x00007fff); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1977 | int plugType = 0; |
| 1978 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 1979 | plugType = 1; |
| 1980 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 1981 | plugType = 2; |
| 1982 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 1983 | plugType = 3; |
| 1984 | } |
| 1985 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 1986 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 1987 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1988 | | (h.states&(~DELTA_STATE_MASK)); |
| 1989 | } |
| 1990 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1991 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 1992 | final HistoryStepDetails last) { |
| 1993 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 1994 | |
| 1995 | // Perform a CPU update right after we do this collection, so we have started |
| 1996 | // collecting good data for the next step. |
| 1997 | requestImmediateCpuUpdate(); |
| 1998 | |
| 1999 | if (last == null) { |
| 2000 | // We are not generating a delta, so all we need to do is reset the stats |
| 2001 | // we will later be doing a delta from. |
| 2002 | final int NU = mUidStats.size(); |
| 2003 | for (int i=0; i<NU; i++) { |
| 2004 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2005 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2006 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2007 | } |
| 2008 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2009 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2010 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2011 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2012 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2013 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2014 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2015 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2016 | tmp.clear(); |
| 2017 | return; |
| 2018 | } |
| 2019 | if (DEBUG) { |
| 2020 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2021 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2022 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2023 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2024 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2025 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2026 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2027 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2028 | } |
| 2029 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2030 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2031 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2032 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2033 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2034 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2035 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2036 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2037 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2038 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2039 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2040 | final int NU = mUidStats.size(); |
| 2041 | for (int i=0; i<NU; i++) { |
| 2042 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2043 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2044 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2045 | final int totalTime = totalUTime + totalSTime; |
| 2046 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2047 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2048 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2049 | continue; |
| 2050 | } |
| 2051 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2052 | out.appCpuUid3 = uid.mUid; |
| 2053 | out.appCpuUTime3 = totalUTime; |
| 2054 | out.appCpuSTime3 = totalSTime; |
| 2055 | } else { |
| 2056 | out.appCpuUid3 = out.appCpuUid2; |
| 2057 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2058 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2059 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2060 | out.appCpuUid2 = uid.mUid; |
| 2061 | out.appCpuUTime2 = totalUTime; |
| 2062 | out.appCpuSTime2 = totalSTime; |
| 2063 | } else { |
| 2064 | out.appCpuUid2 = out.appCpuUid1; |
| 2065 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2066 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2067 | out.appCpuUid1 = uid.mUid; |
| 2068 | out.appCpuUTime1 = totalUTime; |
| 2069 | out.appCpuSTime1 = totalSTime; |
| 2070 | } |
| 2071 | } |
| 2072 | } |
| 2073 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2074 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2075 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2076 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2077 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2078 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2079 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2080 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2081 | } |
| 2082 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2083 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2084 | int firstToken = src.readInt(); |
| 2085 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2086 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2087 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2088 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2089 | + " deltaTimeToken=" + deltaTimeToken); |
| 2090 | |
| 2091 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2092 | cur.time += deltaTimeToken; |
| 2093 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2094 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2095 | cur.numReadInts += 2; |
| 2096 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2097 | cur.readFromParcel(src); |
| 2098 | return; |
| 2099 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2100 | int delta = src.readInt(); |
| 2101 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2102 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2103 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2104 | } else { |
| 2105 | long delta = src.readLong(); |
| 2106 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2107 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2108 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2109 | } |
| 2110 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2111 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2112 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2113 | batteryLevelInt = src.readInt(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2114 | cur.batteryLevel = (byte)((batteryLevelInt>>25)&0x7f); |
| 2115 | cur.batteryTemperature = (short)((batteryLevelInt<<7)>>21); |
| 2116 | cur.batteryVoltage = (char)(batteryLevelInt&0x3fff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2117 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2118 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2119 | + Integer.toHexString(batteryLevelInt) |
| 2120 | + " batteryLevel=" + cur.batteryLevel |
| 2121 | + " batteryTemp=" + cur.batteryTemperature |
| 2122 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2123 | } else { |
| 2124 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2128 | int stateInt = src.readInt(); |
| 2129 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2130 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2131 | & STATE_BATTERY_STATUS_MASK); |
| 2132 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2133 | & STATE_BATTERY_HEALTH_MASK); |
| 2134 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2135 | & STATE_BATTERY_PLUG_MASK); |
| 2136 | switch (cur.batteryPlugType) { |
| 2137 | case 1: |
| 2138 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2139 | break; |
| 2140 | case 2: |
| 2141 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2142 | break; |
| 2143 | case 3: |
| 2144 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2145 | break; |
| 2146 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2147 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2148 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2149 | + Integer.toHexString(stateInt) |
| 2150 | + " batteryStatus=" + cur.batteryStatus |
| 2151 | + " batteryHealth=" + cur.batteryHealth |
| 2152 | + " batteryPlugType=" + cur.batteryPlugType |
| 2153 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2154 | } else { |
| 2155 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 2156 | } |
| 2157 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2158 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2159 | cur.states2 = src.readInt(); |
| 2160 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2161 | + Integer.toHexString(cur.states2)); |
| 2162 | } |
| 2163 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2164 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2165 | int indexes = src.readInt(); |
| 2166 | int wakeLockIndex = indexes&0xffff; |
| 2167 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2168 | if (wakeLockIndex != 0xffff) { |
| 2169 | cur.wakelockTag = cur.localWakelockTag; |
| 2170 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2171 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2172 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2173 | } else { |
| 2174 | cur.wakelockTag = null; |
| 2175 | } |
| 2176 | if (wakeReasonIndex != 0xffff) { |
| 2177 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2178 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2179 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2180 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2181 | } else { |
| 2182 | cur.wakeReasonTag = null; |
| 2183 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2184 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2185 | } else { |
| 2186 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2187 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2188 | } |
| 2189 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2190 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2191 | cur.eventTag = cur.localEventTag; |
| 2192 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2193 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2194 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2195 | readHistoryTag(index, cur.eventTag); |
| 2196 | cur.numReadInts += 1; |
| 2197 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2198 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2199 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2200 | } else { |
| 2201 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2202 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2203 | |
| 2204 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2205 | cur.stepDetails = mReadHistoryStepDetails; |
| 2206 | cur.stepDetails.readFromParcel(src); |
| 2207 | } else { |
| 2208 | cur.stepDetails = null; |
| 2209 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2210 | } |
| 2211 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2212 | @Override |
| 2213 | public void commitCurrentHistoryBatchLocked() { |
| 2214 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2215 | } |
| 2216 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2217 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2218 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2219 | return; |
| 2220 | } |
| 2221 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2222 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2223 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2224 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2225 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2226 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2227 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2228 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2229 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2230 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2231 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2232 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2233 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2234 | && (diffStates2&lastDiffStates2) == 0 |
| 2235 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2236 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2237 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2238 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2239 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2240 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2241 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2242 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2243 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2244 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2245 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2246 | // 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] | 2247 | // 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] | 2248 | // as long as no bit has changed both between now and the last entry, as |
| 2249 | // well as the last entry and the one before it (so we capture any toggles). |
| 2250 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2251 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2252 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2253 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2254 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2255 | // If the last written history had a wakelock tag, we need to retain it. |
| 2256 | // Note that the condition above made sure that we aren't in a case where |
| 2257 | // both it and the current history item have a wakelock tag. |
| 2258 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2259 | cur.wakelockTag = cur.localWakelockTag; |
| 2260 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2261 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2262 | // If the last written history had a wake reason tag, we need to retain it. |
| 2263 | // Note that the condition above made sure that we aren't in a case where |
| 2264 | // both it and the current history item have a wakelock tag. |
| 2265 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2266 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2267 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2268 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2269 | // If the last written history had an event, we need to retain it. |
| 2270 | // Note that the condition above made sure that we aren't in a case where |
| 2271 | // both it and the current history item have an event. |
| 2272 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2273 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2274 | cur.eventTag = cur.localEventTag; |
| 2275 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2276 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2277 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2281 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2282 | if (!mHistoryOverflow) { |
| 2283 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2284 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2285 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2286 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2289 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2290 | boolean writeAnyway = false; |
| 2291 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2292 | & mActiveHistoryStates; |
| 2293 | if (mHistoryLastWritten.states != curStates) { |
| 2294 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2295 | // forced to 0. |
| 2296 | int old = mActiveHistoryStates; |
| 2297 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2298 | writeAnyway |= old != mActiveHistoryStates; |
| 2299 | } |
| 2300 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2301 | & mActiveHistoryStates2; |
| 2302 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2303 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2304 | // forced to 0. |
| 2305 | int old = mActiveHistoryStates2; |
| 2306 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2307 | writeAnyway |= old != mActiveHistoryStates2; |
| 2308 | } |
| 2309 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2310 | // Once we've reached the maximum number of items, we only |
| 2311 | // record changes to the battery level and the most interesting states. |
| 2312 | // Once we've reached the maximum maximum number of items, we only |
| 2313 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2314 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2315 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2316 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2317 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2318 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2319 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2320 | return; |
| 2321 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2322 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2323 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2324 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2327 | if (dataSize == 0) { |
| 2328 | // The history is currently empty; we need it to start with a time stamp. |
| 2329 | cur.currentTime = System.currentTimeMillis(); |
| 2330 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2331 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2332 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2335 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2336 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2337 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2338 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2339 | } |
| 2340 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2341 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2342 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2343 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2344 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2345 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2346 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2347 | cur.wakelockTag = null; |
| 2348 | cur.wakeReasonTag = null; |
| 2349 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2350 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2351 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2352 | + " now " + mHistoryBuffer.dataPosition() |
| 2353 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2356 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2357 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2358 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2359 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2360 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2361 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2362 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2363 | if (diffUptime < (diffElapsed-20)) { |
| 2364 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2365 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2366 | mHistoryAddTmp.wakelockTag = null; |
| 2367 | mHistoryAddTmp.wakeReasonTag = null; |
| 2368 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2369 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2370 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2371 | } |
| 2372 | } |
| 2373 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2374 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2375 | mTrackRunningHistoryUptime = uptimeMs; |
| 2376 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2377 | } |
| 2378 | |
| 2379 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2380 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2381 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2382 | if (!USE_OLD_HISTORY) { |
| 2383 | return; |
| 2384 | } |
| 2385 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2386 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2387 | return; |
| 2388 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2389 | |
| 2390 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2391 | // and no states have since the last recorded entry changed and |
| 2392 | // are now resetting back to their original value, then just collapse |
| 2393 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2394 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2395 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2396 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2397 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2398 | // If the current is the same as the one before, then we no |
| 2399 | // longer need the entry. |
| 2400 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2401 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2402 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2403 | mHistoryLastEnd.next = null; |
| 2404 | mHistoryEnd.next = mHistoryCache; |
| 2405 | mHistoryCache = mHistoryEnd; |
| 2406 | mHistoryEnd = mHistoryLastEnd; |
| 2407 | mHistoryLastEnd = null; |
| 2408 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2409 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2410 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2411 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2412 | } |
| 2413 | return; |
| 2414 | } |
| 2415 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2416 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2417 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2418 | |
| 2419 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2420 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2421 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2424 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2425 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2426 | // record changes to the battery level and the most interesting states. |
| 2427 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2428 | // record changes to the battery level. |
| 2429 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2430 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2431 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2432 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2433 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2434 | return; |
| 2435 | } |
| 2436 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2437 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2438 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2439 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2440 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2441 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2442 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2443 | mHistoryCur.eventCode = code; |
| 2444 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2445 | mHistoryCur.eventTag.string = name; |
| 2446 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2447 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2448 | } |
| 2449 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2450 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2451 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2452 | if (rec != null) { |
| 2453 | mHistoryCache = rec.next; |
| 2454 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2455 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2456 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2457 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2458 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2459 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2460 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2461 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2462 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2463 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2464 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2465 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2466 | if (mHistoryEnd != null) { |
| 2467 | mHistoryEnd.next = rec; |
| 2468 | mHistoryEnd = rec; |
| 2469 | } else { |
| 2470 | mHistory = mHistoryEnd = rec; |
| 2471 | } |
| 2472 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2473 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2474 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2475 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2476 | if (USE_OLD_HISTORY) { |
| 2477 | if (mHistory != null) { |
| 2478 | mHistoryEnd.next = mHistoryCache; |
| 2479 | mHistoryCache = mHistory; |
| 2480 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2481 | } |
| 2482 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2483 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2484 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2485 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2486 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2487 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2488 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2489 | |
| 2490 | mHistoryBuffer.setDataSize(0); |
| 2491 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2492 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2493 | mHistoryLastLastWritten.clear(); |
| 2494 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2495 | mHistoryTagPool.clear(); |
| 2496 | mNextHistoryTagIdx = 0; |
| 2497 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2498 | mHistoryBufferLastPos = -1; |
| 2499 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2500 | mActiveHistoryStates = 0xffffffff; |
| 2501 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2502 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2503 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2504 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2505 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2506 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2507 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2508 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2509 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2510 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2511 | if (DEBUG_ENERGY_CPU) { |
| 2512 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 2513 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2514 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2515 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2516 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | } |
| 2518 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2519 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2520 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2521 | mIsolatedUids.put(isolatedUid, appUid); |
| 2522 | } |
| 2523 | |
| 2524 | public void removeIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2525 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2526 | if (curUid == appUid) { |
| 2527 | mIsolatedUids.delete(isolatedUid); |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | public int mapUid(int uid) { |
| 2532 | int isolated = mIsolatedUids.get(uid, -1); |
| 2533 | return isolated > 0 ? isolated : uid; |
| 2534 | } |
| 2535 | |
| 2536 | public void noteEventLocked(int code, String name, int uid) { |
| 2537 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2538 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2539 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2540 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2541 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2542 | final long uptime = SystemClock.uptimeMillis(); |
| 2543 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2544 | } |
| 2545 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2546 | public void noteCurrentTimeChangedLocked() { |
| 2547 | final long currentTime = System.currentTimeMillis(); |
| 2548 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2549 | final long uptime = SystemClock.uptimeMillis(); |
| 2550 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
| 2551 | if (isStartClockTimeValid()) { |
| 2552 | mStartClockTime = currentTime; |
| 2553 | } |
| 2554 | } |
| 2555 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2556 | public void noteProcessStartLocked(String name, int uid) { |
| 2557 | uid = mapUid(uid); |
| 2558 | if (isOnBattery()) { |
| 2559 | Uid u = getUidStatsLocked(uid); |
| 2560 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2561 | } |
| 2562 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2563 | return; |
| 2564 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2565 | if (!mRecordAllHistory) { |
| 2566 | return; |
| 2567 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2568 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2569 | final long uptime = SystemClock.uptimeMillis(); |
| 2570 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2571 | } |
| 2572 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2573 | public void noteProcessCrashLocked(String name, int uid) { |
| 2574 | uid = mapUid(uid); |
| 2575 | if (isOnBattery()) { |
| 2576 | Uid u = getUidStatsLocked(uid); |
| 2577 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | public void noteProcessAnrLocked(String name, int uid) { |
| 2582 | uid = mapUid(uid); |
| 2583 | if (isOnBattery()) { |
| 2584 | Uid u = getUidStatsLocked(uid); |
| 2585 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2586 | } |
| 2587 | } |
| 2588 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2589 | public void noteProcessStateLocked(String name, int uid, int state) { |
| 2590 | uid = mapUid(uid); |
| 2591 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2592 | getUidStatsLocked(uid).updateProcessStateLocked(name, state, elapsedRealtime); |
| 2593 | } |
| 2594 | |
| 2595 | public void noteProcessFinishLocked(String name, int uid) { |
| 2596 | uid = mapUid(uid); |
| 2597 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2598 | return; |
| 2599 | } |
| 2600 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2601 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2602 | getUidStatsLocked(uid).updateProcessStateLocked(name, Uid.PROCESS_STATE_NONE, |
| 2603 | elapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2604 | if (!mRecordAllHistory) { |
| 2605 | return; |
| 2606 | } |
| 2607 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2610 | public void noteSyncStartLocked(String name, int uid) { |
| 2611 | uid = mapUid(uid); |
| 2612 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2613 | final long uptime = SystemClock.uptimeMillis(); |
| 2614 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2615 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2616 | return; |
| 2617 | } |
| 2618 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2619 | } |
| 2620 | |
| 2621 | public void noteSyncFinishLocked(String name, int uid) { |
| 2622 | uid = mapUid(uid); |
| 2623 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2624 | final long uptime = SystemClock.uptimeMillis(); |
| 2625 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2626 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2627 | return; |
| 2628 | } |
| 2629 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2630 | } |
| 2631 | |
| 2632 | public void noteJobStartLocked(String name, int uid) { |
| 2633 | uid = mapUid(uid); |
| 2634 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2635 | final long uptime = SystemClock.uptimeMillis(); |
| 2636 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2637 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2638 | return; |
| 2639 | } |
| 2640 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2641 | } |
| 2642 | |
| 2643 | public void noteJobFinishLocked(String name, int uid) { |
| 2644 | uid = mapUid(uid); |
| 2645 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2646 | final long uptime = SystemClock.uptimeMillis(); |
| 2647 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2648 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2649 | return; |
| 2650 | } |
| 2651 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2652 | } |
| 2653 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2654 | public void noteAlarmStartLocked(String name, int uid) { |
| 2655 | if (!mRecordAllHistory) { |
| 2656 | return; |
| 2657 | } |
| 2658 | uid = mapUid(uid); |
| 2659 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2660 | final long uptime = SystemClock.uptimeMillis(); |
| 2661 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 2662 | return; |
| 2663 | } |
| 2664 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 2665 | } |
| 2666 | |
| 2667 | public void noteAlarmFinishLocked(String name, int uid) { |
| 2668 | if (!mRecordAllHistory) { |
| 2669 | return; |
| 2670 | } |
| 2671 | uid = mapUid(uid); |
| 2672 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2673 | final long uptime = SystemClock.uptimeMillis(); |
| 2674 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 2675 | return; |
| 2676 | } |
| 2677 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 2678 | } |
| 2679 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2680 | private void requestWakelockCpuUpdate() { |
| 2681 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2682 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2683 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2684 | } |
| 2685 | } |
| 2686 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2687 | private void requestImmediateCpuUpdate() { |
| 2688 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2689 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 2690 | } |
| 2691 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2692 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 2693 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2694 | if (!enabled) { |
| 2695 | // Clear out any existing state. |
| 2696 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2697 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2698 | // Record the currently running processes as stopping, now that we are no |
| 2699 | // longer tracking them. |
| 2700 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2701 | HistoryItem.EVENT_PROC); |
| 2702 | if (active != null) { |
| 2703 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2704 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2705 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2706 | SparseIntArray uids = ent.getValue(); |
| 2707 | for (int j=0; j<uids.size(); j++) { |
| 2708 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2709 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | } else { |
| 2714 | // Record the currently running processes as starting, now that we are tracking them. |
| 2715 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2716 | HistoryItem.EVENT_PROC); |
| 2717 | if (active != null) { |
| 2718 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2719 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2720 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2721 | SparseIntArray uids = ent.getValue(); |
| 2722 | for (int j=0; j<uids.size(); j++) { |
| 2723 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2724 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 2725 | } |
| 2726 | } |
| 2727 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2728 | } |
| 2729 | } |
| 2730 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2731 | public void setNoAutoReset(boolean enabled) { |
| 2732 | mNoAutoReset = enabled; |
| 2733 | } |
| 2734 | |
| 2735 | private String mInitialAcquireWakeName; |
| 2736 | private int mInitialAcquireWakeUid = -1; |
| 2737 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2738 | 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] | 2739 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2740 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2741 | if (type == WAKE_TYPE_PARTIAL) { |
| 2742 | // Only care about partial wake locks, since full wake locks |
| 2743 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2744 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2745 | if (historyName == null) { |
| 2746 | historyName = name; |
| 2747 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2748 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2749 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 2750 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2751 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2752 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2753 | } |
| 2754 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2755 | if (mWakeLockNesting == 0) { |
| 2756 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2757 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 2758 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2759 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2760 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2761 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2762 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2763 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2764 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 2765 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2766 | if (mHistoryLastWritten.wakelockTag != null) { |
| 2767 | // We'll try to update the last tag. |
| 2768 | mHistoryLastWritten.wakelockTag = null; |
| 2769 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2770 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2771 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2772 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2773 | } |
| 2774 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2775 | } |
| 2776 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2777 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2778 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2779 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2780 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 2781 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 2782 | if (DEBUG_ENERGY_CPU) { |
| 2783 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 2784 | } |
| 2785 | requestWakelockCpuUpdate(); |
| 2786 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2787 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2791 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 2792 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2793 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2794 | if (type == WAKE_TYPE_PARTIAL) { |
| 2795 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2796 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2797 | if (historyName == null) { |
| 2798 | historyName = name; |
| 2799 | } |
| 2800 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 2801 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2802 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2803 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2804 | } |
| 2805 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2806 | if (mWakeLockNesting == 0) { |
| 2807 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2808 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 2809 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2810 | mInitialAcquireWakeName = null; |
| 2811 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2812 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2813 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2814 | } |
| 2815 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2816 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2817 | if (DEBUG_ENERGY_CPU) { |
| 2818 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 2819 | } |
| 2820 | requestWakelockCpuUpdate(); |
| 2821 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2822 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2823 | } |
| 2824 | } |
| 2825 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2826 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2827 | String historyName, int type, boolean unimportantForLogging) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2828 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2829 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2830 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2831 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2832 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2833 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2834 | } |
| 2835 | } |
| 2836 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2837 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 2838 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2839 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
| 2840 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2841 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2842 | // For correct semantics, we start the need worksources first, so that we won't |
| 2843 | // make inappropriate history items as if all wake locks went away and new ones |
| 2844 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2845 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2846 | for (int i=0; i<NN; i++) { |
| 2847 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2848 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2849 | } |
| 2850 | final int NO = ws.size(); |
| 2851 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2852 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2853 | } |
| 2854 | } |
| 2855 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2856 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2857 | String historyName, int type) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2858 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2859 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2860 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2861 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2862 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2863 | } |
| 2864 | } |
| 2865 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2866 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 2867 | if (mLastWakeupReason != null) { |
| 2868 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2869 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
| 2870 | timer.addCurrentReportedCount(1); |
| 2871 | timer.addCurrentReportedTotalTime(deltaUptime * 1000); // time is in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2872 | mLastWakeupReason = null; |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | public void noteWakeupReasonLocked(String reason) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2877 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2878 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2879 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2880 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2881 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2882 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 2883 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2884 | mHistoryCur.wakeReasonTag.uid = 0; |
| 2885 | mLastWakeupReason = reason; |
| 2886 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2887 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2888 | } |
| 2889 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2890 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2891 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2892 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2895 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 2896 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 2897 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2898 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 2899 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 2900 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 2901 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 2902 | mCurStepCpuUserTime += totalUTime; |
| 2903 | mCurStepCpuSystemTime += totalSTime; |
| 2904 | mCurStepStatUserTime += statUserTime; |
| 2905 | mCurStepStatSystemTime += statSystemTime; |
| 2906 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 2907 | mCurStepStatIrqTime += statIrqTime; |
| 2908 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 2909 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2912 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2913 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2914 | Uid u = mUidStats.get(uid); |
| 2915 | if (u != null) { |
| 2916 | u.mPids.remove(pid); |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2921 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2922 | Uid u = mUidStats.get(uid); |
| 2923 | if (u != null) { |
| 2924 | Uid.Pid p = u.mPids.get(pid); |
| 2925 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2926 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | return 0; |
| 2930 | } |
| 2931 | |
| 2932 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2933 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2934 | Uid u = mUidStats.get(uid); |
| 2935 | if (u != null) { |
| 2936 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 2937 | } |
| 2938 | } |
| 2939 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2940 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2941 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2942 | Uid u = mUidStats.get(uid); |
| 2943 | if (u != null) { |
| 2944 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 2945 | } |
| 2946 | } |
| 2947 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2948 | int mSensorNesting; |
| 2949 | |
| 2950 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2951 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2952 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2953 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2954 | if (mSensorNesting == 0) { |
| 2955 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2956 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 2957 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2958 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2959 | } |
| 2960 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2961 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2965 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2966 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2967 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2968 | mSensorNesting--; |
| 2969 | if (mSensorNesting == 0) { |
| 2970 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2971 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 2972 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2973 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2974 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2975 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2978 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2979 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2980 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2981 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2982 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2983 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2984 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2985 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2986 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 2987 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2988 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2989 | } |
| 2990 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2991 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2993 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2994 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2995 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2996 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2997 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2998 | mGpsNesting--; |
| 2999 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3000 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3001 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3002 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3003 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3004 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3005 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3007 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3008 | public void noteScreenStateLocked(int state) { |
| 3009 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3010 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3011 | final int oldState = mScreenState; |
| 3012 | mScreenState = state; |
| 3013 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3014 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3015 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3016 | if (state != Display.STATE_UNKNOWN) { |
| 3017 | int stepState = state-1; |
| 3018 | if (stepState < 4) { |
| 3019 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3020 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3021 | } else { |
| 3022 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3023 | } |
| 3024 | } |
| 3025 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3026 | if (state == Display.STATE_ON) { |
| 3027 | // Screen turning on. |
| 3028 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3029 | final long uptime = SystemClock.uptimeMillis(); |
| 3030 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3031 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3032 | + Integer.toHexString(mHistoryCur.states)); |
| 3033 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3034 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3035 | if (mScreenBrightnessBin >= 0) { |
| 3036 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3037 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3038 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3039 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
| 3040 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3041 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3042 | // Fake a wake lock, so we consider the device waked as long |
| 3043 | // as the screen is on. |
| 3044 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3045 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3046 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3047 | // Update discharge amounts. |
| 3048 | if (mOnBatteryInternal) { |
| 3049 | updateDischargeScreenLevelsLocked(false, true); |
| 3050 | } |
| 3051 | } else if (oldState == Display.STATE_ON) { |
| 3052 | // Screen turning off or dozing. |
| 3053 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3054 | final long uptime = SystemClock.uptimeMillis(); |
| 3055 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3056 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3057 | + Integer.toHexString(mHistoryCur.states)); |
| 3058 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3059 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3060 | if (mScreenBrightnessBin >= 0) { |
| 3061 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3062 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3063 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3064 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3065 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3066 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3067 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
| 3068 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3069 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3070 | // Update discharge amounts. |
| 3071 | if (mOnBatteryInternal) { |
| 3072 | updateDischargeScreenLevelsLocked(true, false); |
| 3073 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3074 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3075 | } |
| 3076 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3077 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3078 | public void noteScreenBrightnessLocked(int brightness) { |
| 3079 | // Bin the brightness. |
| 3080 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3081 | if (bin < 0) bin = 0; |
| 3082 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3083 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3084 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3085 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3086 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3087 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3088 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3089 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3090 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3091 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3092 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3093 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3094 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3095 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3096 | } |
| 3097 | mScreenBrightnessBin = bin; |
| 3098 | } |
| 3099 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3100 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3101 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3102 | if (mOnBatteryInternal) { |
| 3103 | uid = mapUid(uid); |
| 3104 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3107 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3108 | public void noteInteractiveLocked(boolean interactive) { |
| 3109 | if (mInteractive != interactive) { |
| 3110 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3111 | mInteractive = interactive; |
| 3112 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3113 | if (interactive) { |
| 3114 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3115 | } else { |
| 3116 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3117 | } |
| 3118 | } |
| 3119 | } |
| 3120 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3121 | public void noteConnectivityChangedLocked(int type, String extra) { |
| 3122 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3123 | final long uptime = SystemClock.uptimeMillis(); |
| 3124 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3125 | extra, type); |
| 3126 | mNumConnectivityChange++; |
| 3127 | } |
| 3128 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3129 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
| 3130 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3131 | final long uptime = SystemClock.uptimeMillis(); |
| 3132 | if (mMobileRadioPowerState != powerState) { |
| 3133 | long realElapsedRealtimeMs; |
| 3134 | final boolean active = |
| 3135 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3136 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3137 | if (active) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3138 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3139 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3140 | } else { |
| 3141 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3142 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3143 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3144 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3145 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3146 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3147 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3148 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3149 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3150 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3151 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3152 | } |
| 3153 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3154 | + Integer.toHexString(mHistoryCur.states)); |
| 3155 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3156 | mMobileRadioPowerState = powerState; |
| 3157 | if (active) { |
| 3158 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3159 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3160 | } else { |
| 3161 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3162 | updateMobileRadioStateLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3163 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3164 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3168 | public void notePowerSaveMode(boolean enabled) { |
| 3169 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3170 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3171 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3172 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3173 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3174 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3175 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3176 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3177 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3178 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3179 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3180 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3181 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3182 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3183 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3184 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3185 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3186 | } |
| 3187 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3188 | } |
| 3189 | } |
| 3190 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3191 | public void noteDeviceIdleModeLocked(boolean enabled, boolean fromActive, boolean fromMotion) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3192 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3193 | final long uptime = SystemClock.uptimeMillis(); |
| 3194 | boolean nowIdling = enabled; |
| 3195 | if (mDeviceIdling && !enabled && !fromActive && !fromMotion) { |
| 3196 | // We don't go out of general idling mode until explicitly taken out of |
| 3197 | // device idle through going active or significant motion. |
| 3198 | nowIdling = true; |
| 3199 | } |
| 3200 | if (mDeviceIdling != nowIdling) { |
| 3201 | mDeviceIdling = nowIdling; |
| 3202 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3203 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3204 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
| 3205 | if (enabled) { |
| 3206 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3207 | } else { |
| 3208 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3209 | } |
| 3210 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3211 | if (mDeviceIdleModeEnabled != enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3212 | mDeviceIdleModeEnabled = enabled; |
| 3213 | if (fromMotion) { |
| 3214 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SIGNIFICANT_MOTION, |
| 3215 | "", 0); |
| 3216 | } |
| 3217 | if (fromActive) { |
| 3218 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3219 | "", 0); |
| 3220 | } |
| 3221 | if (enabled) { |
| 3222 | mHistoryCur.states2 |= HistoryItem.STATE2_DEVICE_IDLE_FLAG; |
| 3223 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode enabled to: " |
| 3224 | + Integer.toHexString(mHistoryCur.states2)); |
| 3225 | mDeviceIdleModeEnabledTimer.startRunningLocked(elapsedRealtime); |
| 3226 | } else { |
| 3227 | mHistoryCur.states2 &= ~HistoryItem.STATE2_DEVICE_IDLE_FLAG; |
| 3228 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode disabled to: " |
| 3229 | + Integer.toHexString(mHistoryCur.states2)); |
| 3230 | mDeviceIdleModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
| 3231 | } |
| 3232 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
| 3237 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3238 | final long uptime = SystemClock.uptimeMillis(); |
| 3239 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3240 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3241 | PackageChange pc = new PackageChange(); |
| 3242 | pc.mPackageName = pkgName; |
| 3243 | pc.mUpdate = true; |
| 3244 | pc.mVersionCode = versionCode; |
| 3245 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | public void notePackageUninstalledLocked(String pkgName) { |
| 3249 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3250 | final long uptime = SystemClock.uptimeMillis(); |
| 3251 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3252 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3253 | PackageChange pc = new PackageChange(); |
| 3254 | pc.mPackageName = pkgName; |
| 3255 | pc.mUpdate = true; |
| 3256 | addPackageChange(pc); |
| 3257 | } |
| 3258 | |
| 3259 | private void addPackageChange(PackageChange pc) { |
| 3260 | if (mDailyPackageChanges == null) { |
| 3261 | mDailyPackageChanges = new ArrayList<>(); |
| 3262 | } |
| 3263 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3266 | public void notePhoneOnLocked() { |
| 3267 | if (!mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3268 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3269 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3270 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3271 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3272 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3273 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3275 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | } |
| 3277 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | public void notePhoneOffLocked() { |
| 3280 | if (mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3281 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3282 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3283 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3284 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3285 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3286 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3288 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3289 | } |
| 3290 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3291 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3292 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3293 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3294 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3295 | if (i == except) { |
| 3296 | continue; |
| 3297 | } |
| 3298 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3299 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3304 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3305 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3306 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3307 | // to infer that we are scanning from other data. |
| 3308 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3309 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3310 | state = ServiceState.STATE_IN_SERVICE; |
| 3311 | } |
| 3312 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3313 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3314 | return state; |
| 3315 | } |
| 3316 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3317 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3318 | boolean scanning = false; |
| 3319 | boolean newHistory = false; |
| 3320 | |
| 3321 | mPhoneServiceStateRaw = state; |
| 3322 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3323 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3324 | |
| 3325 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3326 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3327 | |
| 3328 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3329 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3330 | // to infer that we are scanning from other data. |
| 3331 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3332 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3333 | state = ServiceState.STATE_IN_SERVICE; |
| 3334 | } |
| 3335 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3336 | |
| 3337 | // If the phone is powered off, stop all timers. |
| 3338 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3339 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3340 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3341 | // If we are in service, make sure the correct signal string timer is running. |
| 3342 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3343 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3344 | |
| 3345 | // If we're out of service, we are in the lowest signal strength |
| 3346 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3347 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3348 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3349 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3350 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3351 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3352 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3353 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3354 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3355 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3356 | } |
| 3357 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3358 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3359 | if (!scanning) { |
| 3360 | // If we are no longer scanning, then stop the scanning timer. |
| 3361 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3362 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3363 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3364 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3365 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3366 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3367 | } |
| 3368 | } |
| 3369 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3370 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3371 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3372 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3373 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3374 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3375 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3376 | mPhoneServiceState = state; |
| 3377 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3378 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3379 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3380 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3381 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3382 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3383 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3384 | if (strengthBin >= 0) { |
| 3385 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3386 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3387 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3388 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3389 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3390 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3391 | + Integer.toHexString(mHistoryCur.states)); |
| 3392 | newHistory = true; |
| 3393 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3394 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3395 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3396 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3400 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | /** |
| 3405 | * Telephony stack updates the phone state. |
| 3406 | * @param state phone state from ServiceState.getState() |
| 3407 | */ |
| 3408 | public void notePhoneStateLocked(int state, int simState) { |
| 3409 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3412 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3413 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3414 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3415 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3416 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3417 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3418 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3419 | int bin = DATA_CONNECTION_NONE; |
| 3420 | if (hasData) { |
| 3421 | switch (dataType) { |
| 3422 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3423 | bin = DATA_CONNECTION_EDGE; |
| 3424 | break; |
| 3425 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3426 | bin = DATA_CONNECTION_GPRS; |
| 3427 | break; |
| 3428 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3429 | bin = DATA_CONNECTION_UMTS; |
| 3430 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3431 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3432 | bin = DATA_CONNECTION_CDMA; |
| 3433 | break; |
| 3434 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3435 | bin = DATA_CONNECTION_EVDO_0; |
| 3436 | break; |
| 3437 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3438 | bin = DATA_CONNECTION_EVDO_A; |
| 3439 | break; |
| 3440 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3441 | bin = DATA_CONNECTION_1xRTT; |
| 3442 | break; |
| 3443 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3444 | bin = DATA_CONNECTION_HSDPA; |
| 3445 | break; |
| 3446 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3447 | bin = DATA_CONNECTION_HSUPA; |
| 3448 | break; |
| 3449 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3450 | bin = DATA_CONNECTION_HSPA; |
| 3451 | break; |
| 3452 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3453 | bin = DATA_CONNECTION_IDEN; |
| 3454 | break; |
| 3455 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3456 | bin = DATA_CONNECTION_EVDO_B; |
| 3457 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3458 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3459 | bin = DATA_CONNECTION_LTE; |
| 3460 | break; |
| 3461 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3462 | bin = DATA_CONNECTION_EHRPD; |
| 3463 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3464 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3465 | bin = DATA_CONNECTION_HSPAP; |
| 3466 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3467 | default: |
| 3468 | bin = DATA_CONNECTION_OTHER; |
| 3469 | break; |
| 3470 | } |
| 3471 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3472 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3473 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3474 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3475 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3476 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3477 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3478 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3479 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3480 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3481 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3482 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3483 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3484 | } |
| 3485 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3486 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3487 | } |
| 3488 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3489 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3490 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3491 | if (!mWifiOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3492 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3493 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3494 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3495 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3496 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3497 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3498 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3499 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 3500 | scheduleSyncExternalWifiStatsLocked("wifi-off"); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3501 | } |
| 3502 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3503 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3504 | public void noteWifiOffLocked() { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3505 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3506 | final long uptime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3507 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3508 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3509 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3510 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3511 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3512 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3513 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 3514 | scheduleSyncExternalWifiStatsLocked("wifi-on"); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3515 | } |
| 3516 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3517 | |
| 3518 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3519 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3520 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3521 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3522 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3523 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3524 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3525 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3526 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3527 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3528 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3529 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3530 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3531 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3532 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3533 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3534 | if (mAudioOnNesting == 0) { |
| 3535 | return; |
| 3536 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3537 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3538 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3539 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3540 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3541 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3542 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3543 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3544 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3545 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3546 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3547 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3551 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3552 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3553 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3554 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3555 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3556 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3557 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3558 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3559 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3560 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3561 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3562 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3563 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3564 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3565 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3566 | if (mVideoOnNesting == 0) { |
| 3567 | return; |
| 3568 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3569 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3570 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3571 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3572 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3573 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3574 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3575 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3576 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3577 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3578 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3579 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3582 | public void noteResetAudioLocked() { |
| 3583 | if (mAudioOnNesting > 0) { |
| 3584 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3585 | final long uptime = SystemClock.uptimeMillis(); |
| 3586 | mAudioOnNesting = 0; |
| 3587 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3588 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3589 | + Integer.toHexString(mHistoryCur.states)); |
| 3590 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3591 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3592 | for (int i=0; i<mUidStats.size(); i++) { |
| 3593 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3594 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | public void noteResetVideoLocked() { |
| 3600 | if (mVideoOnNesting > 0) { |
| 3601 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3602 | final long uptime = SystemClock.uptimeMillis(); |
| 3603 | mAudioOnNesting = 0; |
| 3604 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3605 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3606 | + Integer.toHexString(mHistoryCur.states)); |
| 3607 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3608 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3609 | for (int i=0; i<mUidStats.size(); i++) { |
| 3610 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3611 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3612 | } |
| 3613 | } |
| 3614 | } |
| 3615 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3616 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3617 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3618 | getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3622 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3623 | getUidStatsLocked(uid).noteActivityPausedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3626 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3627 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3628 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3629 | } |
| 3630 | |
| 3631 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3632 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3633 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3634 | } |
| 3635 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3636 | public void noteFlashlightOnLocked(int uid) { |
| 3637 | uid = mapUid(uid); |
| 3638 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3639 | final long uptime = SystemClock.uptimeMillis(); |
| 3640 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3641 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3642 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3643 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3644 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3645 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3646 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3647 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 3648 | } |
| 3649 | |
| 3650 | public void noteFlashlightOffLocked(int uid) { |
| 3651 | if (mFlashlightOnNesting == 0) { |
| 3652 | return; |
| 3653 | } |
| 3654 | uid = mapUid(uid); |
| 3655 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3656 | final long uptime = SystemClock.uptimeMillis(); |
| 3657 | if (--mFlashlightOnNesting == 0) { |
| 3658 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3659 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3660 | + Integer.toHexString(mHistoryCur.states2)); |
| 3661 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3662 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3663 | } |
| 3664 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 3665 | } |
| 3666 | |
| 3667 | public void noteCameraOnLocked(int uid) { |
| 3668 | uid = mapUid(uid); |
| 3669 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3670 | final long uptime = SystemClock.uptimeMillis(); |
| 3671 | if (mCameraOnNesting++ == 0) { |
| 3672 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 3673 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 3674 | + Integer.toHexString(mHistoryCur.states2)); |
| 3675 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3676 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 3677 | } |
| 3678 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 3679 | } |
| 3680 | |
| 3681 | public void noteCameraOffLocked(int uid) { |
| 3682 | if (mCameraOnNesting == 0) { |
| 3683 | return; |
| 3684 | } |
| 3685 | uid = mapUid(uid); |
| 3686 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3687 | final long uptime = SystemClock.uptimeMillis(); |
| 3688 | if (--mCameraOnNesting == 0) { |
| 3689 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3690 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3691 | + Integer.toHexString(mHistoryCur.states2)); |
| 3692 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3693 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 3694 | } |
| 3695 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 3696 | } |
| 3697 | |
| 3698 | public void noteResetCameraLocked() { |
| 3699 | if (mCameraOnNesting > 0) { |
| 3700 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3701 | final long uptime = SystemClock.uptimeMillis(); |
| 3702 | mCameraOnNesting = 0; |
| 3703 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3704 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3705 | + Integer.toHexString(mHistoryCur.states2)); |
| 3706 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3707 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3708 | for (int i=0; i<mUidStats.size(); i++) { |
| 3709 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3710 | uid.noteResetCameraLocked(elapsedRealtime); |
| 3711 | } |
| 3712 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3715 | public void noteResetFlashlightLocked() { |
| 3716 | if (mFlashlightOnNesting > 0) { |
| 3717 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3718 | final long uptime = SystemClock.uptimeMillis(); |
| 3719 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3720 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3721 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3722 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3723 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3724 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3725 | for (int i=0; i<mUidStats.size(); i++) { |
| 3726 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3727 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 3728 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3732 | public void noteWifiRadioPowerState(int powerState, long timestampNs) { |
| 3733 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3734 | final long uptime = SystemClock.uptimeMillis(); |
| 3735 | if (mWifiRadioPowerState != powerState) { |
| 3736 | final boolean active = |
| 3737 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3738 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3739 | if (active) { |
| 3740 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 3741 | } else { |
| 3742 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 3743 | } |
| 3744 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 3745 | + Integer.toHexString(mHistoryCur.states)); |
| 3746 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3747 | mWifiRadioPowerState = powerState; |
| 3748 | } |
| 3749 | } |
| 3750 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3751 | public void noteWifiRunningLocked(WorkSource ws) { |
| 3752 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3753 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3754 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3755 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3756 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 3757 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3758 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3759 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3760 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3761 | int N = ws.size(); |
| 3762 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3763 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3764 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3765 | } |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 3766 | scheduleSyncExternalWifiStatsLocked("wifi-running"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3767 | } else { |
| 3768 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3769 | } |
| 3770 | } |
| 3771 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3772 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 3773 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3774 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3775 | int N = oldWs.size(); |
| 3776 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3777 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3778 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3779 | } |
| 3780 | N = newWs.size(); |
| 3781 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3782 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3783 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3784 | } |
| 3785 | } else { |
| 3786 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 3791 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3792 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3793 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3794 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3795 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 3796 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3797 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3798 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3799 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3800 | int N = ws.size(); |
| 3801 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3802 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3803 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3804 | } |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 3805 | scheduleSyncExternalWifiStatsLocked("wifi-stopped"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3806 | } else { |
| 3807 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3811 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 3812 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 3813 | if (mWifiState != wifiState) { |
| 3814 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3815 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3816 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3817 | } |
| 3818 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3819 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 3820 | scheduleSyncExternalWifiStatsLocked("wifi-state"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3824 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 3825 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 3826 | if (mWifiSupplState != supplState) { |
| 3827 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3828 | final long uptime = SystemClock.uptimeMillis(); |
| 3829 | if (mWifiSupplState >= 0) { |
| 3830 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 3831 | } |
| 3832 | mWifiSupplState = supplState; |
| 3833 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 3834 | mHistoryCur.states2 = |
| 3835 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 3836 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 3837 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 3838 | + Integer.toHexString(mHistoryCur.states2)); |
| 3839 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3840 | } |
| 3841 | } |
| 3842 | |
| 3843 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
| 3844 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3845 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3846 | if (i == except) { |
| 3847 | continue; |
| 3848 | } |
| 3849 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 3850 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 3851 | } |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 3856 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 3857 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 3858 | if (mWifiSignalStrengthBin != strengthBin) { |
| 3859 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3860 | final long uptime = SystemClock.uptimeMillis(); |
| 3861 | if (mWifiSignalStrengthBin >= 0) { |
| 3862 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 3863 | elapsedRealtime); |
| 3864 | } |
| 3865 | if (strengthBin >= 0) { |
| 3866 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 3867 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 3868 | } |
| 3869 | mHistoryCur.states2 = |
| 3870 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 3871 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 3872 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 3873 | + Integer.toHexString(mHistoryCur.states2)); |
| 3874 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3875 | } else { |
| 3876 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 3877 | } |
| 3878 | mWifiSignalStrengthBin = strengthBin; |
| 3879 | } |
| 3880 | } |
| 3881 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3882 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3883 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3884 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3885 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3886 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3887 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3888 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3889 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3890 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 3891 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3892 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3893 | } |
| 3894 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3895 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3899 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3900 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3901 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3902 | mWifiFullLockNesting--; |
| 3903 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3904 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3905 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 3906 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3907 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3908 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3909 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3912 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3913 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3914 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3915 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3916 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3917 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3918 | if (mWifiScanNesting == 0) { |
| 3919 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3920 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3921 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3922 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3923 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3924 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3925 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3926 | } |
| 3927 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3928 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3929 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3930 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3931 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3932 | mWifiScanNesting--; |
| 3933 | if (mWifiScanNesting == 0) { |
| 3934 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3935 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3936 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3937 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3938 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3939 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3940 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3941 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3942 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3943 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3944 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3945 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3949 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3950 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3951 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3954 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3955 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3956 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3957 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3958 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3959 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3960 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3961 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3962 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 3963 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3964 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3965 | } |
| 3966 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3967 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3971 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3972 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3973 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3974 | mWifiMulticastNesting--; |
| 3975 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3976 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3977 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 3978 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3979 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3980 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3981 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3984 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 3985 | int N = ws.size(); |
| 3986 | for (int i=0; i<N; i++) { |
| 3987 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 3992 | int N = ws.size(); |
| 3993 | for (int i=0; i<N; i++) { |
| 3994 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 3995 | } |
| 3996 | } |
| 3997 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3998 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3999 | int N = ws.size(); |
| 4000 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4001 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4005 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4006 | int N = ws.size(); |
| 4007 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4008 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4009 | } |
| 4010 | } |
| 4011 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4012 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4013 | int N = ws.size(); |
| 4014 | for (int i=0; i<N; i++) { |
| 4015 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4020 | int N = ws.size(); |
| 4021 | for (int i=0; i<N; i++) { |
| 4022 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4023 | } |
| 4024 | } |
| 4025 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4026 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4027 | int N = ws.size(); |
| 4028 | for (int i=0; i<N; i++) { |
| 4029 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4030 | } |
| 4031 | } |
| 4032 | |
| 4033 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4034 | int N = ws.size(); |
| 4035 | for (int i=0; i<N; i++) { |
| 4036 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4037 | } |
| 4038 | } |
| 4039 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4040 | private static String[] includeInStringArray(String[] array, String str) { |
| 4041 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4042 | return array; |
| 4043 | } |
| 4044 | String[] newArray = new String[array.length+1]; |
| 4045 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4046 | newArray[array.length] = str; |
| 4047 | return newArray; |
| 4048 | } |
| 4049 | |
| 4050 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4051 | int index = ArrayUtils.indexOf(array, str); |
| 4052 | if (index >= 0) { |
| 4053 | String[] newArray = new String[array.length-1]; |
| 4054 | if (index > 0) { |
| 4055 | System.arraycopy(array, 0, newArray, 0, index); |
| 4056 | } |
| 4057 | if (index < array.length-1) { |
| 4058 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4059 | } |
| 4060 | return newArray; |
| 4061 | } |
| 4062 | return array; |
| 4063 | } |
| 4064 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4065 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4066 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4067 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4068 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4069 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4070 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4071 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4072 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4073 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4074 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4075 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4076 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4077 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4078 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4079 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | public void noteNetworkStatsEnabledLocked() { |
| 4084 | // During device boot, qtaguid isn't enabled until after the inital |
| 4085 | // loading of battery stats. Now that they're enabled, take our initial |
| 4086 | // snapshot for future delta calculation. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4087 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 4088 | updateMobileRadioStateLocked(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4089 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4092 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4093 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4095 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4096 | @Override public int getScreenOnCount(int which) { |
| 4097 | return mScreenOnTimer.getCountLocked(which); |
| 4098 | } |
| 4099 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4100 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4101 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4102 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4103 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4104 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4105 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4106 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4107 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4108 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4109 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4110 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4111 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4114 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4115 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4116 | } |
| 4117 | |
| 4118 | @Override public long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4119 | return mDeviceIdleModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4120 | } |
| 4121 | |
| 4122 | @Override public int getDeviceIdleModeEnabledCount(int which) { |
| 4123 | return mDeviceIdleModeEnabledTimer.getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4124 | } |
| 4125 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4126 | @Override public long getDeviceIdlingTime(long elapsedRealtimeUs, int which) { |
| 4127 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4128 | } |
| 4129 | |
| 4130 | @Override public int getDeviceIdlingCount(int which) { |
| 4131 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4132 | } |
| 4133 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4134 | @Override public int getNumConnectivityChange(int which) { |
| 4135 | int val = mNumConnectivityChange; |
| 4136 | if (which == STATS_CURRENT) { |
| 4137 | val -= mLoadedNumConnectivityChange; |
| 4138 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4139 | val -= mUnpluggedNumConnectivityChange; |
| 4140 | } |
| 4141 | return val; |
| 4142 | } |
| 4143 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4144 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4145 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4147 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4148 | @Override public int getPhoneOnCount(int which) { |
| 4149 | return mPhoneOnTimer.getCountLocked(which); |
| 4150 | } |
| 4151 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4152 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4153 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4154 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4155 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4156 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4157 | |
| 4158 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4159 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4160 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4161 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4162 | } |
| 4163 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4164 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4165 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4166 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4167 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4168 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4169 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4170 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4171 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4172 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4173 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4174 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4175 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4176 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4177 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4178 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4179 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4180 | } |
| 4181 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4182 | @Override public int getMobileRadioActiveCount(int which) { |
| 4183 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4184 | } |
| 4185 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4186 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4187 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4188 | } |
| 4189 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4190 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4191 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4192 | } |
| 4193 | |
| 4194 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4195 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4196 | } |
| 4197 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4198 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4199 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4200 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4201 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4202 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4203 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4206 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4207 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4208 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4209 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4213 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4214 | } |
| 4215 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4216 | @Override public long getWifiSupplStateTime(int state, |
| 4217 | long elapsedRealtimeUs, int which) { |
| 4218 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4219 | elapsedRealtimeUs, which); |
| 4220 | } |
| 4221 | |
| 4222 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4223 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4224 | } |
| 4225 | |
| 4226 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4227 | long elapsedRealtimeUs, int which) { |
| 4228 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4229 | elapsedRealtimeUs, which); |
| 4230 | } |
| 4231 | |
| 4232 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4233 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4234 | } |
| 4235 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4236 | @Override public boolean hasBluetoothActivityReporting() { |
| 4237 | return mHasBluetoothEnergyReporting; |
| 4238 | } |
| 4239 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4240 | @Override public long getBluetoothControllerActivity(int type, int which) { |
| 4241 | if (type >= 0 && type < mBluetoothActivityCounters.length) { |
| 4242 | return mBluetoothActivityCounters[type].getCountLocked(which); |
| 4243 | } |
| 4244 | return 0; |
| 4245 | } |
| 4246 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4247 | @Override public boolean hasWifiActivityReporting() { |
| 4248 | return mHasWifiEnergyReporting; |
| 4249 | } |
| 4250 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4251 | @Override public long getWifiControllerActivity(int type, int which) { |
| 4252 | if (type >= 0 && type < mWifiActivityCounters.length) { |
| 4253 | return mWifiActivityCounters[type].getCountLocked(which); |
| 4254 | } |
| 4255 | return 0; |
| 4256 | } |
| 4257 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4258 | @Override |
| 4259 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4260 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4261 | } |
| 4262 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4263 | @Override |
| 4264 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4265 | return mFlashlightOnTimer.getCountLocked(which); |
| 4266 | } |
| 4267 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4268 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4269 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4270 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4271 | } |
| 4272 | |
| 4273 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4274 | public long getNetworkActivityBytes(int type, int which) { |
| 4275 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4276 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4277 | } else { |
| 4278 | return 0; |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | @Override |
| 4283 | public long getNetworkActivityPackets(int type, int which) { |
| 4284 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4285 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4286 | } else { |
| 4287 | return 0; |
| 4288 | } |
| 4289 | } |
| 4290 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4291 | boolean isStartClockTimeValid() { |
| 4292 | return mStartClockTime > 365*24*60*60*1000L; |
| 4293 | } |
| 4294 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4295 | @Override public long getStartClockTime() { |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4296 | if (!isStartClockTimeValid()) { |
| 4297 | // If the last clock time we got was very small, then we hadn't had a real |
| 4298 | // time yet, so try to get it again. |
| 4299 | mStartClockTime = System.currentTimeMillis(); |
| 4300 | if (isStartClockTimeValid()) { |
| 4301 | recordCurrentTimeChangeLocked(mStartClockTime, SystemClock.elapsedRealtime(), |
| 4302 | SystemClock.uptimeMillis()); |
| 4303 | } |
| 4304 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4305 | return mStartClockTime; |
| 4306 | } |
| 4307 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4308 | @Override public String getStartPlatformVersion() { |
| 4309 | return mStartPlatformVersion; |
| 4310 | } |
| 4311 | |
| 4312 | @Override public String getEndPlatformVersion() { |
| 4313 | return mEndPlatformVersion; |
| 4314 | } |
| 4315 | |
| 4316 | @Override public int getParcelVersion() { |
| 4317 | return VERSION; |
| 4318 | } |
| 4319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | @Override public boolean getIsOnBattery() { |
| 4321 | return mOnBattery; |
| 4322 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4325 | return mUidStats; |
| 4326 | } |
| 4327 | |
| 4328 | /** |
| 4329 | * The statistics associated with a particular uid. |
| 4330 | */ |
| 4331 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4334 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4335 | boolean mWifiRunning; |
| 4336 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4337 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4338 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4339 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4340 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4341 | boolean mWifiScanStarted; |
| 4342 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4343 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4344 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4345 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4346 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4347 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4348 | boolean mWifiMulticastEnabled; |
| 4349 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4350 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4351 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4352 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4353 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 4354 | StopwatchTimer mCameraTurnedOnTimer; |
| 4355 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4356 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4357 | StopwatchTimer mForegroundActivityTimer; |
| 4358 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4359 | static final int PROCESS_STATE_NONE = NUM_PROCESS_STATE; |
| 4360 | int mProcessState = PROCESS_STATE_NONE; |
| 4361 | StopwatchTimer[] mProcessStateTimer; |
| 4362 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4363 | BatchTimer mVibratorOnTimer; |
| 4364 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4365 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4366 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4367 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4368 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4369 | LongSamplingCounter mMobileRadioActiveTime; |
| 4370 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4373 | * The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode. |
| 4374 | */ |
| 4375 | LongSamplingCounter[] mWifiControllerTime = |
| 4376 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4377 | |
| 4378 | /** |
| 4379 | * The amount of time this uid has kept the Bluetooth controller in idle, tx, and rx mode. |
| 4380 | */ |
| 4381 | LongSamplingCounter[] mBluetoothControllerTime = |
| 4382 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4383 | |
| 4384 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4385 | * The CPU times we had at the last history details update. |
| 4386 | */ |
| 4387 | long mLastStepUserTime; |
| 4388 | long mLastStepSystemTime; |
| 4389 | long mCurStepUserTime; |
| 4390 | long mCurStepSystemTime; |
| 4391 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4392 | LongSamplingCounter mUserCpuTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4393 | LongSamplingCounter mSystemCpuTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4394 | LongSamplingCounter[] mSpeedBins; |
| 4395 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4396 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | * The statistics we have collected for this uid's wake locks. |
| 4398 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4399 | final OverflowArrayMap<Wakelock> mWakelockStats = new OverflowArrayMap<Wakelock>() { |
| 4400 | @Override public Wakelock instantiateObject() { return new Wakelock(); } |
| 4401 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4402 | |
| 4403 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4404 | * The statistics we have collected for this uid's syncs. |
| 4405 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4406 | final OverflowArrayMap<StopwatchTimer> mSyncStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4407 | @Override public StopwatchTimer instantiateObject() { |
| 4408 | return new StopwatchTimer(Uid.this, SYNC, null, mOnBatteryTimeBase); |
| 4409 | } |
| 4410 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4411 | |
| 4412 | /** |
| 4413 | * The statistics we have collected for this uid's jobs. |
| 4414 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4415 | final OverflowArrayMap<StopwatchTimer> mJobStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4416 | @Override public StopwatchTimer instantiateObject() { |
| 4417 | return new StopwatchTimer(Uid.this, JOB, null, mOnBatteryTimeBase); |
| 4418 | } |
| 4419 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4420 | |
| 4421 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | * The statistics we have collected for this uid's sensor activations. |
| 4423 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4424 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | |
| 4426 | /** |
| 4427 | * The statistics we have collected for this uid's processes. |
| 4428 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4429 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | |
| 4431 | /** |
| 4432 | * The statistics we have collected for this uid's processes. |
| 4433 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4434 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4435 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4436 | /** |
| 4437 | * The transient wake stats we have collected for this uid's pids. |
| 4438 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4439 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | public Uid(int uid) { |
| 4442 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4443 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4444 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4445 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4446 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4447 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4448 | mWifiScanTimers, mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4449 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4450 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4451 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4452 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4453 | mSpeedBins = new LongSamplingCounter[getCpuSpeedSteps()]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4457 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4458 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4462 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4463 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4467 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4468 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4472 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | return mSensorStats; |
| 4474 | } |
| 4475 | |
| 4476 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4477 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | return mProcessStats; |
| 4479 | } |
| 4480 | |
| 4481 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4482 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | return mPackageStats; |
| 4484 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4485 | |
| 4486 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | public int getUid() { |
| 4488 | return mUid; |
| 4489 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4490 | |
| 4491 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4492 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4493 | if (!mWifiRunning) { |
| 4494 | mWifiRunning = true; |
| 4495 | if (mWifiRunningTimer == null) { |
| 4496 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4497 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4498 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4499 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4500 | } |
| 4501 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4502 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4503 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4504 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4505 | if (mWifiRunning) { |
| 4506 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4507 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4508 | } |
| 4509 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4510 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4511 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4512 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4513 | if (!mFullWifiLockOut) { |
| 4514 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4515 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4516 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4517 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4518 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4519 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4520 | } |
| 4521 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4522 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4523 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4524 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4525 | if (mFullWifiLockOut) { |
| 4526 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4527 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4528 | } |
| 4529 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4530 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4531 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4532 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4533 | if (!mWifiScanStarted) { |
| 4534 | mWifiScanStarted = true; |
| 4535 | if (mWifiScanTimer == null) { |
| 4536 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4537 | mWifiScanTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4538 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4539 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4540 | } |
| 4541 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4542 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4543 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4544 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4545 | if (mWifiScanStarted) { |
| 4546 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4547 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4548 | } |
| 4549 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4550 | |
| 4551 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4552 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4553 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 4554 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4555 | csph = csph >> 3; |
| 4556 | bin++; |
| 4557 | } |
| 4558 | |
| 4559 | if (mWifiBatchedScanBinStarted == bin) return; |
| 4560 | |
| 4561 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4562 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4563 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4564 | } |
| 4565 | mWifiBatchedScanBinStarted = bin; |
| 4566 | if (mWifiBatchedScanTimer[bin] == null) { |
| 4567 | makeWifiBatchedScanBin(bin, null); |
| 4568 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4569 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4573 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4574 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4575 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4576 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4577 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4582 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4583 | if (!mWifiMulticastEnabled) { |
| 4584 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4585 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4586 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4587 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4588 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4589 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4594 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4595 | if (mWifiMulticastEnabled) { |
| 4596 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4597 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4601 | public void noteWifiControllerActivityLocked(int type, long timeMs) { |
| 4602 | if (mWifiControllerTime[type] == null) { |
| 4603 | mWifiControllerTime[type] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4604 | } |
| 4605 | mWifiControllerTime[type].addCountLocked(timeMs); |
| 4606 | } |
| 4607 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4608 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 4609 | if (mAudioTurnedOnTimer == null) { |
| 4610 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4611 | mAudioTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4612 | } |
| 4613 | return mAudioTurnedOnTimer; |
| 4614 | } |
| 4615 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4616 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4617 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4618 | } |
| 4619 | |
| 4620 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 4621 | if (mAudioTurnedOnTimer != null) { |
| 4622 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4626 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 4627 | if (mAudioTurnedOnTimer != null) { |
| 4628 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4629 | } |
| 4630 | } |
| 4631 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4632 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 4633 | if (mVideoTurnedOnTimer == null) { |
| 4634 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4635 | mVideoTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4636 | } |
| 4637 | return mVideoTurnedOnTimer; |
| 4638 | } |
| 4639 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4640 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4641 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4642 | } |
| 4643 | |
| 4644 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 4645 | if (mVideoTurnedOnTimer != null) { |
| 4646 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4647 | } |
| 4648 | } |
| 4649 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4650 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 4651 | if (mVideoTurnedOnTimer != null) { |
| 4652 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4653 | } |
| 4654 | } |
| 4655 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4656 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 4657 | if (mFlashlightTurnedOnTimer == null) { |
| 4658 | mFlashlightTurnedOnTimer = new StopwatchTimer(Uid.this, FLASHLIGHT_TURNED_ON, |
| 4659 | mFlashlightTurnedOnTimers, mOnBatteryTimeBase); |
| 4660 | } |
| 4661 | return mFlashlightTurnedOnTimer; |
| 4662 | } |
| 4663 | |
| 4664 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 4665 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4666 | } |
| 4667 | |
| 4668 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 4669 | if (mFlashlightTurnedOnTimer != null) { |
| 4670 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 4675 | if (mFlashlightTurnedOnTimer != null) { |
| 4676 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 4681 | if (mCameraTurnedOnTimer == null) { |
| 4682 | mCameraTurnedOnTimer = new StopwatchTimer(Uid.this, CAMERA_TURNED_ON, |
| 4683 | mCameraTurnedOnTimers, mOnBatteryTimeBase); |
| 4684 | } |
| 4685 | return mCameraTurnedOnTimer; |
| 4686 | } |
| 4687 | |
| 4688 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 4689 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4690 | } |
| 4691 | |
| 4692 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 4693 | if (mCameraTurnedOnTimer != null) { |
| 4694 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 4699 | if (mCameraTurnedOnTimer != null) { |
| 4700 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 4701 | } |
| 4702 | } |
| 4703 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4704 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 4705 | if (mForegroundActivityTimer == null) { |
| 4706 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4707 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4708 | } |
| 4709 | return mForegroundActivityTimer; |
| 4710 | } |
| 4711 | |
| 4712 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4713 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4714 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4715 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4719 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4720 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4721 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4725 | void updateUidProcessStateLocked(int state, long elapsedRealtimeMs) { |
| 4726 | if (mProcessState == state) return; |
| 4727 | |
| 4728 | if (mProcessState != PROCESS_STATE_NONE) { |
| 4729 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
| 4730 | } |
| 4731 | mProcessState = state; |
| 4732 | if (state != PROCESS_STATE_NONE) { |
| 4733 | if (mProcessStateTimer[state] == null) { |
| 4734 | makeProcessState(state, null); |
| 4735 | } |
| 4736 | mProcessStateTimer[state].startRunningLocked(elapsedRealtimeMs); |
| 4737 | } |
| 4738 | } |
| 4739 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4740 | public BatchTimer createVibratorOnTimerLocked() { |
| 4741 | if (mVibratorOnTimer == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4742 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4743 | } |
| 4744 | return mVibratorOnTimer; |
| 4745 | } |
| 4746 | |
| 4747 | public void noteVibratorOnLocked(long durationMillis) { |
| 4748 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 4749 | } |
| 4750 | |
| 4751 | public void noteVibratorOffLocked() { |
| 4752 | if (mVibratorOnTimer != null) { |
| 4753 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4754 | } |
| 4755 | } |
| 4756 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4757 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4758 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4759 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4760 | return 0; |
| 4761 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4762 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4763 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4764 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4765 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4766 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4767 | if (mFullWifiLockTimer == null) { |
| 4768 | return 0; |
| 4769 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4770 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4771 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4772 | |
| 4773 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4774 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4775 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4776 | return 0; |
| 4777 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4778 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4779 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4780 | |
| 4781 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4782 | public int getWifiScanCount(int which) { |
| 4783 | if (mWifiScanTimer == null) { |
| 4784 | return 0; |
| 4785 | } |
| 4786 | return mWifiScanTimer.getCountLocked(which); |
| 4787 | } |
| 4788 | |
| 4789 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4790 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4791 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4792 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4793 | return 0; |
| 4794 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4795 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4799 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 4800 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4801 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4802 | return 0; |
| 4803 | } |
| 4804 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 4805 | } |
| 4806 | |
| 4807 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4808 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4809 | if (mWifiMulticastTimer == null) { |
| 4810 | return 0; |
| 4811 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4812 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4815 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4816 | public Timer getAudioTurnedOnTimer() { |
| 4817 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4820 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4821 | public Timer getVideoTurnedOnTimer() { |
| 4822 | return mVideoTurnedOnTimer; |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
| 4826 | public Timer getFlashlightTurnedOnTimer() { |
| 4827 | return mFlashlightTurnedOnTimer; |
| 4828 | } |
| 4829 | |
| 4830 | @Override |
| 4831 | public Timer getCameraTurnedOnTimer() { |
| 4832 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4835 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4836 | public Timer getForegroundActivityTimer() { |
| 4837 | return mForegroundActivityTimer; |
| 4838 | } |
| 4839 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4840 | void makeProcessState(int i, Parcel in) { |
| 4841 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 4842 | |
| 4843 | if (in == null) { |
| 4844 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4845 | mOnBatteryTimeBase); |
| 4846 | } else { |
| 4847 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4848 | mOnBatteryTimeBase, in); |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | @Override |
| 4853 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 4854 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 4855 | if (mProcessStateTimer[state] == null) { |
| 4856 | return 0; |
| 4857 | } |
| 4858 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4859 | } |
| 4860 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4861 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4862 | public Timer getVibratorOnTimer() { |
| 4863 | return mVibratorOnTimer; |
| 4864 | } |
| 4865 | |
| 4866 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4867 | public void noteUserActivityLocked(int type) { |
| 4868 | if (mUserActivityCounters == null) { |
| 4869 | initUserActivityLocked(); |
| 4870 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 4871 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 4872 | mUserActivityCounters[type].stepAtomic(); |
| 4873 | } else { |
| 4874 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 4875 | new Throwable()); |
| 4876 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4877 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4878 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4879 | @Override |
| 4880 | public boolean hasUserActivity() { |
| 4881 | return mUserActivityCounters != null; |
| 4882 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4883 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4884 | @Override |
| 4885 | public int getUserActivityCount(int type, int which) { |
| 4886 | if (mUserActivityCounters == null) { |
| 4887 | return 0; |
| 4888 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4889 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4890 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4891 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4892 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 4893 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 4894 | |
| 4895 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 4896 | if (collected == null) { |
| 4897 | collected = new ArrayList<StopwatchTimer>(); |
| 4898 | mWifiBatchedScanTimers.put(i, collected); |
| 4899 | } |
| 4900 | if (in == null) { |
| 4901 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4902 | mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4903 | } else { |
| 4904 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4905 | mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4910 | void initUserActivityLocked() { |
| 4911 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4912 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4913 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4914 | } |
| 4915 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4916 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4917 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 4918 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4919 | initNetworkActivityLocked(); |
| 4920 | } |
| 4921 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4922 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 4923 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4924 | } else { |
| 4925 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 4926 | new Throwable()); |
| 4927 | } |
| 4928 | } |
| 4929 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4930 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 4931 | if (mNetworkByteActivityCounters == null) { |
| 4932 | initNetworkActivityLocked(); |
| 4933 | } |
| 4934 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 4935 | mMobileRadioActiveCount.addCountLocked(1); |
| 4936 | } |
| 4937 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4938 | @Override |
| 4939 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4940 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4944 | public long getNetworkActivityBytes(int type, int which) { |
| 4945 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 4946 | && type < mNetworkByteActivityCounters.length) { |
| 4947 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4948 | } else { |
| 4949 | return 0; |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | @Override |
| 4954 | public long getNetworkActivityPackets(int type, int which) { |
| 4955 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 4956 | && type < mNetworkPacketActivityCounters.length) { |
| 4957 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4958 | } else { |
| 4959 | return 0; |
| 4960 | } |
| 4961 | } |
| 4962 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4963 | @Override |
| 4964 | public long getMobileRadioActiveTime(int which) { |
| 4965 | return mMobileRadioActiveTime != null |
| 4966 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 4967 | } |
| 4968 | |
| 4969 | @Override |
| 4970 | public int getMobileRadioActiveCount(int which) { |
| 4971 | return mMobileRadioActiveCount != null |
| 4972 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 4973 | } |
| 4974 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4975 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4976 | public long getUserCpuTimeUs(int which) { |
| 4977 | return mUserCpuTime.getCountLocked(which); |
| 4978 | } |
| 4979 | |
| 4980 | @Override |
| 4981 | public long getSystemCpuTimeUs(int which) { |
| 4982 | return mSystemCpuTime.getCountLocked(which); |
| 4983 | } |
| 4984 | |
| 4985 | @Override |
| 4986 | public long getTimeAtCpuSpeed(int step, int which) { |
| 4987 | if (step >= 0 && step < mSpeedBins.length) { |
| 4988 | if (mSpeedBins[step] != null) { |
| 4989 | return mSpeedBins[step].getCountLocked(which); |
| 4990 | } |
| 4991 | } |
| 4992 | return 0; |
| 4993 | } |
| 4994 | |
| 4995 | @Override |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4996 | public long getWifiControllerActivity(int type, int which) { |
| 4997 | if (type >= 0 && type < NUM_CONTROLLER_ACTIVITY_TYPES && |
| 4998 | mWifiControllerTime[type] != null) { |
| 4999 | return mWifiControllerTime[type].getCountLocked(which); |
| 5000 | } |
| 5001 | return 0; |
| 5002 | } |
| 5003 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5004 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5005 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5006 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5007 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5008 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5009 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5010 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5011 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5012 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5013 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5014 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5015 | /** |
| 5016 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5017 | * inactive so can be dropped. |
| 5018 | */ |
| 5019 | boolean reset() { |
| 5020 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5021 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5022 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5023 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5024 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5025 | } |
| 5026 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5027 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5028 | active |= mFullWifiLockOut; |
| 5029 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5030 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5031 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5032 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5033 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5034 | if (mWifiBatchedScanTimer != null) { |
| 5035 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5036 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5037 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5038 | } |
| 5039 | } |
| 5040 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5041 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5042 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5043 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5044 | active |= mWifiMulticastEnabled; |
| 5045 | } |
| 5046 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5047 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5048 | } |
| 5049 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5050 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5051 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5052 | if (mFlashlightTurnedOnTimer != null) { |
| 5053 | active |= !mFlashlightTurnedOnTimer.reset(false); |
| 5054 | } |
| 5055 | if (mCameraTurnedOnTimer != null) { |
| 5056 | active |= !mCameraTurnedOnTimer.reset(false); |
| 5057 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5058 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5059 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5060 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5061 | if (mProcessStateTimer != null) { |
| 5062 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5063 | if (mProcessStateTimer[i] != null) { |
| 5064 | active |= !mProcessStateTimer[i].reset(false); |
| 5065 | } |
| 5066 | } |
| 5067 | active |= (mProcessState != PROCESS_STATE_NONE); |
| 5068 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5069 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5070 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5071 | mVibratorOnTimer.detach(); |
| 5072 | mVibratorOnTimer = null; |
| 5073 | } else { |
| 5074 | active = true; |
| 5075 | } |
| 5076 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5077 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5078 | if (mUserActivityCounters != null) { |
| 5079 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5080 | mUserActivityCounters[i].reset(false); |
| 5081 | } |
| 5082 | } |
| 5083 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5084 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5085 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5086 | mNetworkByteActivityCounters[i].reset(false); |
| 5087 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5088 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5089 | mMobileRadioActiveTime.reset(false); |
| 5090 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5091 | } |
| 5092 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5093 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5094 | if (mWifiControllerTime[i] != null) { |
| 5095 | mWifiControllerTime[i].reset(false); |
| 5096 | } |
| 5097 | |
| 5098 | if (mBluetoothControllerTime[i] != null) { |
| 5099 | mBluetoothControllerTime[i].reset(false); |
| 5100 | } |
| 5101 | } |
| 5102 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5103 | mUserCpuTime.reset(false); |
| 5104 | mSystemCpuTime.reset(false); |
| 5105 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5106 | LongSamplingCounter c = mSpeedBins[i]; |
| 5107 | if (c != null) { |
| 5108 | c.reset(false); |
| 5109 | } |
| 5110 | } |
| 5111 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5112 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5113 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5114 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5115 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5116 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5117 | } else { |
| 5118 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5119 | } |
| 5120 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5121 | mWakelockStats.cleanup(); |
| 5122 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5123 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5124 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5125 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5126 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5127 | timer.detach(); |
| 5128 | } else { |
| 5129 | active = true; |
| 5130 | } |
| 5131 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5132 | mSyncStats.cleanup(); |
| 5133 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5134 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5135 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5136 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5137 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5138 | timer.detach(); |
| 5139 | } else { |
| 5140 | active = true; |
| 5141 | } |
| 5142 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5143 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5144 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5145 | Sensor s = mSensorStats.valueAt(ise); |
| 5146 | if (s.reset()) { |
| 5147 | mSensorStats.removeAt(ise); |
| 5148 | } else { |
| 5149 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5150 | } |
| 5151 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5152 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5153 | Proc proc = mProcessStats.valueAt(ip); |
| 5154 | if (proc.mProcessState == PROCESS_STATE_NONE) { |
| 5155 | proc.detach(); |
| 5156 | mProcessStats.removeAt(ip); |
| 5157 | } else { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5158 | proc.reset(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5159 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5160 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5161 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5162 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5163 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5164 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5165 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5166 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5167 | } else { |
| 5168 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5169 | } |
| 5170 | } |
| 5171 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5172 | if (mPackageStats.size() > 0) { |
| 5173 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5174 | while (it.hasNext()) { |
| 5175 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5176 | Pkg p = pkgEntry.getValue(); |
| 5177 | p.detach(); |
| 5178 | if (p.mServiceStats.size() > 0) { |
| 5179 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5180 | = p.mServiceStats.entrySet().iterator(); |
| 5181 | while (it2.hasNext()) { |
| 5182 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5183 | servEntry.getValue().detach(); |
| 5184 | } |
| 5185 | } |
| 5186 | } |
| 5187 | mPackageStats.clear(); |
| 5188 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5189 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5190 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5191 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5192 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5193 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5194 | if (mWifiRunningTimer != null) { |
| 5195 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5196 | } |
| 5197 | if (mFullWifiLockTimer != null) { |
| 5198 | mFullWifiLockTimer.detach(); |
| 5199 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5200 | if (mWifiScanTimer != null) { |
| 5201 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5202 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5203 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5204 | if (mWifiBatchedScanTimer[i] != null) { |
| 5205 | mWifiBatchedScanTimer[i].detach(); |
| 5206 | } |
| 5207 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5208 | if (mWifiMulticastTimer != null) { |
| 5209 | mWifiMulticastTimer.detach(); |
| 5210 | } |
| 5211 | if (mAudioTurnedOnTimer != null) { |
| 5212 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5213 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5214 | } |
| 5215 | if (mVideoTurnedOnTimer != null) { |
| 5216 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5217 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5218 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5219 | if (mFlashlightTurnedOnTimer != null) { |
| 5220 | mFlashlightTurnedOnTimer.detach(); |
| 5221 | mFlashlightTurnedOnTimer = null; |
| 5222 | } |
| 5223 | if (mCameraTurnedOnTimer != null) { |
| 5224 | mCameraTurnedOnTimer.detach(); |
| 5225 | mCameraTurnedOnTimer = null; |
| 5226 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5227 | if (mForegroundActivityTimer != null) { |
| 5228 | mForegroundActivityTimer.detach(); |
| 5229 | mForegroundActivityTimer = null; |
| 5230 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5231 | if (mUserActivityCounters != null) { |
| 5232 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5233 | mUserActivityCounters[i].detach(); |
| 5234 | } |
| 5235 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5236 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5237 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5238 | mNetworkByteActivityCounters[i].detach(); |
| 5239 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5240 | } |
| 5241 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5242 | |
| 5243 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5244 | if (mWifiControllerTime[i] != null) { |
| 5245 | mWifiControllerTime[i].detach(); |
| 5246 | } |
| 5247 | |
| 5248 | if (mBluetoothControllerTime[i] != null) { |
| 5249 | mBluetoothControllerTime[i].detach(); |
| 5250 | } |
| 5251 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5252 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5253 | |
| 5254 | mUserCpuTime.detach(); |
| 5255 | mSystemCpuTime.detach(); |
| 5256 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5257 | LongSamplingCounter c = mSpeedBins[i]; |
| 5258 | if (c != null) { |
| 5259 | c.detach(); |
| 5260 | } |
| 5261 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5262 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5263 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5264 | return !active; |
| 5265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5266 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5267 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5268 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5269 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5270 | out.writeInt(NW); |
| 5271 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5272 | out.writeString(wakeStats.keyAt(iw)); |
| 5273 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5274 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5275 | } |
| 5276 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5277 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5278 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5279 | out.writeInt(NS); |
| 5280 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5281 | out.writeString(syncStats.keyAt(is)); |
| 5282 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5283 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5284 | } |
| 5285 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5286 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5287 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5288 | out.writeInt(NJ); |
| 5289 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5290 | out.writeString(jobStats.keyAt(ij)); |
| 5291 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5292 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5293 | } |
| 5294 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5295 | int NSE = mSensorStats.size(); |
| 5296 | out.writeInt(NSE); |
| 5297 | for (int ise=0; ise<NSE; ise++) { |
| 5298 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5299 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5300 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | } |
| 5302 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5303 | int NP = mProcessStats.size(); |
| 5304 | out.writeInt(NP); |
| 5305 | for (int ip=0; ip<NP; ip++) { |
| 5306 | out.writeString(mProcessStats.keyAt(ip)); |
| 5307 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5308 | proc.writeToParcelLocked(out); |
| 5309 | } |
| 5310 | |
| 5311 | out.writeInt(mPackageStats.size()); |
| 5312 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5313 | out.writeString(pkgEntry.getKey()); |
| 5314 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5315 | pkg.writeToParcelLocked(out); |
| 5316 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5317 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5318 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5319 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5320 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5321 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5322 | out.writeInt(0); |
| 5323 | } |
| 5324 | if (mFullWifiLockTimer != null) { |
| 5325 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5326 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5327 | } else { |
| 5328 | out.writeInt(0); |
| 5329 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5330 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5331 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5332 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5333 | } else { |
| 5334 | out.writeInt(0); |
| 5335 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5336 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5337 | if (mWifiBatchedScanTimer[i] != null) { |
| 5338 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5339 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5340 | } else { |
| 5341 | out.writeInt(0); |
| 5342 | } |
| 5343 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5344 | if (mWifiMulticastTimer != null) { |
| 5345 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5346 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5347 | } else { |
| 5348 | out.writeInt(0); |
| 5349 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5350 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5351 | if (mAudioTurnedOnTimer != null) { |
| 5352 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5353 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5354 | } else { |
| 5355 | out.writeInt(0); |
| 5356 | } |
| 5357 | if (mVideoTurnedOnTimer != null) { |
| 5358 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5359 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5360 | } else { |
| 5361 | out.writeInt(0); |
| 5362 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5363 | if (mFlashlightTurnedOnTimer != null) { |
| 5364 | out.writeInt(1); |
| 5365 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5366 | } else { |
| 5367 | out.writeInt(0); |
| 5368 | } |
| 5369 | if (mCameraTurnedOnTimer != null) { |
| 5370 | out.writeInt(1); |
| 5371 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5372 | } else { |
| 5373 | out.writeInt(0); |
| 5374 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5375 | if (mForegroundActivityTimer != null) { |
| 5376 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5377 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5378 | } else { |
| 5379 | out.writeInt(0); |
| 5380 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5381 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5382 | if (mProcessStateTimer[i] != null) { |
| 5383 | out.writeInt(1); |
| 5384 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 5385 | } else { |
| 5386 | out.writeInt(0); |
| 5387 | } |
| 5388 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5389 | if (mVibratorOnTimer != null) { |
| 5390 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5391 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5392 | } else { |
| 5393 | out.writeInt(0); |
| 5394 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5395 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5396 | out.writeInt(1); |
| 5397 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5398 | mUserActivityCounters[i].writeToParcel(out); |
| 5399 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5400 | } else { |
| 5401 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5402 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5403 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5404 | out.writeInt(1); |
| 5405 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5406 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 5407 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5408 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5409 | mMobileRadioActiveTime.writeToParcel(out); |
| 5410 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5411 | } else { |
| 5412 | out.writeInt(0); |
| 5413 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5414 | |
| 5415 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5416 | if (mWifiControllerTime[i] != null) { |
| 5417 | out.writeInt(1); |
| 5418 | mWifiControllerTime[i].writeToParcel(out); |
| 5419 | } else { |
| 5420 | out.writeInt(0); |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5425 | if (mBluetoothControllerTime[i] != null) { |
| 5426 | out.writeInt(1); |
| 5427 | mBluetoothControllerTime[i].writeToParcel(out); |
| 5428 | } else { |
| 5429 | out.writeInt(0); |
| 5430 | } |
| 5431 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5432 | |
| 5433 | mUserCpuTime.writeToParcel(out); |
| 5434 | mSystemCpuTime.writeToParcel(out); |
| 5435 | |
| 5436 | out.writeInt(mSpeedBins.length); |
| 5437 | for (int i = 0; i < mSpeedBins.length; i++) { |
| 5438 | LongSamplingCounter c = mSpeedBins[i]; |
| 5439 | if (c != null) { |
| 5440 | out.writeInt(1); |
| 5441 | c.writeToParcel(out); |
| 5442 | } else { |
| 5443 | out.writeInt(0); |
| 5444 | } |
| 5445 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | } |
| 5447 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5448 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5449 | int numWakelocks = in.readInt(); |
| 5450 | mWakelockStats.clear(); |
| 5451 | for (int j = 0; j < numWakelocks; j++) { |
| 5452 | String wakelockName = in.readString(); |
| 5453 | Uid.Wakelock wakelock = new Wakelock(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5454 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5455 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5456 | } |
| 5457 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5458 | int numSyncs = in.readInt(); |
| 5459 | mSyncStats.clear(); |
| 5460 | for (int j = 0; j < numSyncs; j++) { |
| 5461 | String syncName = in.readString(); |
| 5462 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5463 | mSyncStats.add(syncName, |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5464 | new StopwatchTimer(Uid.this, SYNC, null, timeBase, in)); |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | int numJobs = in.readInt(); |
| 5469 | mJobStats.clear(); |
| 5470 | for (int j = 0; j < numJobs; j++) { |
| 5471 | String jobName = in.readString(); |
| 5472 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5473 | mJobStats.add(jobName, new StopwatchTimer(Uid.this, JOB, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5474 | } |
| 5475 | } |
| 5476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | int numSensors = in.readInt(); |
| 5478 | mSensorStats.clear(); |
| 5479 | for (int k = 0; k < numSensors; k++) { |
| 5480 | int sensorNumber = in.readInt(); |
| 5481 | Uid.Sensor sensor = new Sensor(sensorNumber); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5482 | sensor.readFromParcelLocked(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5483 | mSensorStats.put(sensorNumber, sensor); |
| 5484 | } |
| 5485 | |
| 5486 | int numProcs = in.readInt(); |
| 5487 | mProcessStats.clear(); |
| 5488 | for (int k = 0; k < numProcs; k++) { |
| 5489 | String processName = in.readString(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5490 | Uid.Proc proc = new Proc(processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5491 | proc.readFromParcelLocked(in); |
| 5492 | mProcessStats.put(processName, proc); |
| 5493 | } |
| 5494 | |
| 5495 | int numPkgs = in.readInt(); |
| 5496 | mPackageStats.clear(); |
| 5497 | for (int l = 0; l < numPkgs; l++) { |
| 5498 | String packageName = in.readString(); |
| 5499 | Uid.Pkg pkg = new Pkg(); |
| 5500 | pkg.readFromParcelLocked(in); |
| 5501 | mPackageStats.put(packageName, pkg); |
| 5502 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5503 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5504 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5505 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5506 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5507 | mWifiRunningTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5508 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5509 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5510 | } |
| 5511 | mFullWifiLockOut = false; |
| 5512 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5513 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5514 | mFullWifiLockTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5515 | } else { |
| 5516 | mFullWifiLockTimer = null; |
| 5517 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5518 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5519 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5520 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5521 | mWifiScanTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5522 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5523 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5524 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5525 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5526 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5527 | if (in.readInt() != 0) { |
| 5528 | makeWifiBatchedScanBin(i, in); |
| 5529 | } else { |
| 5530 | mWifiBatchedScanTimer[i] = null; |
| 5531 | } |
| 5532 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5533 | mWifiMulticastEnabled = false; |
| 5534 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5535 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5536 | mWifiMulticastTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5537 | } else { |
| 5538 | mWifiMulticastTimer = null; |
| 5539 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5540 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5541 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5542 | mAudioTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5543 | } else { |
| 5544 | mAudioTurnedOnTimer = null; |
| 5545 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5546 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5547 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5548 | mVideoTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5549 | } else { |
| 5550 | mVideoTurnedOnTimer = null; |
| 5551 | } |
| 5552 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5553 | mFlashlightTurnedOnTimer = new StopwatchTimer(Uid.this, FLASHLIGHT_TURNED_ON, |
| 5554 | mFlashlightTurnedOnTimers, mOnBatteryTimeBase, in); |
| 5555 | } else { |
| 5556 | mFlashlightTurnedOnTimer = null; |
| 5557 | } |
| 5558 | if (in.readInt() != 0) { |
| 5559 | mCameraTurnedOnTimer = new StopwatchTimer(Uid.this, CAMERA_TURNED_ON, |
| 5560 | mCameraTurnedOnTimers, mOnBatteryTimeBase, in); |
| 5561 | } else { |
| 5562 | mCameraTurnedOnTimer = null; |
| 5563 | } |
| 5564 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5565 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5566 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5567 | } else { |
| 5568 | mForegroundActivityTimer = null; |
| 5569 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5570 | mProcessState = PROCESS_STATE_NONE; |
| 5571 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5572 | if (in.readInt() != 0) { |
| 5573 | makeProcessState(i, in); |
| 5574 | } else { |
| 5575 | mProcessStateTimer[i] = null; |
| 5576 | } |
| 5577 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5578 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5579 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5580 | } else { |
| 5581 | mVibratorOnTimer = null; |
| 5582 | } |
| 5583 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5584 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5585 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5586 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5587 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5588 | } else { |
| 5589 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5590 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5591 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5592 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5593 | mNetworkPacketActivityCounters |
| 5594 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5595 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5596 | mNetworkByteActivityCounters[i] |
| 5597 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5598 | mNetworkPacketActivityCounters[i] |
| 5599 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5600 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5601 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5602 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5603 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5604 | mNetworkByteActivityCounters = null; |
| 5605 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5606 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5607 | |
| 5608 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5609 | if (in.readInt() != 0) { |
| 5610 | mWifiControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5611 | } else { |
| 5612 | mWifiControllerTime[i] = null; |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5617 | if (in.readInt() != 0) { |
| 5618 | mBluetoothControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5619 | } else { |
| 5620 | mBluetoothControllerTime[i] = null; |
| 5621 | } |
| 5622 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5623 | |
| 5624 | mUserCpuTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5625 | mSystemCpuTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5626 | |
| 5627 | int bins = in.readInt(); |
| 5628 | int steps = getCpuSpeedSteps(); |
| 5629 | mSpeedBins = new LongSamplingCounter[bins >= steps ? bins : steps]; |
| 5630 | for (int i = 0; i < bins; i++) { |
| 5631 | if (in.readInt() != 0) { |
| 5632 | mSpeedBins[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5633 | } |
| 5634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * The statistics associated with a particular wake lock. |
| 5639 | */ |
| 5640 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 5641 | /** |
| 5642 | * How long (in ms) this uid has been keeping the device partially awake. |
| 5643 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5644 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | |
| 5646 | /** |
| 5647 | * How long (in ms) this uid has been keeping the device fully awake. |
| 5648 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5649 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | |
| 5651 | /** |
| 5652 | * How long (in ms) this uid has had a window keeping the device awake. |
| 5653 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5654 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5655 | |
| 5656 | /** |
| 5657 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 5658 | * proper timer pool from the given BatteryStatsImpl object. |
| 5659 | * |
| 5660 | * @param in the Parcel to be read from. |
| 5661 | * return a new Timer, or null. |
| 5662 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5663 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5664 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | if (in.readInt() == 0) { |
| 5666 | return null; |
| 5667 | } |
| 5668 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5669 | return new StopwatchTimer(Uid.this, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | } |
| 5671 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5672 | boolean reset() { |
| 5673 | boolean wlactive = false; |
| 5674 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5675 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5676 | } |
| 5677 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5678 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5679 | } |
| 5680 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5681 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5682 | } |
| 5683 | if (!wlactive) { |
| 5684 | if (mTimerFull != null) { |
| 5685 | mTimerFull.detach(); |
| 5686 | mTimerFull = null; |
| 5687 | } |
| 5688 | if (mTimerPartial != null) { |
| 5689 | mTimerPartial.detach(); |
| 5690 | mTimerPartial = null; |
| 5691 | } |
| 5692 | if (mTimerWindow != null) { |
| 5693 | mTimerWindow.detach(); |
| 5694 | mTimerWindow = null; |
| 5695 | } |
| 5696 | } |
| 5697 | return !wlactive; |
| 5698 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5699 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5700 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5701 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5702 | mPartialTimers, screenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5703 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5704 | mFullTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5705 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5706 | mWindowTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5707 | } |
| 5708 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5709 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5710 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 5711 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 5712 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | @Override |
| 5716 | public Timer getWakeTime(int type) { |
| 5717 | switch (type) { |
| 5718 | case WAKE_TYPE_FULL: return mTimerFull; |
| 5719 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 5720 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
| 5721 | default: throw new IllegalArgumentException("type = " + type); |
| 5722 | } |
| 5723 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5724 | |
| 5725 | public StopwatchTimer getStopwatchTimer(int type) { |
| 5726 | StopwatchTimer t; |
| 5727 | switch (type) { |
| 5728 | case WAKE_TYPE_PARTIAL: |
| 5729 | t = mTimerPartial; |
| 5730 | if (t == null) { |
| 5731 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
| 5732 | mPartialTimers, mOnBatteryScreenOffTimeBase); |
| 5733 | mTimerPartial = t; |
| 5734 | } |
| 5735 | return t; |
| 5736 | case WAKE_TYPE_FULL: |
| 5737 | t = mTimerFull; |
| 5738 | if (t == null) { |
| 5739 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
| 5740 | mFullTimers, mOnBatteryTimeBase); |
| 5741 | mTimerFull = t; |
| 5742 | } |
| 5743 | return t; |
| 5744 | case WAKE_TYPE_WINDOW: |
| 5745 | t = mTimerWindow; |
| 5746 | if (t == null) { |
| 5747 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
| 5748 | mWindowTimers, mOnBatteryTimeBase); |
| 5749 | mTimerWindow = t; |
| 5750 | } |
| 5751 | return t; |
| 5752 | default: |
| 5753 | throw new IllegalArgumentException("type=" + type); |
| 5754 | } |
| 5755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5756 | } |
| 5757 | |
| 5758 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 5759 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5760 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5762 | public Sensor(int handle) { |
| 5763 | mHandle = handle; |
| 5764 | } |
| 5765 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5766 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | if (in.readInt() == 0) { |
| 5768 | return null; |
| 5769 | } |
| 5770 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5771 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5772 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5773 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5774 | mSensorTimers.put(mHandle, pool); |
| 5775 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5776 | return new StopwatchTimer(Uid.this, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | } |
| 5778 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5779 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5780 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5781 | mTimer = null; |
| 5782 | return true; |
| 5783 | } |
| 5784 | return false; |
| 5785 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5786 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5787 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 5788 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5791 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5792 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | @Override |
| 5796 | public Timer getSensorTime() { |
| 5797 | return mTimer; |
| 5798 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5799 | |
| 5800 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | public int getHandle() { |
| 5802 | return mHandle; |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | /** |
| 5807 | * The statistics associated with a particular process. |
| 5808 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5809 | 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] | 5810 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5811 | * The name of this process. |
| 5812 | */ |
| 5813 | final String mName; |
| 5814 | |
| 5815 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5816 | * Remains true until removed from the stats. |
| 5817 | */ |
| 5818 | boolean mActive = true; |
| 5819 | |
| 5820 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5821 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | */ |
| 5823 | long mUserTime; |
| 5824 | |
| 5825 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5826 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5827 | */ |
| 5828 | long mSystemTime; |
| 5829 | |
| 5830 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5831 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5832 | */ |
| 5833 | long mForegroundTime; |
| 5834 | |
| 5835 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5836 | * Number of times the process has been started. |
| 5837 | */ |
| 5838 | int mStarts; |
| 5839 | |
| 5840 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5841 | * Number of times the process has crashed. |
| 5842 | */ |
| 5843 | int mNumCrashes; |
| 5844 | |
| 5845 | /** |
| 5846 | * Number of times the process has had an ANR. |
| 5847 | */ |
| 5848 | int mNumAnrs; |
| 5849 | |
| 5850 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | * The amount of user time loaded from a previous save. |
| 5852 | */ |
| 5853 | long mLoadedUserTime; |
| 5854 | |
| 5855 | /** |
| 5856 | * The amount of system time loaded from a previous save. |
| 5857 | */ |
| 5858 | long mLoadedSystemTime; |
| 5859 | |
| 5860 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5861 | * The amount of foreground time loaded from a previous save. |
| 5862 | */ |
| 5863 | long mLoadedForegroundTime; |
| 5864 | |
| 5865 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5866 | * The number of times the process has started from a previous save. |
| 5867 | */ |
| 5868 | int mLoadedStarts; |
| 5869 | |
| 5870 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5871 | * 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] | 5872 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5873 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | |
| 5875 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5876 | * 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] | 5877 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5878 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5879 | |
| 5880 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5881 | * The amount of user time when last unplugged. |
| 5882 | */ |
| 5883 | long mUnpluggedUserTime; |
| 5884 | |
| 5885 | /** |
| 5886 | * The amount of system time when last unplugged. |
| 5887 | */ |
| 5888 | long mUnpluggedSystemTime; |
| 5889 | |
| 5890 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5891 | * The amount of foreground time since unplugged. |
| 5892 | */ |
| 5893 | long mUnpluggedForegroundTime; |
| 5894 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5895 | /** |
| 5896 | * The number of times the process has started before unplugged. |
| 5897 | */ |
| 5898 | int mUnpluggedStarts; |
| 5899 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5900 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5901 | * Number of times the process has crashed before unplugged. |
| 5902 | */ |
| 5903 | int mUnpluggedNumCrashes; |
| 5904 | |
| 5905 | /** |
| 5906 | * Number of times the process has had an ANR before unplugged. |
| 5907 | */ |
| 5908 | int mUnpluggedNumAnrs; |
| 5909 | |
| 5910 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5911 | * Current process state. |
| 5912 | */ |
| 5913 | int mProcessState = PROCESS_STATE_NONE; |
| 5914 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5915 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5916 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5917 | Proc(String name) { |
| 5918 | mName = name; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5919 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5920 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 5921 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5922 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5923 | mUnpluggedUserTime = mUserTime; |
| 5924 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5925 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5926 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5927 | mUnpluggedNumCrashes = mNumCrashes; |
| 5928 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | } |
| 5930 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5931 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5933 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5934 | void reset() { |
| 5935 | mUserTime = mSystemTime = mForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5936 | mStarts = mNumCrashes = mNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5937 | mLoadedUserTime = mLoadedSystemTime = mLoadedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5938 | mLoadedStarts = mLoadedNumCrashes = mLoadedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5939 | mUnpluggedUserTime = mUnpluggedSystemTime = mUnpluggedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5940 | mUnpluggedStarts = mUnpluggedNumCrashes = mUnpluggedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5941 | mExcessivePower = null; |
| 5942 | } |
| 5943 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5944 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5945 | mActive = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5946 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5947 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5948 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5949 | public int countExcessivePowers() { |
| 5950 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5953 | public ExcessivePower getExcessivePower(int i) { |
| 5954 | if (mExcessivePower != null) { |
| 5955 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5956 | } |
| 5957 | return null; |
| 5958 | } |
| 5959 | |
| 5960 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5961 | if (mExcessivePower == null) { |
| 5962 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5963 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5964 | ExcessivePower ew = new ExcessivePower(); |
| 5965 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5966 | ew.overTime = overTime; |
| 5967 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5968 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5971 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 5972 | if (mExcessivePower == null) { |
| 5973 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 5974 | } |
| 5975 | ExcessivePower ew = new ExcessivePower(); |
| 5976 | ew.type = ExcessivePower.TYPE_CPU; |
| 5977 | ew.overTime = overTime; |
| 5978 | ew.usedTime = usedTime; |
| 5979 | mExcessivePower.add(ew); |
| 5980 | } |
| 5981 | |
| 5982 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 5983 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5984 | out.writeInt(0); |
| 5985 | return; |
| 5986 | } |
| 5987 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5988 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5989 | out.writeInt(N); |
| 5990 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5991 | ExcessivePower ew = mExcessivePower.get(i); |
| 5992 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5993 | out.writeLong(ew.overTime); |
| 5994 | out.writeLong(ew.usedTime); |
| 5995 | } |
| 5996 | } |
| 5997 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 5998 | boolean readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5999 | final int N = in.readInt(); |
| 6000 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6001 | mExcessivePower = null; |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6002 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6003 | } |
| 6004 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6005 | if (N > 10000) { |
| 6006 | Slog.w(TAG, "File corrupt: too many excessive power entries " + N); |
| 6007 | return false; |
| 6008 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6009 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6010 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6011 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6012 | ExcessivePower ew = new ExcessivePower(); |
| 6013 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6014 | ew.overTime = in.readLong(); |
| 6015 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6016 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6017 | } |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6018 | return true; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6019 | } |
| 6020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6021 | void writeToParcelLocked(Parcel out) { |
| 6022 | out.writeLong(mUserTime); |
| 6023 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6024 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6025 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6026 | out.writeInt(mNumCrashes); |
| 6027 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | out.writeLong(mLoadedUserTime); |
| 6029 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6030 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6031 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6032 | out.writeInt(mLoadedNumCrashes); |
| 6033 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6034 | out.writeLong(mUnpluggedUserTime); |
| 6035 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6036 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6038 | out.writeInt(mUnpluggedNumCrashes); |
| 6039 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6040 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | void readFromParcelLocked(Parcel in) { |
| 6044 | mUserTime = in.readLong(); |
| 6045 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6046 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6047 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6048 | mNumCrashes = in.readInt(); |
| 6049 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | mLoadedUserTime = in.readLong(); |
| 6051 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6052 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6053 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6054 | mLoadedNumCrashes = in.readInt(); |
| 6055 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | mUnpluggedUserTime = in.readLong(); |
| 6057 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6058 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6060 | mUnpluggedNumCrashes = in.readInt(); |
| 6061 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6062 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6063 | } |
| 6064 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6065 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | mUserTime += utime; |
| 6067 | mSystemTime += stime; |
| 6068 | } |
| 6069 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6070 | public void addForegroundTimeLocked(long ttime) { |
| 6071 | mForegroundTime += ttime; |
| 6072 | } |
| 6073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | public void incStartsLocked() { |
| 6075 | mStarts++; |
| 6076 | } |
| 6077 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6078 | public void incNumCrashesLocked() { |
| 6079 | mNumCrashes++; |
| 6080 | } |
| 6081 | |
| 6082 | public void incNumAnrsLocked() { |
| 6083 | mNumAnrs++; |
| 6084 | } |
| 6085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6086 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6087 | public boolean isActive() { |
| 6088 | return mActive; |
| 6089 | } |
| 6090 | |
| 6091 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6093 | long val = mUserTime; |
| 6094 | if (which == STATS_CURRENT) { |
| 6095 | val -= mLoadedUserTime; |
| 6096 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6097 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | } |
| 6099 | return val; |
| 6100 | } |
| 6101 | |
| 6102 | @Override |
| 6103 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6104 | long val = mSystemTime; |
| 6105 | if (which == STATS_CURRENT) { |
| 6106 | val -= mLoadedSystemTime; |
| 6107 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6108 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6109 | } |
| 6110 | return val; |
| 6111 | } |
| 6112 | |
| 6113 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6114 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6115 | long val = mForegroundTime; |
| 6116 | if (which == STATS_CURRENT) { |
| 6117 | val -= mLoadedForegroundTime; |
| 6118 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6119 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6120 | } |
| 6121 | return val; |
| 6122 | } |
| 6123 | |
| 6124 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6125 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6126 | int val = mStarts; |
| 6127 | if (which == STATS_CURRENT) { |
| 6128 | val -= mLoadedStarts; |
| 6129 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6130 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6131 | } |
| 6132 | return val; |
| 6133 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6134 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6135 | @Override |
| 6136 | public int getNumCrashes(int which) { |
| 6137 | int val = mNumCrashes; |
| 6138 | if (which == STATS_CURRENT) { |
| 6139 | val -= mLoadedNumCrashes; |
| 6140 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6141 | val -= mUnpluggedNumCrashes; |
| 6142 | } |
| 6143 | return val; |
| 6144 | } |
| 6145 | |
| 6146 | @Override |
| 6147 | public int getNumAnrs(int which) { |
| 6148 | int val = mNumAnrs; |
| 6149 | if (which == STATS_CURRENT) { |
| 6150 | val -= mLoadedNumAnrs; |
| 6151 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6152 | val -= mUnpluggedNumAnrs; |
| 6153 | } |
| 6154 | return val; |
| 6155 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | /** |
| 6159 | * The statistics associated with a particular package. |
| 6160 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6161 | 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] | 6162 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6163 | * 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] | 6164 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6165 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | |
| 6167 | /** |
| 6168 | * The statics we have collected for this package's services. |
| 6169 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6170 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6171 | |
| 6172 | Pkg() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6173 | mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6174 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6175 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6176 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6177 | } |
| 6178 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6179 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6181 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6182 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6183 | mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6184 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6187 | int numWA = in.readInt(); |
| 6188 | mWakeupAlarms.clear(); |
| 6189 | for (int i=0; i<numWA; i++) { |
| 6190 | String tag = in.readString(); |
| 6191 | mWakeupAlarms.put(tag, new Counter(mOnBatteryTimeBase, in)); |
| 6192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6193 | |
| 6194 | int numServs = in.readInt(); |
| 6195 | mServiceStats.clear(); |
| 6196 | for (int m = 0; m < numServs; m++) { |
| 6197 | String serviceName = in.readString(); |
| 6198 | Uid.Pkg.Serv serv = new Serv(); |
| 6199 | mServiceStats.put(serviceName, serv); |
| 6200 | |
| 6201 | serv.readFromParcelLocked(in); |
| 6202 | } |
| 6203 | } |
| 6204 | |
| 6205 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6206 | int numWA = mWakeupAlarms.size(); |
| 6207 | out.writeInt(numWA); |
| 6208 | for (int i=0; i<numWA; i++) { |
| 6209 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6210 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6211 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6212 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6213 | final int NS = mServiceStats.size(); |
| 6214 | out.writeInt(NS); |
| 6215 | for (int i=0; i<NS; i++) { |
| 6216 | out.writeString(mServiceStats.keyAt(i)); |
| 6217 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6218 | serv.writeToParcelLocked(out); |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6223 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6224 | return mWakeupAlarms; |
| 6225 | } |
| 6226 | |
| 6227 | public void noteWakeupAlarmLocked(String tag) { |
| 6228 | Counter c = mWakeupAlarms.get(tag); |
| 6229 | if (c == null) { |
| 6230 | c = new Counter(mOnBatteryTimeBase); |
| 6231 | mWakeupAlarms.put(tag, c); |
| 6232 | } |
| 6233 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6237 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6238 | return mServiceStats; |
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 service. |
| 6243 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6244 | 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] | 6245 | /** |
| 6246 | * Total time (ms in battery uptime) the service has been left started. |
| 6247 | */ |
| 6248 | long mStartTime; |
| 6249 | |
| 6250 | /** |
| 6251 | * If service has been started and not yet stopped, this is |
| 6252 | * when it was started. |
| 6253 | */ |
| 6254 | long mRunningSince; |
| 6255 | |
| 6256 | /** |
| 6257 | * True if we are currently running. |
| 6258 | */ |
| 6259 | boolean mRunning; |
| 6260 | |
| 6261 | /** |
| 6262 | * Total number of times startService() has been called. |
| 6263 | */ |
| 6264 | int mStarts; |
| 6265 | |
| 6266 | /** |
| 6267 | * Total time (ms in battery uptime) the service has been left launched. |
| 6268 | */ |
| 6269 | long mLaunchedTime; |
| 6270 | |
| 6271 | /** |
| 6272 | * If service has been launched and not yet exited, this is |
| 6273 | * when it was launched (ms in battery uptime). |
| 6274 | */ |
| 6275 | long mLaunchedSince; |
| 6276 | |
| 6277 | /** |
| 6278 | * True if we are currently launched. |
| 6279 | */ |
| 6280 | boolean mLaunched; |
| 6281 | |
| 6282 | /** |
| 6283 | * Total number times the service has been launched. |
| 6284 | */ |
| 6285 | int mLaunches; |
| 6286 | |
| 6287 | /** |
| 6288 | * The amount of time spent started loaded from a previous save |
| 6289 | * (ms in battery uptime). |
| 6290 | */ |
| 6291 | long mLoadedStartTime; |
| 6292 | |
| 6293 | /** |
| 6294 | * The number of starts loaded from a previous save. |
| 6295 | */ |
| 6296 | int mLoadedStarts; |
| 6297 | |
| 6298 | /** |
| 6299 | * The number of launches loaded from a previous save. |
| 6300 | */ |
| 6301 | int mLoadedLaunches; |
| 6302 | |
| 6303 | /** |
| 6304 | * The amount of time spent started as of the last run (ms |
| 6305 | * in battery uptime). |
| 6306 | */ |
| 6307 | long mLastStartTime; |
| 6308 | |
| 6309 | /** |
| 6310 | * The number of starts as of the last run. |
| 6311 | */ |
| 6312 | int mLastStarts; |
| 6313 | |
| 6314 | /** |
| 6315 | * The number of launches as of the last run. |
| 6316 | */ |
| 6317 | int mLastLaunches; |
| 6318 | |
| 6319 | /** |
| 6320 | * The amount of time spent started when last unplugged (ms |
| 6321 | * in battery uptime). |
| 6322 | */ |
| 6323 | long mUnpluggedStartTime; |
| 6324 | |
| 6325 | /** |
| 6326 | * The number of starts when last unplugged. |
| 6327 | */ |
| 6328 | int mUnpluggedStarts; |
| 6329 | |
| 6330 | /** |
| 6331 | * The number of launches when last unplugged. |
| 6332 | */ |
| 6333 | int mUnpluggedLaunches; |
| 6334 | |
| 6335 | Serv() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6336 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6338 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6339 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 6340 | long baseRealtime) { |
| 6341 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6342 | mUnpluggedStarts = mStarts; |
| 6343 | mUnpluggedLaunches = mLaunches; |
| 6344 | } |
| 6345 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6346 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 6347 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6348 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6349 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6350 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6351 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6352 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | void readFromParcelLocked(Parcel in) { |
| 6355 | mStartTime = in.readLong(); |
| 6356 | mRunningSince = in.readLong(); |
| 6357 | mRunning = in.readInt() != 0; |
| 6358 | mStarts = in.readInt(); |
| 6359 | mLaunchedTime = in.readLong(); |
| 6360 | mLaunchedSince = in.readLong(); |
| 6361 | mLaunched = in.readInt() != 0; |
| 6362 | mLaunches = in.readInt(); |
| 6363 | mLoadedStartTime = in.readLong(); |
| 6364 | mLoadedStarts = in.readInt(); |
| 6365 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6366 | mLastStartTime = 0; |
| 6367 | mLastStarts = 0; |
| 6368 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6369 | mUnpluggedStartTime = in.readLong(); |
| 6370 | mUnpluggedStarts = in.readInt(); |
| 6371 | mUnpluggedLaunches = in.readInt(); |
| 6372 | } |
| 6373 | |
| 6374 | void writeToParcelLocked(Parcel out) { |
| 6375 | out.writeLong(mStartTime); |
| 6376 | out.writeLong(mRunningSince); |
| 6377 | out.writeInt(mRunning ? 1 : 0); |
| 6378 | out.writeInt(mStarts); |
| 6379 | out.writeLong(mLaunchedTime); |
| 6380 | out.writeLong(mLaunchedSince); |
| 6381 | out.writeInt(mLaunched ? 1 : 0); |
| 6382 | out.writeInt(mLaunches); |
| 6383 | out.writeLong(mLoadedStartTime); |
| 6384 | out.writeInt(mLoadedStarts); |
| 6385 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | out.writeLong(mUnpluggedStartTime); |
| 6387 | out.writeInt(mUnpluggedStarts); |
| 6388 | out.writeInt(mUnpluggedLaunches); |
| 6389 | } |
| 6390 | |
| 6391 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 6392 | if (!mLaunched) return mLaunchedTime; |
| 6393 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 6394 | } |
| 6395 | |
| 6396 | long getStartTimeToNowLocked(long batteryUptime) { |
| 6397 | if (!mRunning) return mStartTime; |
| 6398 | return mStartTime + batteryUptime - mRunningSince; |
| 6399 | } |
| 6400 | |
| 6401 | public void startLaunchedLocked() { |
| 6402 | if (!mLaunched) { |
| 6403 | mLaunches++; |
| 6404 | mLaunchedSince = getBatteryUptimeLocked(); |
| 6405 | mLaunched = true; |
| 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | public void stopLaunchedLocked() { |
| 6410 | if (mLaunched) { |
| 6411 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 6412 | if (time > 0) { |
| 6413 | mLaunchedTime += time; |
| 6414 | } else { |
| 6415 | mLaunches--; |
| 6416 | } |
| 6417 | mLaunched = false; |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | public void startRunningLocked() { |
| 6422 | if (!mRunning) { |
| 6423 | mStarts++; |
| 6424 | mRunningSince = getBatteryUptimeLocked(); |
| 6425 | mRunning = true; |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | public void stopRunningLocked() { |
| 6430 | if (mRunning) { |
| 6431 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 6432 | if (time > 0) { |
| 6433 | mStartTime += time; |
| 6434 | } else { |
| 6435 | mStarts--; |
| 6436 | } |
| 6437 | mRunning = false; |
| 6438 | } |
| 6439 | } |
| 6440 | |
| 6441 | public BatteryStatsImpl getBatteryStats() { |
| 6442 | return BatteryStatsImpl.this; |
| 6443 | } |
| 6444 | |
| 6445 | @Override |
| 6446 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6447 | int val = mLaunches; |
| 6448 | if (which == STATS_CURRENT) { |
| 6449 | val -= mLoadedLaunches; |
| 6450 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6451 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | return val; |
| 6454 | } |
| 6455 | |
| 6456 | @Override |
| 6457 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6458 | long val = getStartTimeToNowLocked(now); |
| 6459 | if (which == STATS_CURRENT) { |
| 6460 | val -= mLoadedStartTime; |
| 6461 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6462 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6463 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | return val; |
| 6465 | } |
| 6466 | |
| 6467 | @Override |
| 6468 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6469 | int val = mStarts; |
| 6470 | if (which == STATS_CURRENT) { |
| 6471 | val -= mLoadedStarts; |
| 6472 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6473 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | } |
| 6475 | |
| 6476 | return val; |
| 6477 | } |
| 6478 | } |
| 6479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | final Serv newServiceStatsLocked() { |
| 6481 | return new Serv(); |
| 6482 | } |
| 6483 | } |
| 6484 | |
| 6485 | /** |
| 6486 | * Retrieve the statistics object for a particular process, creating |
| 6487 | * if needed. |
| 6488 | */ |
| 6489 | public Proc getProcessStatsLocked(String name) { |
| 6490 | Proc ps = mProcessStats.get(name); |
| 6491 | if (ps == null) { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6492 | ps = new Proc(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | mProcessStats.put(name, ps); |
| 6494 | } |
| 6495 | |
| 6496 | return ps; |
| 6497 | } |
| 6498 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6499 | public void updateProcessStateLocked(String procName, int state, long elapsedRealtimeMs) { |
| 6500 | int procState; |
| 6501 | if (state <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 6502 | procState = PROCESS_STATE_FOREGROUND; |
| 6503 | } else if (state <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 6504 | procState = PROCESS_STATE_ACTIVE; |
| 6505 | } else { |
| 6506 | procState = PROCESS_STATE_RUNNING; |
| 6507 | } |
| 6508 | updateRealProcessStateLocked(procName, procState, elapsedRealtimeMs); |
| 6509 | } |
| 6510 | |
| 6511 | public void updateRealProcessStateLocked(String procName, int procState, |
| 6512 | long elapsedRealtimeMs) { |
| 6513 | Proc proc = getProcessStatsLocked(procName); |
| 6514 | if (proc.mProcessState != procState) { |
| 6515 | boolean changed; |
| 6516 | if (procState < proc.mProcessState) { |
| 6517 | // Has this process become more important? If so, |
| 6518 | // we may need to change the uid if the currrent uid proc state |
| 6519 | // is not as important as what we are now setting. |
| 6520 | changed = mProcessState > procState; |
| 6521 | } else { |
| 6522 | // Has this process become less important? If so, |
| 6523 | // we may need to change the uid if the current uid proc state |
| 6524 | // is the same importance as the old setting. |
| 6525 | changed = mProcessState == proc.mProcessState; |
| 6526 | } |
| 6527 | proc.mProcessState = procState; |
| 6528 | if (changed) { |
| 6529 | // uid's state may have changed; compute what the new state should be. |
| 6530 | int uidProcState = PROCESS_STATE_NONE; |
| 6531 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6532 | proc = mProcessStats.valueAt(ip); |
| 6533 | if (proc.mProcessState < uidProcState) { |
| 6534 | uidProcState = proc.mProcessState; |
| 6535 | } |
| 6536 | } |
| 6537 | updateUidProcessStateLocked(uidProcState, elapsedRealtimeMs); |
| 6538 | } |
| 6539 | } |
| 6540 | } |
| 6541 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6542 | public SparseArray<? extends Pid> getPidStats() { |
| 6543 | return mPids; |
| 6544 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6545 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6546 | public Pid getPidStatsLocked(int pid) { |
| 6547 | Pid p = mPids.get(pid); |
| 6548 | if (p == null) { |
| 6549 | p = new Pid(); |
| 6550 | mPids.put(pid, p); |
| 6551 | } |
| 6552 | return p; |
| 6553 | } |
| 6554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | /** |
| 6556 | * Retrieve the statistics object for a particular service, creating |
| 6557 | * if needed. |
| 6558 | */ |
| 6559 | public Pkg getPackageStatsLocked(String name) { |
| 6560 | Pkg ps = mPackageStats.get(name); |
| 6561 | if (ps == null) { |
| 6562 | ps = new Pkg(); |
| 6563 | mPackageStats.put(name, ps); |
| 6564 | } |
| 6565 | |
| 6566 | return ps; |
| 6567 | } |
| 6568 | |
| 6569 | /** |
| 6570 | * Retrieve the statistics object for a particular service, creating |
| 6571 | * if needed. |
| 6572 | */ |
| 6573 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 6574 | Pkg ps = getPackageStatsLocked(pkg); |
| 6575 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 6576 | if (ss == null) { |
| 6577 | ss = ps.newServiceStatsLocked(); |
| 6578 | ps.mServiceStats.put(serv, ss); |
| 6579 | } |
| 6580 | |
| 6581 | return ss; |
| 6582 | } |
| 6583 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6584 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 6585 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 6586 | timer.readSummaryFromParcelLocked(in); |
| 6587 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6588 | } |
| 6589 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6590 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 6591 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 6592 | timer.readSummaryFromParcelLocked(in); |
| 6593 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6594 | } |
| 6595 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6596 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
| 6597 | Wakelock wl = new Wakelock(); |
| 6598 | mWakelockStats.add(wlName, wl); |
| 6599 | if (in.readInt() != 0) { |
| 6600 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6602 | if (in.readInt() != 0) { |
| 6603 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 6604 | } |
| 6605 | if (in.readInt() != 0) { |
| 6606 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6607 | } |
| 6608 | } |
| 6609 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6610 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6611 | Sensor se = mSensorStats.get(sensor); |
| 6612 | if (se == null) { |
| 6613 | if (!create) { |
| 6614 | return null; |
| 6615 | } |
| 6616 | se = new Sensor(sensor); |
| 6617 | mSensorStats.put(sensor, se); |
| 6618 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6619 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | if (t != null) { |
| 6621 | return t; |
| 6622 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6623 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6625 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6626 | mSensorTimers.put(sensor, timers); |
| 6627 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6628 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | se.mTimer = t; |
| 6630 | return t; |
| 6631 | } |
| 6632 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6633 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6634 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6635 | if (t != null) { |
| 6636 | t.startRunningLocked(elapsedRealtimeMs); |
| 6637 | } |
| 6638 | } |
| 6639 | |
| 6640 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6641 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6642 | if (t != null) { |
| 6643 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 6648 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6649 | if (t != null) { |
| 6650 | t.startRunningLocked(elapsedRealtimeMs); |
| 6651 | } |
| 6652 | } |
| 6653 | |
| 6654 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6655 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6656 | if (t != null) { |
| 6657 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6658 | } |
| 6659 | } |
| 6660 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6661 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6662 | Wakelock wl = mWakelockStats.startObject(name); |
| 6663 | if (wl != null) { |
| 6664 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6666 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6667 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6668 | if (p.mWakeNesting++ == 0) { |
| 6669 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 6670 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6671 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | } |
| 6673 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6674 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6675 | Wakelock wl = mWakelockStats.stopObject(name); |
| 6676 | if (wl != null) { |
| 6677 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6678 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6679 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6680 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6681 | if (p != null && p.mWakeNesting > 0) { |
| 6682 | if (p.mWakeNesting-- == 1) { |
| 6683 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 6684 | p.mWakeStartMs = 0; |
| 6685 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6686 | } |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 6691 | Proc p = getProcessStatsLocked(proc); |
| 6692 | if (p != null) { |
| 6693 | p.addExcessiveWake(overTime, usedTime); |
| 6694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6695 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6696 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6697 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 6698 | Proc p = getProcessStatsLocked(proc); |
| 6699 | if (p != null) { |
| 6700 | p.addExcessiveCpu(overTime, usedTime); |
| 6701 | } |
| 6702 | } |
| 6703 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6704 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6705 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6707 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | } |
| 6710 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6711 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6713 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6714 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6715 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6716 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6718 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6719 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6720 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6721 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6722 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6723 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6724 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6725 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6726 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6727 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6728 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6729 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6730 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | public BatteryStatsImpl getBatteryStats() { |
| 6734 | return BatteryStatsImpl.this; |
| 6735 | } |
| 6736 | } |
| 6737 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6738 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6739 | if (systemDir != null) { |
| 6740 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 6741 | new File(systemDir, "batterystats.bin.tmp")); |
| 6742 | } else { |
| 6743 | mFile = null; |
| 6744 | } |
| 6745 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6746 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6747 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 6748 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | mStartCount++; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6750 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6751 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6752 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6753 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6754 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase); |
| 6755 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase); |
| 6756 | mDeviceIdleModeEnabledTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6757 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6758 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6759 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6760 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, |
| 6761 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6762 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6763 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6764 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6765 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, |
| 6766 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6767 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6768 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6769 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6770 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6771 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6772 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 6773 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6774 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6775 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6776 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); |
| 6777 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6778 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6779 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6780 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6781 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase); |
| 6782 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6783 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6784 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6785 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6786 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 6787 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, null, mOnBatteryTimeBase); |
| 6788 | } |
| 6789 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 6790 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, null, |
| 6791 | mOnBatteryTimeBase); |
| 6792 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6793 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
| 6794 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6795 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6796 | mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6798 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 6799 | long realtime = SystemClock.elapsedRealtime() * 1000; |
| 6800 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6801 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6802 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6803 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6804 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6805 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6806 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6807 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6808 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6809 | updateDailyDeadlineLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6813 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6814 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6815 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6816 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6817 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6818 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6819 | readFromParcel(p); |
| 6820 | } |
| 6821 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6822 | public void setPowerProfile(PowerProfile profile) { |
| 6823 | synchronized (this) { |
| 6824 | mPowerProfile = profile; |
| 6825 | } |
| 6826 | } |
| 6827 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6828 | public void setCallback(BatteryCallback cb) { |
| 6829 | mCallback = cb; |
| 6830 | } |
| 6831 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6832 | public void setNumSpeedSteps(int steps) { |
| 6833 | if (sNumSpeedSteps == 0) sNumSpeedSteps = steps; |
| 6834 | } |
| 6835 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6836 | public void setRadioScanningTimeout(long timeout) { |
| 6837 | if (mPhoneSignalScanningTimer != null) { |
| 6838 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 6839 | } |
| 6840 | } |
| 6841 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6842 | public void updateDailyDeadlineLocked() { |
| 6843 | // Get the current time. |
| 6844 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 6845 | Calendar calDeadline = Calendar.getInstance(); |
| 6846 | calDeadline.setTimeInMillis(currentTime); |
| 6847 | |
| 6848 | // Move time up to the next day, ranging from 1am to 3pm. |
| 6849 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 6850 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 6851 | calDeadline.set(Calendar.SECOND, 0); |
| 6852 | calDeadline.set(Calendar.MINUTE, 0); |
| 6853 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 6854 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 6855 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 6856 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 6857 | } |
| 6858 | |
| 6859 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 6860 | long currentTime = System.currentTimeMillis(); |
| 6861 | if (currentTime >= mNextMaxDailyDeadline) { |
| 6862 | recordDailyStatsLocked(); |
| 6863 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 6864 | recordDailyStatsLocked(); |
| 6865 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 6866 | recordDailyStatsLocked(); |
| 6867 | } |
| 6868 | } |
| 6869 | |
| 6870 | public void recordDailyStatsLocked() { |
| 6871 | DailyItem item = new DailyItem(); |
| 6872 | item.mStartTime = mDailyStartTime; |
| 6873 | item.mEndTime = System.currentTimeMillis(); |
| 6874 | boolean hasData = false; |
| 6875 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 6876 | hasData = true; |
| 6877 | item.mDischargeSteps = new LevelStepTracker( |
| 6878 | mDailyDischargeStepTracker.mNumStepDurations, |
| 6879 | mDailyDischargeStepTracker.mStepDurations); |
| 6880 | } |
| 6881 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 6882 | hasData = true; |
| 6883 | item.mChargeSteps = new LevelStepTracker( |
| 6884 | mDailyChargeStepTracker.mNumStepDurations, |
| 6885 | mDailyChargeStepTracker.mStepDurations); |
| 6886 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6887 | if (mDailyPackageChanges != null) { |
| 6888 | hasData = true; |
| 6889 | item.mPackageChanges = mDailyPackageChanges; |
| 6890 | mDailyPackageChanges = null; |
| 6891 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6892 | mDailyDischargeStepTracker.init(); |
| 6893 | mDailyChargeStepTracker.init(); |
| 6894 | updateDailyDeadlineLocked(); |
| 6895 | |
| 6896 | if (hasData) { |
| 6897 | mDailyItems.add(item); |
| 6898 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 6899 | mDailyItems.remove(0); |
| 6900 | } |
| 6901 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 6902 | try { |
| 6903 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 6904 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6905 | writeDailyItemsLocked(out); |
| 6906 | BackgroundThread.getHandler().post(new Runnable() { |
| 6907 | @Override |
| 6908 | public void run() { |
| 6909 | synchronized (mCheckinFile) { |
| 6910 | FileOutputStream stream = null; |
| 6911 | try { |
| 6912 | stream = mDailyFile.startWrite(); |
| 6913 | memStream.writeTo(stream); |
| 6914 | stream.flush(); |
| 6915 | FileUtils.sync(stream); |
| 6916 | stream.close(); |
| 6917 | mDailyFile.finishWrite(stream); |
| 6918 | } catch (IOException e) { |
| 6919 | Slog.w("BatteryStats", |
| 6920 | "Error writing battery daily items", e); |
| 6921 | mDailyFile.failWrite(stream); |
| 6922 | } |
| 6923 | } |
| 6924 | } |
| 6925 | }); |
| 6926 | } catch (IOException e) { |
| 6927 | } |
| 6928 | } |
| 6929 | } |
| 6930 | |
| 6931 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 6932 | StringBuilder sb = new StringBuilder(64); |
| 6933 | out.startDocument(null, true); |
| 6934 | out.startTag(null, "daily-items"); |
| 6935 | for (int i=0; i<mDailyItems.size(); i++) { |
| 6936 | final DailyItem dit = mDailyItems.get(i); |
| 6937 | out.startTag(null, "item"); |
| 6938 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 6939 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 6940 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 6941 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6942 | if (dit.mPackageChanges != null) { |
| 6943 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 6944 | PackageChange pc = dit.mPackageChanges.get(j); |
| 6945 | if (pc.mUpdate) { |
| 6946 | out.startTag(null, "upd"); |
| 6947 | out.attribute(null, "pkg", pc.mPackageName); |
| 6948 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 6949 | out.endTag(null, "upd"); |
| 6950 | } else { |
| 6951 | out.startTag(null, "rem"); |
| 6952 | out.attribute(null, "pkg", pc.mPackageName); |
| 6953 | out.endTag(null, "rem"); |
| 6954 | } |
| 6955 | } |
| 6956 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6957 | out.endTag(null, "item"); |
| 6958 | } |
| 6959 | out.endTag(null, "daily-items"); |
| 6960 | out.endDocument(); |
| 6961 | } |
| 6962 | |
| 6963 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 6964 | StringBuilder tmpBuilder) throws IOException { |
| 6965 | if (steps != null) { |
| 6966 | out.startTag(null, tag); |
| 6967 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 6968 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 6969 | out.startTag(null, "s"); |
| 6970 | tmpBuilder.setLength(0); |
| 6971 | steps.encodeEntryAt(i, tmpBuilder); |
| 6972 | out.attribute(null, "v", tmpBuilder.toString()); |
| 6973 | out.endTag(null, "s"); |
| 6974 | } |
| 6975 | out.endTag(null, tag); |
| 6976 | } |
| 6977 | } |
| 6978 | |
| 6979 | public void readDailyStatsLocked() { |
| 6980 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 6981 | mDailyItems.clear(); |
| 6982 | FileInputStream stream; |
| 6983 | try { |
| 6984 | stream = mDailyFile.openRead(); |
| 6985 | } catch (FileNotFoundException e) { |
| 6986 | return; |
| 6987 | } |
| 6988 | try { |
| 6989 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 6990 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6991 | readDailyItemsLocked(parser); |
| 6992 | } catch (XmlPullParserException e) { |
| 6993 | } finally { |
| 6994 | try { |
| 6995 | stream.close(); |
| 6996 | } catch (IOException e) { |
| 6997 | } |
| 6998 | } |
| 6999 | } |
| 7000 | |
| 7001 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7002 | try { |
| 7003 | int type; |
| 7004 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7005 | && type != XmlPullParser.END_DOCUMENT) { |
| 7006 | ; |
| 7007 | } |
| 7008 | |
| 7009 | if (type != XmlPullParser.START_TAG) { |
| 7010 | throw new IllegalStateException("no start tag found"); |
| 7011 | } |
| 7012 | |
| 7013 | int outerDepth = parser.getDepth(); |
| 7014 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7015 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7016 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7017 | continue; |
| 7018 | } |
| 7019 | |
| 7020 | String tagName = parser.getName(); |
| 7021 | if (tagName.equals("item")) { |
| 7022 | readDailyItemTagLocked(parser); |
| 7023 | } else { |
| 7024 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7025 | + parser.getName()); |
| 7026 | XmlUtils.skipCurrentTag(parser); |
| 7027 | } |
| 7028 | } |
| 7029 | |
| 7030 | } catch (IllegalStateException e) { |
| 7031 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7032 | } catch (NullPointerException e) { |
| 7033 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7034 | } catch (NumberFormatException e) { |
| 7035 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7036 | } catch (XmlPullParserException e) { |
| 7037 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7038 | } catch (IOException e) { |
| 7039 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7040 | } catch (IndexOutOfBoundsException e) { |
| 7041 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7042 | } |
| 7043 | } |
| 7044 | |
| 7045 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7046 | XmlPullParserException, IOException { |
| 7047 | DailyItem dit = new DailyItem(); |
| 7048 | String attr = parser.getAttributeValue(null, "start"); |
| 7049 | if (attr != null) { |
| 7050 | dit.mStartTime = Long.parseLong(attr); |
| 7051 | } |
| 7052 | attr = parser.getAttributeValue(null, "end"); |
| 7053 | if (attr != null) { |
| 7054 | dit.mEndTime = Long.parseLong(attr); |
| 7055 | } |
| 7056 | int outerDepth = parser.getDepth(); |
| 7057 | int type; |
| 7058 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7059 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7060 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7061 | continue; |
| 7062 | } |
| 7063 | |
| 7064 | String tagName = parser.getName(); |
| 7065 | if (tagName.equals("dis")) { |
| 7066 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7067 | } else if (tagName.equals("chg")) { |
| 7068 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7069 | } else if (tagName.equals("upd")) { |
| 7070 | if (dit.mPackageChanges == null) { |
| 7071 | dit.mPackageChanges = new ArrayList<>(); |
| 7072 | } |
| 7073 | PackageChange pc = new PackageChange(); |
| 7074 | pc.mUpdate = true; |
| 7075 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7076 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7077 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7078 | dit.mPackageChanges.add(pc); |
| 7079 | XmlUtils.skipCurrentTag(parser); |
| 7080 | } else if (tagName.equals("rem")) { |
| 7081 | if (dit.mPackageChanges == null) { |
| 7082 | dit.mPackageChanges = new ArrayList<>(); |
| 7083 | } |
| 7084 | PackageChange pc = new PackageChange(); |
| 7085 | pc.mUpdate = false; |
| 7086 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7087 | dit.mPackageChanges.add(pc); |
| 7088 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7089 | } else { |
| 7090 | Slog.w(TAG, "Unknown element under <item>: " |
| 7091 | + parser.getName()); |
| 7092 | XmlUtils.skipCurrentTag(parser); |
| 7093 | } |
| 7094 | } |
| 7095 | mDailyItems.add(dit); |
| 7096 | } |
| 7097 | |
| 7098 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7099 | String tag) |
| 7100 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7101 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7102 | if (numAttr == null) { |
| 7103 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7104 | XmlUtils.skipCurrentTag(parser); |
| 7105 | return; |
| 7106 | } |
| 7107 | final int num = Integer.parseInt(numAttr); |
| 7108 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7109 | if (isCharge) { |
| 7110 | dit.mChargeSteps = steps; |
| 7111 | } else { |
| 7112 | dit.mDischargeSteps = steps; |
| 7113 | } |
| 7114 | int i = 0; |
| 7115 | int outerDepth = parser.getDepth(); |
| 7116 | int type; |
| 7117 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7118 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7119 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7120 | continue; |
| 7121 | } |
| 7122 | |
| 7123 | String tagName = parser.getName(); |
| 7124 | if ("s".equals(tagName)) { |
| 7125 | if (i < num) { |
| 7126 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7127 | if (valueAttr != null) { |
| 7128 | steps.decodeEntryAt(i, valueAttr); |
| 7129 | i++; |
| 7130 | } |
| 7131 | } |
| 7132 | } else { |
| 7133 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7134 | + parser.getName()); |
| 7135 | XmlUtils.skipCurrentTag(parser); |
| 7136 | } |
| 7137 | } |
| 7138 | steps.mNumStepDurations = i; |
| 7139 | } |
| 7140 | |
| 7141 | @Override |
| 7142 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7143 | int index = mDailyItems.size()-1-daysAgo; |
| 7144 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7145 | } |
| 7146 | |
| 7147 | @Override |
| 7148 | public long getCurrentDailyStartTime() { |
| 7149 | return mDailyStartTime; |
| 7150 | } |
| 7151 | |
| 7152 | @Override |
| 7153 | public long getNextMinDailyDeadline() { |
| 7154 | return mNextMinDailyDeadline; |
| 7155 | } |
| 7156 | |
| 7157 | @Override |
| 7158 | public long getNextMaxDailyDeadline() { |
| 7159 | return mNextMaxDailyDeadline; |
| 7160 | } |
| 7161 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7162 | @Override |
| 7163 | public boolean startIteratingOldHistoryLocked() { |
| 7164 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7165 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7166 | if ((mHistoryIterator = mHistory) == null) { |
| 7167 | return false; |
| 7168 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7169 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7170 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7171 | mReadOverflow = false; |
| 7172 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7173 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7174 | } |
| 7175 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7176 | @Override |
| 7177 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7178 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7179 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7180 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7181 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7182 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7183 | HistoryItem cur = mHistoryIterator; |
| 7184 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7185 | if (!mReadOverflow && !end) { |
| 7186 | Slog.w(TAG, "Old history ends before new history!"); |
| 7187 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7188 | return false; |
| 7189 | } |
| 7190 | out.setTo(cur); |
| 7191 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7192 | if (!mReadOverflow) { |
| 7193 | if (end) { |
| 7194 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7195 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7196 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7197 | pw.println("Histories differ!"); |
| 7198 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7199 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7200 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7201 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7202 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7203 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7204 | } |
| 7205 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7206 | return true; |
| 7207 | } |
| 7208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7209 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7210 | public void finishIteratingOldHistoryLocked() { |
| 7211 | mIteratingHistory = false; |
| 7212 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7213 | mHistoryIterator = null; |
| 7214 | } |
| 7215 | |
| 7216 | public int getHistoryTotalSize() { |
| 7217 | return MAX_HISTORY_BUFFER; |
| 7218 | } |
| 7219 | |
| 7220 | public int getHistoryUsedSize() { |
| 7221 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | @Override |
| 7225 | public boolean startIteratingHistoryLocked() { |
| 7226 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7227 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7228 | if (mHistoryBuffer.dataSize() <= 0) { |
| 7229 | return false; |
| 7230 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7231 | mHistoryBuffer.setDataPosition(0); |
| 7232 | mReadOverflow = false; |
| 7233 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7234 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 7235 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 7236 | mReadHistoryChars = 0; |
| 7237 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7238 | final HistoryTag tag = ent.getKey(); |
| 7239 | final int idx = ent.getValue(); |
| 7240 | mReadHistoryStrings[idx] = tag.string; |
| 7241 | mReadHistoryUids[idx] = tag.uid; |
| 7242 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7243 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7244 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7248 | public int getHistoryStringPoolSize() { |
| 7249 | return mReadHistoryStrings.length; |
| 7250 | } |
| 7251 | |
| 7252 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7253 | public int getHistoryStringPoolBytes() { |
| 7254 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 7255 | // Each string character is 2 bytes. |
| 7256 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 7257 | } |
| 7258 | |
| 7259 | @Override |
| 7260 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7261 | return mReadHistoryStrings[index]; |
| 7262 | } |
| 7263 | |
| 7264 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7265 | public int getHistoryTagPoolUid(int index) { |
| 7266 | return mReadHistoryUids[index]; |
| 7267 | } |
| 7268 | |
| 7269 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7270 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7271 | final int pos = mHistoryBuffer.dataPosition(); |
| 7272 | if (pos == 0) { |
| 7273 | out.clear(); |
| 7274 | } |
| 7275 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7276 | if (end) { |
| 7277 | return false; |
| 7278 | } |
| 7279 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7280 | final long lastRealtime = out.time; |
| 7281 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7282 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7283 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 7284 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7285 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 7286 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7287 | return true; |
| 7288 | } |
| 7289 | |
| 7290 | @Override |
| 7291 | public void finishIteratingHistoryLocked() { |
| 7292 | mIteratingHistory = false; |
| 7293 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7294 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7295 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7296 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7297 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7298 | public long getHistoryBaseTime() { |
| 7299 | return mHistoryBaseTime; |
| 7300 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7301 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7302 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | public int getStartCount() { |
| 7304 | return mStartCount; |
| 7305 | } |
| 7306 | |
| 7307 | public boolean isOnBattery() { |
| 7308 | return mOnBattery; |
| 7309 | } |
| 7310 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7311 | public boolean isCharging() { |
| 7312 | return mCharging; |
| 7313 | } |
| 7314 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7315 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7316 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7317 | } |
| 7318 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7319 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7320 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7321 | mOnBatteryTimeBase.init(uptime, realtime); |
| 7322 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7323 | mRealtime = 0; |
| 7324 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7325 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7326 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7327 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7328 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7329 | void initDischarge() { |
| 7330 | mLowDischargeAmountSinceCharge = 0; |
| 7331 | mHighDischargeAmountSinceCharge = 0; |
| 7332 | mDischargeAmountScreenOn = 0; |
| 7333 | mDischargeAmountScreenOnSinceCharge = 0; |
| 7334 | mDischargeAmountScreenOff = 0; |
| 7335 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7336 | mDischargeStepTracker.init(); |
| 7337 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7338 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7339 | |
| 7340 | public void resetAllStatsCmdLocked() { |
| 7341 | resetAllStatsLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7342 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 7343 | long uptime = mSecUptime * 1000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7344 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 7345 | long realtime = mSecRealtime * 1000; |
| 7346 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 7347 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7348 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7349 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 7350 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7351 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 7352 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 7353 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7354 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7355 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 7356 | mDischargeScreenOffUnplugLevel = 0; |
| 7357 | } else { |
| 7358 | mDischargeScreenOnUnplugLevel = 0; |
| 7359 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 7360 | } |
| 7361 | mDischargeAmountScreenOn = 0; |
| 7362 | mDischargeAmountScreenOff = 0; |
| 7363 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7364 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7365 | } |
| 7366 | |
| 7367 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7368 | mStartCount = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7369 | initTimes(SystemClock.uptimeMillis() * 1000, SystemClock.elapsedRealtime() * 1000); |
| 7370 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7371 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7372 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7373 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7374 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 7375 | mPowerSaveModeEnabledTimer.reset(false); |
| 7376 | mDeviceIdleModeEnabledTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7377 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7378 | mPhoneOnTimer.reset(false); |
| 7379 | mAudioOnTimer.reset(false); |
| 7380 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 7381 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7382 | mCameraOnTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7383 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7384 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7385 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7386 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7387 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7388 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7389 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7390 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7391 | mNetworkByteActivityCounters[i].reset(false); |
| 7392 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7393 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7394 | mMobileRadioActiveTimer.reset(false); |
| 7395 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7396 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7397 | mMobileRadioActiveUnknownTime.reset(false); |
| 7398 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7399 | mWifiOnTimer.reset(false); |
| 7400 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7401 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7402 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7403 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7404 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7405 | mWifiSupplStateTimer[i].reset(false); |
| 7406 | } |
| 7407 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7408 | mWifiSignalStrengthsTimer[i].reset(false); |
| 7409 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 7410 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 7411 | mBluetoothActivityCounters[i].reset(false); |
| 7412 | mWifiActivityCounters[i].reset(false); |
| 7413 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7414 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7415 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7416 | for (int i=0; i<mUidStats.size(); i++) { |
| 7417 | if (mUidStats.valueAt(i).reset()) { |
| 7418 | mUidStats.remove(mUidStats.keyAt(i)); |
| 7419 | i--; |
| 7420 | } |
| 7421 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7422 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7423 | if (mKernelWakelockStats.size() > 0) { |
| 7424 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7425 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7426 | } |
| 7427 | mKernelWakelockStats.clear(); |
| 7428 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7429 | |
| 7430 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7431 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 7432 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7433 | } |
| 7434 | mWakeupReasonStats.clear(); |
| 7435 | } |
| 7436 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 7437 | mLastHistoryStepDetails = null; |
| 7438 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 7439 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 7440 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 7441 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 7442 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 7443 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 7444 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 7445 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 7446 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 7447 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 7448 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7449 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7450 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7451 | clearHistoryLocked(); |
| 7452 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7453 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7454 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7455 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7456 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 7457 | // Not recording process starts/stops. |
| 7458 | continue; |
| 7459 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7460 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7461 | if (active == null) { |
| 7462 | continue; |
| 7463 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7464 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 7465 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7466 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7467 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 7468 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7469 | } |
| 7470 | } |
| 7471 | } |
| 7472 | } |
| 7473 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7474 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7475 | if (oldScreenOn) { |
| 7476 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 7477 | if (diff > 0) { |
| 7478 | mDischargeAmountScreenOn += diff; |
| 7479 | mDischargeAmountScreenOnSinceCharge += diff; |
| 7480 | } |
| 7481 | } else { |
| 7482 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 7483 | if (diff > 0) { |
| 7484 | mDischargeAmountScreenOff += diff; |
| 7485 | mDischargeAmountScreenOffSinceCharge += diff; |
| 7486 | } |
| 7487 | } |
| 7488 | if (newScreenOn) { |
| 7489 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 7490 | mDischargeScreenOffUnplugLevel = 0; |
| 7491 | } else { |
| 7492 | mDischargeScreenOnUnplugLevel = 0; |
| 7493 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 7494 | } |
| 7495 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7496 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7497 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7498 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7499 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 7500 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7501 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7502 | } |
| 7503 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7504 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 7505 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 7506 | |
| 7507 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 7508 | |
| 7509 | private static final int NETWORK_STATS_LAST = 0; |
| 7510 | private static final int NETWORK_STATS_NEXT = 1; |
| 7511 | private static final int NETWORK_STATS_DELTA = 2; |
| 7512 | |
| 7513 | private final NetworkStats[] mMobileNetworkStats = new NetworkStats[] { |
| 7514 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7515 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7516 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7517 | }; |
| 7518 | |
| 7519 | private final NetworkStats[] mWifiNetworkStats = new NetworkStats[] { |
| 7520 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7521 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7522 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7523 | }; |
| 7524 | |
| 7525 | /** |
| 7526 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 7527 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 7528 | */ |
| 7529 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 7530 | NetworkStats[] networkStatsBuffer) |
| 7531 | throws IOException { |
| 7532 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 7533 | false)) { |
| 7534 | return null; |
| 7535 | } |
| 7536 | |
| 7537 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 7538 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 7539 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 7540 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 7541 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 7542 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 7543 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 7544 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 7545 | } |
| 7546 | |
| 7547 | /** |
| 7548 | * Distribute WiFi energy info and network traffic to apps. |
| 7549 | * @param info The energy information from the WiFi controller. |
| 7550 | */ |
| 7551 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 7552 | if (DEBUG_ENERGY) { |
| 7553 | Slog.d(TAG, "Updating wifi stats"); |
| 7554 | } |
| 7555 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7556 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 7557 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7558 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7559 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 7560 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 7561 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7562 | } catch (IOException e) { |
| 7563 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 7564 | return; |
| 7565 | } |
| 7566 | |
| 7567 | if (!mOnBatteryInternal) { |
| 7568 | return; |
| 7569 | } |
| 7570 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7571 | SparseLongArray rxPackets = new SparseLongArray(); |
| 7572 | SparseLongArray txPackets = new SparseLongArray(); |
| 7573 | long totalTxPackets = 0; |
| 7574 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7575 | if (delta != null) { |
| 7576 | final int size = delta.size(); |
| 7577 | for (int i = 0; i < size; i++) { |
| 7578 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7579 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7580 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7581 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7582 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7583 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7584 | } |
| 7585 | |
| 7586 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7587 | continue; |
| 7588 | } |
| 7589 | |
| 7590 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7591 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 7592 | entry.rxPackets); |
| 7593 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 7594 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7595 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 7596 | txPackets.put(u.getUid(), entry.txPackets); |
| 7597 | |
| 7598 | // Sum the total number of packets so that the Rx Power and Tx Power can |
| 7599 | // be evenly distributed amongst the apps. |
| 7600 | totalRxPackets += entry.rxPackets; |
| 7601 | totalTxPackets += entry.txPackets; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7602 | |
| 7603 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7604 | entry.rxBytes); |
| 7605 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7606 | entry.txBytes); |
| 7607 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7608 | entry.rxPackets); |
| 7609 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7610 | entry.txPackets); |
| 7611 | } |
| 7612 | } |
| 7613 | |
| 7614 | if (info != null) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7615 | mHasWifiEnergyReporting = true; |
| 7616 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7617 | // Measured in mAms |
| 7618 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 7619 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 7620 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 7621 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 7622 | |
| 7623 | long leftOverRxTimeMs = rxTimeMs; |
| 7624 | |
| 7625 | if (DEBUG_ENERGY) { |
| 7626 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 7627 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 7628 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 7629 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 7630 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 7631 | } |
| 7632 | |
| 7633 | long totalWifiLockTimeMs = 0; |
| 7634 | long totalScanTimeMs = 0; |
| 7635 | |
| 7636 | // On the first pass, collect some totals so that we can normalize power |
| 7637 | // calculations if we need to. |
| 7638 | final int uidStatsSize = mUidStats.size(); |
| 7639 | for (int i = 0; i < uidStatsSize; i++) { |
| 7640 | final Uid uid = mUidStats.valueAt(i); |
| 7641 | |
| 7642 | // Sum the total scan power for all apps. |
| 7643 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7644 | elapsedRealtimeMs * 1000) / 1000; |
| 7645 | |
| 7646 | // Sum the total time holding wifi lock for all apps. |
| 7647 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7648 | elapsedRealtimeMs * 1000) / 1000; |
| 7649 | } |
| 7650 | |
| 7651 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 7652 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 7653 | + rxTimeMs + " ms). Normalizing scan time."); |
| 7654 | } |
| 7655 | |
| 7656 | // Actually assign and distribute power usage to apps. |
| 7657 | for (int i = 0; i < uidStatsSize; i++) { |
| 7658 | final Uid uid = mUidStats.valueAt(i); |
| 7659 | |
| 7660 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7661 | elapsedRealtimeMs * 1000) / 1000; |
| 7662 | if (scanTimeSinceMarkMs > 0) { |
| 7663 | // Set the new mark so that next time we get new data since this point. |
| 7664 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 7665 | |
| 7666 | if (totalScanTimeMs > rxTimeMs) { |
| 7667 | // Our total scan time is more than the reported Rx time. |
| 7668 | // This is possible because the cost of a scan is approximate. |
| 7669 | // Let's normalize the result so that we evenly blame each app |
| 7670 | // scanning. |
| 7671 | // |
| 7672 | // This means that we may have apps that received packets not be blamed |
| 7673 | // for this, but this is fine as scans are relatively more expensive. |
| 7674 | scanTimeSinceMarkMs = (rxTimeMs * scanTimeSinceMarkMs) / totalScanTimeMs; |
| 7675 | } |
| 7676 | |
| 7677 | if (DEBUG_ENERGY) { |
| 7678 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": " |
| 7679 | + scanTimeSinceMarkMs + " ms)"); |
| 7680 | } |
| 7681 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, scanTimeSinceMarkMs); |
| 7682 | leftOverRxTimeMs -= scanTimeSinceMarkMs; |
| 7683 | } |
| 7684 | |
| 7685 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 7686 | // lock. |
| 7687 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7688 | elapsedRealtimeMs * 1000) / 1000; |
| 7689 | if (wifiLockTimeSinceMarkMs > 0) { |
| 7690 | // Set the new mark so that next time we get new data since this point. |
| 7691 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 7692 | |
| 7693 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 7694 | / totalWifiLockTimeMs; |
| 7695 | if (DEBUG_ENERGY) { |
| 7696 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 7697 | + myIdleTimeMs + " ms"); |
| 7698 | } |
| 7699 | uid.noteWifiControllerActivityLocked(CONTROLLER_IDLE_TIME, myIdleTimeMs); |
| 7700 | } |
| 7701 | } |
| 7702 | |
| 7703 | if (DEBUG_ENERGY) { |
| 7704 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 7705 | } |
| 7706 | |
| 7707 | // Distribute the Tx power appropriately between all apps that transmitted packets. |
| 7708 | for (int i = 0; i < txPackets.size(); i++) { |
| 7709 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 7710 | final long myTxTimeMs = (txPackets.valueAt(i) * txTimeMs) / totalTxPackets; |
| 7711 | if (DEBUG_ENERGY) { |
| 7712 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 7713 | } |
| 7714 | uid.noteWifiControllerActivityLocked(CONTROLLER_TX_TIME, myTxTimeMs); |
| 7715 | } |
| 7716 | |
| 7717 | // Distribute the remaining Rx power appropriately between all apps that received |
| 7718 | // packets. |
| 7719 | for (int i = 0; i < rxPackets.size(); i++) { |
| 7720 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 7721 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 7722 | if (DEBUG_ENERGY) { |
| 7723 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 7724 | } |
| 7725 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, myRxTimeMs); |
| 7726 | } |
| 7727 | |
| 7728 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 7729 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7730 | // Update WiFi controller stats. |
| 7731 | mWifiActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7732 | info.getControllerRxTimeMillis()); |
| 7733 | mWifiActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7734 | info.getControllerTxTimeMillis()); |
| 7735 | mWifiActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7736 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7737 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7738 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 7739 | final double opVolt = mPowerProfile.getAveragePower( |
| 7740 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 7741 | if (opVolt != 0) { |
| 7742 | // We store the power drain as mAms. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7743 | mWifiActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7744 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7745 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7746 | } |
| 7747 | } |
| 7748 | |
| 7749 | /** |
| 7750 | * Distribute Cell radio energy info and network traffic to apps. |
| 7751 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7752 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 7753 | if (DEBUG_ENERGY) { |
| 7754 | Slog.d(TAG, "Updating mobile radio stats"); |
| 7755 | } |
| 7756 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7757 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7758 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7759 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 7760 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 7761 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7762 | } catch (IOException e) { |
| 7763 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 7764 | return; |
| 7765 | } |
| 7766 | |
| 7767 | if (delta == null || !mOnBatteryInternal) { |
| 7768 | return; |
| 7769 | } |
| 7770 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7771 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 7772 | elapsedRealtimeMs * 1000); |
| 7773 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7774 | long totalPackets = delta.getTotalPackets(); |
| 7775 | |
| 7776 | final int size = delta.size(); |
| 7777 | for (int i = 0; i < size; i++) { |
| 7778 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7779 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7780 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7781 | continue; |
| 7782 | } |
| 7783 | |
| 7784 | if (DEBUG_ENERGY) { |
| 7785 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 7786 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7787 | + " txPackets=" + entry.txPackets); |
| 7788 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7789 | |
| 7790 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7791 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 7792 | entry.rxPackets); |
| 7793 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 7794 | entry.txPackets); |
| 7795 | |
| 7796 | if (radioTime > 0) { |
| 7797 | // Distribute total radio active time in to this app. |
| 7798 | long appPackets = entry.rxPackets + entry.txPackets; |
| 7799 | long appRadioTime = (radioTime*appPackets)/totalPackets; |
| 7800 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 7801 | // Remove this app from the totals, so that we don't lose any time |
| 7802 | // due to rounding. |
| 7803 | radioTime -= appRadioTime; |
| 7804 | totalPackets -= appPackets; |
| 7805 | } |
| 7806 | |
| 7807 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 7808 | entry.rxBytes); |
| 7809 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 7810 | entry.txBytes); |
| 7811 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 7812 | entry.rxPackets); |
| 7813 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 7814 | entry.txPackets); |
| 7815 | } |
| 7816 | |
| 7817 | if (radioTime > 0) { |
| 7818 | // Whoops, there is some radio time we can't blame on an app! |
| 7819 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 7820 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 7821 | } |
| 7822 | } |
| 7823 | |
| 7824 | /** |
| 7825 | * Distribute Bluetooth energy info and network traffic to apps. |
| 7826 | * @param info The energy information from the bluetooth controller. |
| 7827 | */ |
| 7828 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 7829 | if (DEBUG_ENERGY) { |
| 7830 | Slog.d(TAG, "Updating bluetooth stats"); |
| 7831 | } |
| 7832 | |
Adam Lesinski | 719e61f | 2015-05-15 15:49:24 -0700 | [diff] [blame] | 7833 | if (info != null && mOnBatteryInternal) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7834 | mHasBluetoothEnergyReporting = true; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7835 | mBluetoothActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7836 | info.getControllerRxTimeMillis()); |
| 7837 | mBluetoothActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7838 | info.getControllerTxTimeMillis()); |
| 7839 | mBluetoothActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7840 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7841 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7842 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 7843 | final double opVolt = mPowerProfile.getAveragePower( |
| 7844 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 7845 | if (opVolt != 0) { |
| 7846 | // We store the power drain as mAms. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7847 | mBluetoothActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7848 | (long) (info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7849 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7850 | } |
| 7851 | } |
| 7852 | |
| 7853 | /** |
| 7854 | * Read and distribute kernel wake lock use across apps. |
| 7855 | */ |
| 7856 | public void updateKernelWakelocksLocked() { |
| 7857 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 7858 | mTmpWakelockStats); |
| 7859 | if (wakelockStats == null) { |
| 7860 | // Not crashing might make board bringup easier. |
| 7861 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 7862 | return; |
| 7863 | } |
| 7864 | |
| 7865 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 7866 | String name = ent.getKey(); |
| 7867 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 7868 | |
| 7869 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 7870 | if (kwlt == null) { |
| 7871 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, |
| 7872 | true /* track reported val */); |
| 7873 | mKernelWakelockStats.put(name, kwlt); |
| 7874 | } |
| 7875 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 7876 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 7877 | kwlt.setUpdateVersion(kws.mVersion); |
| 7878 | } |
| 7879 | |
| 7880 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 7881 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 7882 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 7883 | SamplingTimer st = ent.getValue(); |
| 7884 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 7885 | st.setStale(); |
| 7886 | } |
| 7887 | } |
| 7888 | } |
| 7889 | } |
| 7890 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 7891 | // We use an anonymous class to access these variables, |
| 7892 | // so they can't live on the stack or they'd have to be |
| 7893 | // final MutableLong objects (more allocations). |
| 7894 | // Used in updateCpuTimeLocked(). |
| 7895 | long mTempTotalCpuUserTimeUs; |
| 7896 | long mTempTotalCpuSystemTimeUs; |
| 7897 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7898 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 7899 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 7900 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 7901 | * wakelocks. If the screen is on, we just assign the actual cpu time an app used. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7902 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 7903 | public void updateCpuTimeLocked() { |
| 7904 | if (DEBUG_ENERGY_CPU) { |
| 7905 | Slog.d(TAG, "!Cpu updating!"); |
| 7906 | } |
| 7907 | |
| 7908 | // Holding a wakelock costs more than just using the cpu. |
| 7909 | // Currently, we assign only half the cpu time to an app that is running but |
| 7910 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 7911 | // If no app is holding a wakelock, then the distribution is normal. |
| 7912 | final int wakelockWeight = 50; |
| 7913 | |
| 7914 | // Read the time spent at various cpu frequencies. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7915 | final int cpuSpeedSteps = getCpuSpeedSteps(); |
| 7916 | final long[] cpuSpeeds = mKernelCpuSpeedReader.readDelta(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 7917 | |
| 7918 | int numWakelocks = 0; |
| 7919 | |
| 7920 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 7921 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 7922 | final int numPartialTimers = mPartialTimers.size(); |
| 7923 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 7924 | for (int i = 0; i < numPartialTimers; i++) { |
| 7925 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 7926 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 7927 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 7928 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 7929 | // the newly added timer for past cpu time, so we only consider timers that |
| 7930 | // were present for one round of collection. Once a timer has gone through |
| 7931 | // a round of collection, its mInList field is set to true. |
| 7932 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7933 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 7934 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7935 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 7936 | |
| 7937 | final int numWakelocksF = numWakelocks; |
| 7938 | mTempTotalCpuUserTimeUs = 0; |
| 7939 | mTempTotalCpuSystemTimeUs = 0; |
| 7940 | |
| 7941 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 7942 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 7943 | // we just ignore the data. |
| 7944 | final long startTimeMs = SystemClock.elapsedRealtime(); |
| 7945 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 7946 | new KernelUidCpuTimeReader.Callback() { |
| 7947 | @Override |
| 7948 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs) { |
| 7949 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 7950 | |
| 7951 | // Accumulate the total system and user time. |
| 7952 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 7953 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 7954 | |
| 7955 | StringBuilder sb = null; |
| 7956 | if (DEBUG_ENERGY_CPU) { |
| 7957 | sb = new StringBuilder(); |
| 7958 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 7959 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 7960 | sb.append(" s="); |
| 7961 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 7962 | sb.append("\n"); |
| 7963 | } |
| 7964 | |
| 7965 | if (numWakelocksF > 0) { |
| 7966 | // We have wakelocks being held, so only give a portion of the |
| 7967 | // time to the process. The rest will be distributed among wakelock |
| 7968 | // holders. |
| 7969 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 7970 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 7971 | } |
| 7972 | |
| 7973 | if (sb != null) { |
| 7974 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 7975 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 7976 | sb.append(" s="); |
| 7977 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 7978 | Slog.d(TAG, sb.toString()); |
| 7979 | } |
| 7980 | |
| 7981 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 7982 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 7983 | |
| 7984 | // Add the cpu speeds to this UID. These are used as a ratio |
| 7985 | // for computing the power this UID used. |
| 7986 | for (int i = 0; i < cpuSpeedSteps; i++) { |
| 7987 | if (u.mSpeedBins[i] == null) { |
| 7988 | u.mSpeedBins[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7989 | } |
| 7990 | u.mSpeedBins[i].addCountLocked(cpuSpeeds[i]); |
| 7991 | } |
| 7992 | } |
| 7993 | }); |
| 7994 | |
| 7995 | if (DEBUG_ENERGY_CPU) { |
| 7996 | Slog.d(TAG, "Reading cpu stats took " + (SystemClock.elapsedRealtime() - startTimeMs) + |
| 7997 | " ms"); |
| 7998 | } |
| 7999 | |
| 8000 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 8001 | // Distribute a portion of the total cpu time to wakelock holders. |
| 8002 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 8003 | mTempTotalCpuSystemTimeUs = |
| 8004 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 8005 | |
| 8006 | for (int i = 0; i < numPartialTimers; i++) { |
| 8007 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8008 | |
| 8009 | // The system does not share any blame, as it is usually holding the wakelock |
| 8010 | // on behalf of an app. |
| 8011 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8012 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 8013 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 8014 | |
| 8015 | if (DEBUG_ENERGY_CPU) { |
| 8016 | StringBuilder sb = new StringBuilder(); |
| 8017 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 8018 | .append(": u="); |
| 8019 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8020 | sb.append(" s="); |
| 8021 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 8022 | Slog.d(TAG, sb.toString()); |
| 8023 | } |
| 8024 | |
| 8025 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 8026 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 8027 | |
| 8028 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
| 8029 | proc.addCpuTimeLocked(userTimeUs, systemTimeUs); |
| 8030 | |
| 8031 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 8032 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 8033 | numWakelocks--; |
| 8034 | } |
| 8035 | } |
| 8036 | |
| 8037 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 8038 | // Anything left over is given to the system. |
| 8039 | if (DEBUG_ENERGY_CPU) { |
| 8040 | StringBuilder sb = new StringBuilder(); |
| 8041 | sb.append(" Distributing lost time to system: u="); |
| 8042 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 8043 | sb.append(" s="); |
| 8044 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 8045 | Slog.d(TAG, sb.toString()); |
| 8046 | } |
| 8047 | |
| 8048 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 8049 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 8050 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 8051 | |
| 8052 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
| 8053 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs, |
| 8054 | (int) mTempTotalCpuSystemTimeUs); |
| 8055 | } |
| 8056 | } |
| 8057 | |
| 8058 | // See if there is a difference in wakelocks between this collection and the last |
| 8059 | // collection. |
| 8060 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 8061 | // No difference, so each timer is now considered for the next collection. |
| 8062 | for (int i = 0; i < numPartialTimers; i++) { |
| 8063 | mPartialTimers.get(i).mInList = true; |
| 8064 | } |
| 8065 | } else { |
| 8066 | // The lists are different, meaning we added (or removed a timer) since the last |
| 8067 | // collection. |
| 8068 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 8069 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 8070 | mLastPartialTimers.get(i).mInList = false; |
| 8071 | } |
| 8072 | mLastPartialTimers.clear(); |
| 8073 | |
| 8074 | // Mark the current timers as gone through a collection. |
| 8075 | for (int i = 0; i < numPartialTimers; i++) { |
| 8076 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8077 | timer.mInList = true; |
| 8078 | mLastPartialTimers.add(timer); |
| 8079 | } |
| 8080 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8081 | } |
| 8082 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8083 | boolean setChargingLocked(boolean charging) { |
| 8084 | if (mCharging != charging) { |
| 8085 | mCharging = charging; |
| 8086 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8087 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8088 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8089 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8090 | } |
| 8091 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 8092 | return true; |
| 8093 | } |
| 8094 | return false; |
| 8095 | } |
| 8096 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8097 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 8098 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8099 | boolean doWrite = false; |
| 8100 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 8101 | m.arg1 = onBattery ? 1 : 0; |
| 8102 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8103 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8104 | final long uptime = mSecUptime * 1000; |
| 8105 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8106 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8107 | if (onBattery) { |
| 8108 | // We will reset our status if we are unplugging after the |
| 8109 | // battery was last full, or the level is at 100, or |
| 8110 | // we have gone through a significant charge (from a very low |
| 8111 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8112 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 8113 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8114 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 8115 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 8116 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 8117 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 8118 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 8119 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 8120 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 8121 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8122 | // Before we write, collect a snapshot of the final aggregated |
| 8123 | // stats to be reported in the next checkin. Only do this if we have |
| 8124 | // a sufficient amount of data to make it interesting. |
| 8125 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 8126 | final Parcel parcel = Parcel.obtain(); |
| 8127 | writeSummaryToParcel(parcel, true); |
| 8128 | BackgroundThread.getHandler().post(new Runnable() { |
| 8129 | @Override public void run() { |
| 8130 | synchronized (mCheckinFile) { |
| 8131 | FileOutputStream stream = null; |
| 8132 | try { |
| 8133 | stream = mCheckinFile.startWrite(); |
| 8134 | stream.write(parcel.marshall()); |
| 8135 | stream.flush(); |
| 8136 | FileUtils.sync(stream); |
| 8137 | stream.close(); |
| 8138 | mCheckinFile.finishWrite(stream); |
| 8139 | } catch (IOException e) { |
| 8140 | Slog.w("BatteryStats", |
| 8141 | "Error writing checkin battery statistics", e); |
| 8142 | mCheckinFile.failWrite(stream); |
| 8143 | } finally { |
| 8144 | parcel.recycle(); |
| 8145 | } |
| 8146 | } |
| 8147 | } |
| 8148 | }); |
| 8149 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8150 | doWrite = true; |
| 8151 | resetAllStatsLocked(); |
| 8152 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8153 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8154 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8155 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8156 | if (mCharging) { |
| 8157 | setChargingLocked(false); |
| 8158 | } |
| 8159 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8160 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8161 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8162 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8163 | mDischargeStepTracker.clearTime(); |
| 8164 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8165 | mInitStepMode = mCurStepMode; |
| 8166 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8167 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8168 | mHistoryCur.batteryLevel = (byte)level; |
| 8169 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 8170 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 8171 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8172 | if (reset) { |
| 8173 | mRecordingHistory = true; |
| 8174 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 8175 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8176 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8177 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8178 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8179 | mDischargeScreenOnUnplugLevel = level; |
| 8180 | mDischargeScreenOffUnplugLevel = 0; |
| 8181 | } else { |
| 8182 | mDischargeScreenOnUnplugLevel = 0; |
| 8183 | mDischargeScreenOffUnplugLevel = level; |
| 8184 | } |
| 8185 | mDischargeAmountScreenOn = 0; |
| 8186 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8187 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8188 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8189 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8190 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8191 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8192 | mHistoryCur.batteryLevel = (byte)level; |
| 8193 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 8194 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 8195 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8196 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8197 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8198 | if (level < mDischargeUnplugLevel) { |
| 8199 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 8200 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 8201 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8202 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 8203 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8204 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8205 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8206 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8207 | mInitStepMode = mCurStepMode; |
| 8208 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8209 | } |
| 8210 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 8211 | if (mFile != null) { |
| 8212 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | } |
| 8214 | } |
| 8215 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8216 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8217 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 8218 | boolean reset) { |
| 8219 | mRecordingHistory = true; |
| 8220 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8221 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 8222 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8223 | mHistoryCur); |
| 8224 | mHistoryCur.currentTime = 0; |
| 8225 | if (reset) { |
| 8226 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 8227 | } |
| 8228 | } |
| 8229 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 8230 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 8231 | final long uptimeMs) { |
| 8232 | if (mRecordingHistory) { |
| 8233 | mHistoryCur.currentTime = currentTime; |
| 8234 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 8235 | mHistoryCur); |
| 8236 | mHistoryCur.currentTime = 0; |
| 8237 | } |
| 8238 | } |
| 8239 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8240 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 8241 | if (mRecordingHistory) { |
| 8242 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8243 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 8244 | mHistoryCur); |
| 8245 | mHistoryCur.currentTime = 0; |
| 8246 | } |
| 8247 | } |
| 8248 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8249 | private void scheduleSyncExternalStatsLocked(String reason) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8250 | if (mExternalSync != null) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8251 | mExternalSync.scheduleSync(reason); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8252 | } |
| 8253 | } |
| 8254 | |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame^] | 8255 | private void scheduleSyncExternalWifiStatsLocked(String reason) { |
| 8256 | if (mExternalSync != null) { |
| 8257 | mExternalSync.scheduleWifiSync(reason); |
| 8258 | } |
| 8259 | } |
| 8260 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8261 | // 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] | 8262 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8263 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8264 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8265 | int temp, int volt) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8266 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 8267 | final long uptime = SystemClock.uptimeMillis(); |
| 8268 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8269 | if (!mHaveBatteryLevel) { |
| 8270 | mHaveBatteryLevel = true; |
| 8271 | // We start out assuming that the device is plugged in (not |
| 8272 | // on battery). If our first report is now that we are indeed |
| 8273 | // plugged in, then twiddle our state to correctly reflect that |
| 8274 | // since we won't be going through the full setOnBattery(). |
| 8275 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8276 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8277 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8278 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8279 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8280 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8281 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8282 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8283 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8284 | mHistoryCur.batteryStatus = (byte)status; |
| 8285 | mHistoryCur.batteryLevel = (byte)level; |
| 8286 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 8287 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8288 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8289 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 8290 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 8291 | } |
| 8292 | int oldStatus = mHistoryCur.batteryStatus; |
| 8293 | if (onBattery) { |
| 8294 | mDischargeCurrentLevel = level; |
| 8295 | if (!mRecordingHistory) { |
| 8296 | mRecordingHistory = true; |
| 8297 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 8298 | } |
| 8299 | } else if (level < 96) { |
| 8300 | if (!mRecordingHistory) { |
| 8301 | mRecordingHistory = true; |
| 8302 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8303 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8304 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8305 | mCurrentBatteryLevel = level; |
| 8306 | if (mDischargePlugLevel < 0) { |
| 8307 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8308 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8309 | if (onBattery != mOnBattery) { |
| 8310 | mHistoryCur.batteryLevel = (byte)level; |
| 8311 | mHistoryCur.batteryStatus = (byte)status; |
| 8312 | mHistoryCur.batteryHealth = (byte)health; |
| 8313 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8314 | mHistoryCur.batteryTemperature = (short)temp; |
| 8315 | mHistoryCur.batteryVoltage = (char)volt; |
| 8316 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 8317 | } else { |
| 8318 | boolean changed = false; |
| 8319 | if (mHistoryCur.batteryLevel != level) { |
| 8320 | mHistoryCur.batteryLevel = (byte)level; |
| 8321 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8322 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8323 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 8324 | // which will pull external stats. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8325 | scheduleSyncExternalStatsLocked("battery-level"); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8326 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8327 | if (mHistoryCur.batteryStatus != status) { |
| 8328 | mHistoryCur.batteryStatus = (byte)status; |
| 8329 | changed = true; |
| 8330 | } |
| 8331 | if (mHistoryCur.batteryHealth != health) { |
| 8332 | mHistoryCur.batteryHealth = (byte)health; |
| 8333 | changed = true; |
| 8334 | } |
| 8335 | if (mHistoryCur.batteryPlugType != plugType) { |
| 8336 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8337 | changed = true; |
| 8338 | } |
| 8339 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 8340 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 8341 | mHistoryCur.batteryTemperature = (short)temp; |
| 8342 | changed = true; |
| 8343 | } |
| 8344 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 8345 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 8346 | mHistoryCur.batteryVoltage = (char)volt; |
| 8347 | changed = true; |
| 8348 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8349 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 8350 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 8351 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 8352 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8353 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8354 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 8355 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8356 | modeBits, elapsedRealtime); |
| 8357 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8358 | modeBits, elapsedRealtime); |
| 8359 | mLastDischargeStepLevel = level; |
| 8360 | mMinDischargeStepLevel = level; |
| 8361 | mInitStepMode = mCurStepMode; |
| 8362 | mModStepMode = 0; |
| 8363 | } |
| 8364 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8365 | if (level >= 90) { |
| 8366 | // If the battery level is at least 90%, always consider the device to be |
| 8367 | // charging even if it happens to go down a level. |
| 8368 | changed |= setChargingLocked(true); |
| 8369 | mLastChargeStepLevel = level; |
| 8370 | } if (!mCharging) { |
| 8371 | if (mLastChargeStepLevel < level) { |
| 8372 | // We have not reporting that we are charging, but the level has now |
| 8373 | // gone up, so consider the state to be charging. |
| 8374 | changed |= setChargingLocked(true); |
| 8375 | mLastChargeStepLevel = level; |
| 8376 | } |
| 8377 | } else { |
| 8378 | if (mLastChargeStepLevel > level) { |
| 8379 | // We had reported that the device was charging, but here we are with |
| 8380 | // power connected and the level going down. Looks like the current |
| 8381 | // power supplied isn't enough, so consider the device to now be |
| 8382 | // discharging. |
| 8383 | changed |= setChargingLocked(false); |
| 8384 | mLastChargeStepLevel = level; |
| 8385 | } |
| 8386 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8387 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 8388 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8389 | modeBits, elapsedRealtime); |
| 8390 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8391 | modeBits, elapsedRealtime); |
| 8392 | mLastChargeStepLevel = level; |
| 8393 | mMaxChargeStepLevel = level; |
| 8394 | mInitStepMode = mCurStepMode; |
| 8395 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8396 | } |
| 8397 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8398 | if (changed) { |
| 8399 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 8400 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8401 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8402 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 8403 | // We don't record history while we are plugged in and fully charged. |
| 8404 | // The next time we are unplugged, history will be cleared. |
| 8405 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 8406 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8407 | } |
| 8408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8409 | public long getAwakeTimeBattery() { |
| 8410 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 8411 | } |
| 8412 | |
| 8413 | public long getAwakeTimePlugged() { |
| 8414 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 8415 | } |
| 8416 | |
| 8417 | @Override |
| 8418 | public long computeUptime(long curTime, int which) { |
| 8419 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8420 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8421 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8422 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8423 | } |
| 8424 | return 0; |
| 8425 | } |
| 8426 | |
| 8427 | @Override |
| 8428 | public long computeRealtime(long curTime, int which) { |
| 8429 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8430 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8432 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8433 | } |
| 8434 | return 0; |
| 8435 | } |
| 8436 | |
| 8437 | @Override |
| 8438 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8439 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | } |
| 8441 | |
| 8442 | @Override |
| 8443 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8444 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8445 | } |
| 8446 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8447 | @Override |
| 8448 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 8449 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 8450 | } |
| 8451 | |
| 8452 | @Override |
| 8453 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 8454 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | } |
| 8456 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8457 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 8458 | // For now we'll do a simple average across all steps. |
| 8459 | if (numSteps <= 0) { |
| 8460 | return -1; |
| 8461 | } |
| 8462 | long total = 0; |
| 8463 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8464 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8465 | } |
| 8466 | return total / numSteps; |
| 8467 | /* |
| 8468 | long[] buckets = new long[numSteps]; |
| 8469 | int numBuckets = 0; |
| 8470 | int numToAverage = 4; |
| 8471 | int i = 0; |
| 8472 | while (i < numSteps) { |
| 8473 | long totalTime = 0; |
| 8474 | int num = 0; |
| 8475 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8476 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8477 | num++; |
| 8478 | } |
| 8479 | buckets[numBuckets] = totalTime / num; |
| 8480 | numBuckets++; |
| 8481 | numToAverage *= 2; |
| 8482 | i += num; |
| 8483 | } |
| 8484 | if (numBuckets < 1) { |
| 8485 | return -1; |
| 8486 | } |
| 8487 | long averageTime = buckets[numBuckets-1]; |
| 8488 | for (i=numBuckets-2; i>=0; i--) { |
| 8489 | averageTime = (averageTime + buckets[i]) / 2; |
| 8490 | } |
| 8491 | return averageTime; |
| 8492 | */ |
| 8493 | } |
| 8494 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8495 | @Override |
| 8496 | public long computeBatteryTimeRemaining(long curTime) { |
| 8497 | if (!mOnBattery) { |
| 8498 | return -1; |
| 8499 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8500 | /* Simple implementation just looks at the average discharge per level across the |
| 8501 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8502 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 8503 | if (discharge < 2) { |
| 8504 | return -1; |
| 8505 | } |
| 8506 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 8507 | if (duration < 1000*1000) { |
| 8508 | return -1; |
| 8509 | } |
| 8510 | long usPerLevel = duration/discharge; |
| 8511 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8512 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8513 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8514 | return -1; |
| 8515 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8516 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8517 | if (msPerLevel <= 0) { |
| 8518 | return -1; |
| 8519 | } |
| 8520 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8521 | } |
| 8522 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8523 | @Override |
| 8524 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 8525 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8528 | @Override |
| 8529 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 8530 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8531 | } |
| 8532 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8533 | @Override |
| 8534 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8535 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8536 | // Not yet working. |
| 8537 | return -1; |
| 8538 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8539 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8540 | int curLevel = mCurrentBatteryLevel; |
| 8541 | int plugLevel = mDischargePlugLevel; |
| 8542 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 8543 | return -1; |
| 8544 | } |
| 8545 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 8546 | if (duration < 1000*1000) { |
| 8547 | return -1; |
| 8548 | } |
| 8549 | long usPerLevel = duration/(curLevel-plugLevel); |
| 8550 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8551 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8552 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8553 | return -1; |
| 8554 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8555 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8556 | if (msPerLevel <= 0) { |
| 8557 | return -1; |
| 8558 | } |
| 8559 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8560 | } |
| 8561 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8562 | @Override |
| 8563 | public LevelStepTracker getChargeLevelStepTracker() { |
| 8564 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8565 | } |
| 8566 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8567 | @Override |
| 8568 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 8569 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8570 | } |
| 8571 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8572 | @Override |
| 8573 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 8574 | return mDailyPackageChanges; |
| 8575 | } |
| 8576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8577 | long getBatteryUptimeLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8578 | return mOnBatteryTimeBase.getUptime(SystemClock.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8579 | } |
| 8580 | |
| 8581 | @Override |
| 8582 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8583 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8584 | } |
| 8585 | |
| 8586 | @Override |
| 8587 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8588 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8589 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 8590 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8591 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8592 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8593 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8594 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8595 | } |
| 8596 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8597 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8598 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8599 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8600 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8601 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8602 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8603 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8604 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8605 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8606 | } |
| 8607 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8608 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8609 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8610 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8611 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8613 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8614 | public int getLowDischargeAmountSinceCharge() { |
| 8615 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8616 | int val = mLowDischargeAmountSinceCharge; |
| 8617 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8618 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 8619 | } |
| 8620 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8621 | } |
| 8622 | } |
| 8623 | |
| 8624 | @Override |
| 8625 | public int getHighDischargeAmountSinceCharge() { |
| 8626 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8627 | int val = mHighDischargeAmountSinceCharge; |
| 8628 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8629 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 8630 | } |
| 8631 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8632 | } |
| 8633 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8634 | |
| 8635 | @Override |
| 8636 | public int getDischargeAmount(int which) { |
| 8637 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 8638 | ? getHighDischargeAmountSinceCharge() |
| 8639 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 8640 | if (dischargeAmount < 0) { |
| 8641 | dischargeAmount = 0; |
| 8642 | } |
| 8643 | return dischargeAmount; |
| 8644 | } |
| 8645 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8646 | public int getDischargeAmountScreenOn() { |
| 8647 | synchronized(this) { |
| 8648 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8649 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8650 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8651 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8652 | } |
| 8653 | return val; |
| 8654 | } |
| 8655 | } |
| 8656 | |
| 8657 | public int getDischargeAmountScreenOnSinceCharge() { |
| 8658 | synchronized(this) { |
| 8659 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8660 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8661 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8662 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8663 | } |
| 8664 | return val; |
| 8665 | } |
| 8666 | } |
| 8667 | |
| 8668 | public int getDischargeAmountScreenOff() { |
| 8669 | synchronized(this) { |
| 8670 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8671 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8672 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8673 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8674 | } |
| 8675 | return val; |
| 8676 | } |
| 8677 | } |
| 8678 | |
| 8679 | public int getDischargeAmountScreenOffSinceCharge() { |
| 8680 | synchronized(this) { |
| 8681 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8682 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8683 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8684 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8685 | } |
| 8686 | return val; |
| 8687 | } |
| 8688 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8689 | |
| 8690 | @Override |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8691 | public int getCpuSpeedSteps() { |
| 8692 | return sNumSpeedSteps; |
| 8693 | } |
| 8694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8695 | /** |
| 8696 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 8697 | */ |
| 8698 | public Uid getUidStatsLocked(int uid) { |
| 8699 | Uid u = mUidStats.get(uid); |
| 8700 | if (u == null) { |
| 8701 | u = new Uid(uid); |
| 8702 | mUidStats.put(uid, u); |
| 8703 | } |
| 8704 | return u; |
| 8705 | } |
| 8706 | |
| 8707 | /** |
| 8708 | * Remove the statistics object for a particular uid. |
| 8709 | */ |
| 8710 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 8711 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8712 | mUidStats.remove(uid); |
| 8713 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 8714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8715 | /** |
| 8716 | * Retrieve the statistics object for a particular process, creating |
| 8717 | * if needed. |
| 8718 | */ |
| 8719 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8720 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8721 | Uid u = getUidStatsLocked(uid); |
| 8722 | return u.getProcessStatsLocked(name); |
| 8723 | } |
| 8724 | |
| 8725 | /** |
| 8726 | * Retrieve the statistics object for a particular process, creating |
| 8727 | * if needed. |
| 8728 | */ |
| 8729 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8730 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | Uid u = getUidStatsLocked(uid); |
| 8732 | return u.getPackageStatsLocked(pkg); |
| 8733 | } |
| 8734 | |
| 8735 | /** |
| 8736 | * Retrieve the statistics object for a particular service, creating |
| 8737 | * if needed. |
| 8738 | */ |
| 8739 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8740 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8741 | Uid u = getUidStatsLocked(uid); |
| 8742 | return u.getServiceStatsLocked(pkg, name); |
| 8743 | } |
| 8744 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8745 | public void shutdownLocked() { |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8746 | recordShutdownLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8747 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8748 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8749 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8750 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8751 | Parcel mPendingWrite = null; |
| 8752 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 8753 | |
| 8754 | public void writeAsyncLocked() { |
| 8755 | writeLocked(false); |
| 8756 | } |
| 8757 | |
| 8758 | public void writeSyncLocked() { |
| 8759 | writeLocked(true); |
| 8760 | } |
| 8761 | |
| 8762 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8763 | if (mFile == null) { |
| 8764 | 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] | 8765 | return; |
| 8766 | } |
| 8767 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8768 | if (mShuttingDown) { |
| 8769 | return; |
| 8770 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8771 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8772 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8773 | writeSummaryToParcel(out, true); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8774 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 8775 | |
| 8776 | if (mPendingWrite != null) { |
| 8777 | mPendingWrite.recycle(); |
| 8778 | } |
| 8779 | mPendingWrite = out; |
| 8780 | |
| 8781 | if (sync) { |
| 8782 | commitPendingDataToDisk(); |
| 8783 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8784 | BackgroundThread.getHandler().post(new Runnable() { |
| 8785 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8786 | commitPendingDataToDisk(); |
| 8787 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8788 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8789 | } |
| 8790 | } |
| 8791 | |
| 8792 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 8793 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8794 | synchronized (this) { |
| 8795 | next = mPendingWrite; |
| 8796 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 8797 | if (next == null) { |
| 8798 | return; |
| 8799 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8800 | |
| 8801 | mWriteLock.lock(); |
| 8802 | } |
| 8803 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8804 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8805 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8806 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8807 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 8808 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8809 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8810 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8811 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8812 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8813 | mFile.rollback(); |
| 8814 | } finally { |
| 8815 | next.recycle(); |
| 8816 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8817 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8818 | } |
| 8819 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8820 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8821 | if (mDailyFile != null) { |
| 8822 | readDailyStatsLocked(); |
| 8823 | } |
| 8824 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8825 | if (mFile == null) { |
| 8826 | 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] | 8827 | return; |
| 8828 | } |
| 8829 | |
| 8830 | mUidStats.clear(); |
| 8831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8832 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8833 | File file = mFile.chooseForRead(); |
| 8834 | if (!file.exists()) { |
| 8835 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8836 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8837 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8838 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8839 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8840 | Parcel in = Parcel.obtain(); |
| 8841 | in.unmarshall(raw, 0, raw.length); |
| 8842 | in.setDataPosition(0); |
| 8843 | stream.close(); |
| 8844 | |
| 8845 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 8846 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8847 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8848 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8849 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8850 | mEndPlatformVersion = Build.ID; |
| 8851 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8852 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8853 | mRecordingHistory = true; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8854 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8855 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8856 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8857 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8858 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8859 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 8860 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8861 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8862 | |
| 8863 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | public int describeContents() { |
| 8867 | return 0; |
| 8868 | } |
| 8869 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8870 | void readHistory(Parcel in, boolean andOldHistory) { |
| 8871 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8872 | |
| 8873 | mHistoryBuffer.setDataSize(0); |
| 8874 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8875 | mHistoryTagPool.clear(); |
| 8876 | mNextHistoryTagIdx = 0; |
| 8877 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8878 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8879 | int numTags = in.readInt(); |
| 8880 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8881 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8882 | String str = in.readString(); |
| 8883 | int uid = in.readInt(); |
| 8884 | HistoryTag tag = new HistoryTag(); |
| 8885 | tag.string = str; |
| 8886 | tag.uid = uid; |
| 8887 | tag.poolIdx = idx; |
| 8888 | mHistoryTagPool.put(tag, idx); |
| 8889 | if (idx >= mNextHistoryTagIdx) { |
| 8890 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8891 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8892 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8893 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8894 | |
| 8895 | int bufSize = in.readInt(); |
| 8896 | int curPos = in.dataPosition(); |
| 8897 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
| 8898 | Slog.w(TAG, "File corrupt: history data buffer too large " + bufSize); |
| 8899 | } else if ((bufSize&~3) != bufSize) { |
| 8900 | Slog.w(TAG, "File corrupt: history data buffer not aligned " + bufSize); |
| 8901 | } else { |
| 8902 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 8903 | + " bytes at " + curPos); |
| 8904 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 8905 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8906 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8907 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8908 | if (andOldHistory) { |
| 8909 | readOldHistory(in); |
| 8910 | } |
| 8911 | |
| 8912 | if (DEBUG_HISTORY) { |
| 8913 | StringBuilder sb = new StringBuilder(128); |
| 8914 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 8915 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8916 | Slog.i(TAG, sb.toString()); |
| 8917 | } |
| 8918 | mHistoryBaseTime = historyBaseTime; |
| 8919 | if (DEBUG_HISTORY) { |
| 8920 | StringBuilder sb = new StringBuilder(128); |
| 8921 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 8922 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8923 | Slog.i(TAG, sb.toString()); |
| 8924 | } |
| 8925 | |
| 8926 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 8927 | // the last run until samples in this run. |
| 8928 | if (mHistoryBaseTime > 0) { |
| 8929 | long oldnow = SystemClock.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8930 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8931 | if (DEBUG_HISTORY) { |
| 8932 | StringBuilder sb = new StringBuilder(128); |
| 8933 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 8934 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 8935 | Slog.i(TAG, sb.toString()); |
| 8936 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 8937 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8938 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8939 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8940 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8941 | if (!USE_OLD_HISTORY) { |
| 8942 | return; |
| 8943 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8944 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 8945 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 8946 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8947 | HistoryItem rec = new HistoryItem(time, in); |
| 8948 | addHistoryRecordLocked(rec); |
| 8949 | } |
| 8950 | } |
| 8951 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8952 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8953 | if (DEBUG_HISTORY) { |
| 8954 | StringBuilder sb = new StringBuilder(128); |
| 8955 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 8956 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8957 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 8958 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8959 | Slog.i(TAG, sb.toString()); |
| 8960 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8961 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8962 | if (!inclData) { |
| 8963 | out.writeInt(0); |
| 8964 | out.writeInt(0); |
| 8965 | return; |
| 8966 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8967 | out.writeInt(mHistoryTagPool.size()); |
| 8968 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8969 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8970 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8971 | out.writeString(tag.string); |
| 8972 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8973 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8974 | out.writeInt(mHistoryBuffer.dataSize()); |
| 8975 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 8976 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 8977 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 8978 | |
| 8979 | if (andOldHistory) { |
| 8980 | writeOldHistory(out); |
| 8981 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8982 | } |
| 8983 | |
| 8984 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 8985 | if (!USE_OLD_HISTORY) { |
| 8986 | return; |
| 8987 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8988 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8989 | while (rec != null) { |
| 8990 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 8991 | rec = rec.next; |
| 8992 | } |
| 8993 | out.writeLong(-1); |
| 8994 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8995 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8996 | public void readSummaryFromParcel(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8997 | final int version = in.readInt(); |
| 8998 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8999 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | + ", expected " + VERSION + "; erasing old stats"); |
| 9001 | return; |
| 9002 | } |
| 9003 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9004 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9006 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9007 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9008 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9009 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9010 | mStartPlatformVersion = in.readString(); |
| 9011 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9012 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 9013 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9014 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9015 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9016 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9017 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9018 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9019 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9020 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9021 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9022 | mDischargeStepTracker.readFromParcel(in); |
| 9023 | mChargeStepTracker.readFromParcel(in); |
| 9024 | mDailyDischargeStepTracker.readFromParcel(in); |
| 9025 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9026 | int NPKG = in.readInt(); |
| 9027 | if (NPKG > 0) { |
| 9028 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 9029 | while (NPKG > 0) { |
| 9030 | NPKG--; |
| 9031 | PackageChange pc = new PackageChange(); |
| 9032 | pc.mPackageName = in.readString(); |
| 9033 | pc.mUpdate = in.readInt() != 0; |
| 9034 | pc.mVersionCode = in.readInt(); |
| 9035 | mDailyPackageChanges.add(pc); |
| 9036 | } |
| 9037 | } else { |
| 9038 | mDailyPackageChanges = null; |
| 9039 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9040 | mDailyStartTime = in.readLong(); |
| 9041 | mNextMinDailyDeadline = in.readLong(); |
| 9042 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9045 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9046 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9047 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9048 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9049 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 9050 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9051 | mInteractive = false; |
| 9052 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9053 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9054 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
| 9055 | mDeviceIdleModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9056 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9057 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9058 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9059 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9060 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 9061 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9062 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9063 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 9064 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9065 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9066 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9067 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9068 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9069 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9070 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9071 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9072 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9073 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 9074 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9075 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9076 | mWifiOn = false; |
| 9077 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9078 | mGlobalWifiRunning = false; |
| 9079 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9080 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9081 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 9082 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9083 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9084 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 9085 | } |
| 9086 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9087 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9088 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9089 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9090 | mBluetoothActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9091 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9092 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9093 | mWifiActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9094 | } |
| 9095 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9096 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9097 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9098 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9099 | mCameraOnNesting = 0; |
| 9100 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9102 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9103 | if (NKW > 10000) { |
| 9104 | Slog.w(TAG, "File corrupt: too many kernel wake locks " + NKW); |
| 9105 | return; |
| 9106 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9107 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 9108 | if (in.readInt() != 0) { |
| 9109 | String kwltName = in.readString(); |
| 9110 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 9111 | } |
| 9112 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9113 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9114 | int NWR = in.readInt(); |
| 9115 | if (NWR > 10000) { |
| 9116 | Slog.w(TAG, "File corrupt: too many wakeup reasons " + NWR); |
| 9117 | return; |
| 9118 | } |
| 9119 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 9120 | if (in.readInt() != 0) { |
| 9121 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9122 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9123 | } |
| 9124 | } |
| 9125 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9126 | sNumSpeedSteps = in.readInt(); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 9127 | if (sNumSpeedSteps < 0 || sNumSpeedSteps > 100) { |
| 9128 | throw new BadParcelableException("Bad speed steps in data: " + sNumSpeedSteps); |
| 9129 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9131 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9132 | if (NU > 10000) { |
| 9133 | Slog.w(TAG, "File corrupt: too many uids " + NU); |
| 9134 | return; |
| 9135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9136 | for (int iu = 0; iu < NU; iu++) { |
| 9137 | int uid = in.readInt(); |
| 9138 | Uid u = new Uid(uid); |
| 9139 | mUidStats.put(uid, u); |
| 9140 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9141 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9142 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9143 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9144 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9145 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9146 | if (in.readInt() != 0) { |
| 9147 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 9148 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9149 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9150 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9151 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9152 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9153 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 9154 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9155 | if (in.readInt() != 0) { |
| 9156 | u.makeWifiBatchedScanBin(i, null); |
| 9157 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 9158 | } |
| 9159 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9160 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9161 | if (in.readInt() != 0) { |
| 9162 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 9163 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9164 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9165 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9166 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9167 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9168 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9169 | } |
| 9170 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9171 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9172 | } |
| 9173 | if (in.readInt() != 0) { |
| 9174 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9175 | } |
| 9176 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9177 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 9178 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9179 | u.mProcessState = Uid.PROCESS_STATE_NONE; |
| 9180 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9181 | if (in.readInt() != 0) { |
| 9182 | u.makeProcessState(i, null); |
| 9183 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 9184 | } |
| 9185 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9186 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9187 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9188 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9189 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9190 | if (in.readInt() != 0) { |
| 9191 | if (u.mUserActivityCounters == null) { |
| 9192 | u.initUserActivityLocked(); |
| 9193 | } |
| 9194 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9195 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9196 | } |
| 9197 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9198 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9199 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9200 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9201 | u.initNetworkActivityLocked(); |
| 9202 | } |
| 9203 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9204 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9205 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9206 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9207 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 9208 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9209 | } |
| 9210 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9211 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 9212 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 9213 | |
| 9214 | int NSB = in.readInt(); |
| 9215 | if (NSB > 100) { |
| 9216 | Slog.w(TAG, "File corrupt: too many speed bins " + NSB); |
| 9217 | return; |
| 9218 | } |
| 9219 | |
| 9220 | u.mSpeedBins = new LongSamplingCounter[NSB]; |
| 9221 | for (int i=0; i<NSB; i++) { |
| 9222 | if (in.readInt() != 0) { |
| 9223 | u.mSpeedBins[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 9224 | u.mSpeedBins[i].readSummaryFromParcelLocked(in); |
| 9225 | } |
| 9226 | } |
| 9227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9228 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9229 | if (NW > 100) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9230 | Slog.w(TAG, "File corrupt: too many wake locks " + NW); |
| 9231 | return; |
| 9232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9233 | for (int iw = 0; iw < NW; iw++) { |
| 9234 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9235 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9236 | } |
| 9237 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9238 | int NS = in.readInt(); |
| 9239 | if (NS > 100) { |
| 9240 | Slog.w(TAG, "File corrupt: too many syncs " + NS); |
| 9241 | return; |
| 9242 | } |
| 9243 | for (int is = 0; is < NS; is++) { |
| 9244 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9245 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9246 | } |
| 9247 | |
| 9248 | int NJ = in.readInt(); |
| 9249 | if (NJ > 100) { |
| 9250 | Slog.w(TAG, "File corrupt: too many job timers " + NJ); |
| 9251 | return; |
| 9252 | } |
| 9253 | for (int ij = 0; ij < NJ; ij++) { |
| 9254 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9255 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9256 | } |
| 9257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9259 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9260 | Slog.w(TAG, "File corrupt: too many sensors " + NP); |
| 9261 | return; |
| 9262 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9263 | for (int is = 0; is < NP; is++) { |
| 9264 | int seNumber = in.readInt(); |
| 9265 | if (in.readInt() != 0) { |
| 9266 | u.getSensorTimerLocked(seNumber, true) |
| 9267 | .readSummaryFromParcelLocked(in); |
| 9268 | } |
| 9269 | } |
| 9270 | |
| 9271 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9272 | if (NP > 1000) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9273 | Slog.w(TAG, "File corrupt: too many processes " + NP); |
| 9274 | return; |
| 9275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9276 | for (int ip = 0; ip < NP; ip++) { |
| 9277 | String procName = in.readString(); |
| 9278 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 9279 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9280 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9281 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9282 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9283 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 9284 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9285 | if (!p.readExcessivePowerFromParcelLocked(in)) { |
| 9286 | return; |
| 9287 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9288 | } |
| 9289 | |
| 9290 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9291 | if (NP > 10000) { |
| 9292 | Slog.w(TAG, "File corrupt: too many packages " + NP); |
| 9293 | return; |
| 9294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9295 | for (int ip = 0; ip < NP; ip++) { |
| 9296 | String pkgName = in.readString(); |
| 9297 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9298 | final int NWA = in.readInt(); |
| 9299 | if (NWA > 1000) { |
| 9300 | Slog.w(TAG, "File corrupt: too many wakeup alarms " + NWA); |
| 9301 | return; |
| 9302 | } |
| 9303 | p.mWakeupAlarms.clear(); |
| 9304 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9305 | String tag = in.readString(); |
| 9306 | Counter c = new Counter(mOnBatteryTimeBase); |
| 9307 | c.readSummaryFromParcelLocked(in); |
| 9308 | p.mWakeupAlarms.put(tag, c); |
| 9309 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9310 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9311 | if (NS > 1000) { |
| 9312 | Slog.w(TAG, "File corrupt: too many services " + NS); |
| 9313 | return; |
| 9314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9315 | for (int is = 0; is < NS; is++) { |
| 9316 | String servName = in.readString(); |
| 9317 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 9318 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9319 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9321 | } |
| 9322 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9323 | } |
| 9324 | } |
| 9325 | |
| 9326 | /** |
| 9327 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 9328 | * disk. This format does not allow a lossless round-trip. |
| 9329 | * |
| 9330 | * @param out the Parcel to be written to. |
| 9331 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9332 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9333 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9334 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9335 | // Pull the clock time. This may update the time and make a new history entry |
| 9336 | // if we had originally pulled a time before the RTC was set. |
| 9337 | long startClockTime = getStartClockTime(); |
| 9338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 9340 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9341 | |
| 9342 | out.writeInt(VERSION); |
| 9343 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9344 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9347 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9348 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9349 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9350 | out.writeString(mStartPlatformVersion); |
| 9351 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9352 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 9353 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9354 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9355 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9356 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9357 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9358 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 9359 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9360 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 9361 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9362 | mDischargeStepTracker.writeToParcel(out); |
| 9363 | mChargeStepTracker.writeToParcel(out); |
| 9364 | mDailyDischargeStepTracker.writeToParcel(out); |
| 9365 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9366 | if (mDailyPackageChanges != null) { |
| 9367 | final int NPKG = mDailyPackageChanges.size(); |
| 9368 | out.writeInt(NPKG); |
| 9369 | for (int i=0; i<NPKG; i++) { |
| 9370 | PackageChange pc = mDailyPackageChanges.get(i); |
| 9371 | out.writeString(pc.mPackageName); |
| 9372 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 9373 | out.writeInt(pc.mVersionCode); |
| 9374 | } |
| 9375 | } else { |
| 9376 | out.writeInt(0); |
| 9377 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9378 | out.writeLong(mDailyStartTime); |
| 9379 | out.writeLong(mNextMinDailyDeadline); |
| 9380 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9381 | |
| 9382 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9383 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9384 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9385 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9386 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9387 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9388 | mDeviceIdleModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9389 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9390 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9391 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9392 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9393 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9394 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9395 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9396 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9397 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9398 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9399 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9400 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9401 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9402 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9403 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9404 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9405 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 9406 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9407 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9408 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9409 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9410 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9411 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9412 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9413 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9414 | } |
| 9415 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9416 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9417 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9418 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9419 | mBluetoothActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9420 | } |
| 9421 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9422 | mWifiActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9423 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9424 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9425 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9426 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9427 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9428 | out.writeInt(mKernelWakelockStats.size()); |
| 9429 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9430 | Timer kwlt = ent.getValue(); |
| 9431 | if (kwlt != null) { |
| 9432 | out.writeInt(1); |
| 9433 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9434 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9435 | } else { |
| 9436 | out.writeInt(0); |
| 9437 | } |
| 9438 | } |
| 9439 | |
| 9440 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9441 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9442 | SamplingTimer timer = ent.getValue(); |
| 9443 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9444 | out.writeInt(1); |
| 9445 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9446 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9447 | } else { |
| 9448 | out.writeInt(0); |
| 9449 | } |
| 9450 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9451 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9452 | out.writeInt(sNumSpeedSteps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | final int NU = mUidStats.size(); |
| 9454 | out.writeInt(NU); |
| 9455 | for (int iu = 0; iu < NU; iu++) { |
| 9456 | out.writeInt(mUidStats.keyAt(iu)); |
| 9457 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9458 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9459 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9460 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9461 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9462 | } else { |
| 9463 | out.writeInt(0); |
| 9464 | } |
| 9465 | if (u.mFullWifiLockTimer != null) { |
| 9466 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9467 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9468 | } else { |
| 9469 | out.writeInt(0); |
| 9470 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9471 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9472 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9473 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9474 | } else { |
| 9475 | out.writeInt(0); |
| 9476 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9477 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9478 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 9479 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9480 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9481 | } else { |
| 9482 | out.writeInt(0); |
| 9483 | } |
| 9484 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9485 | if (u.mWifiMulticastTimer != null) { |
| 9486 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9487 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9488 | } else { |
| 9489 | out.writeInt(0); |
| 9490 | } |
| 9491 | if (u.mAudioTurnedOnTimer != null) { |
| 9492 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9493 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9494 | } else { |
| 9495 | out.writeInt(0); |
| 9496 | } |
| 9497 | if (u.mVideoTurnedOnTimer != null) { |
| 9498 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9499 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9500 | } else { |
| 9501 | out.writeInt(0); |
| 9502 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9503 | if (u.mFlashlightTurnedOnTimer != null) { |
| 9504 | out.writeInt(1); |
| 9505 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9506 | } else { |
| 9507 | out.writeInt(0); |
| 9508 | } |
| 9509 | if (u.mCameraTurnedOnTimer != null) { |
| 9510 | out.writeInt(1); |
| 9511 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9512 | } else { |
| 9513 | out.writeInt(0); |
| 9514 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9515 | if (u.mForegroundActivityTimer != null) { |
| 9516 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9517 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9518 | } else { |
| 9519 | out.writeInt(0); |
| 9520 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9521 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9522 | if (u.mProcessStateTimer[i] != null) { |
| 9523 | out.writeInt(1); |
| 9524 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9525 | } else { |
| 9526 | out.writeInt(0); |
| 9527 | } |
| 9528 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9529 | if (u.mVibratorOnTimer != null) { |
| 9530 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9531 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9532 | } else { |
| 9533 | out.writeInt(0); |
| 9534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9535 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9536 | if (u.mUserActivityCounters == null) { |
| 9537 | out.writeInt(0); |
| 9538 | } else { |
| 9539 | out.writeInt(1); |
| 9540 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9541 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9542 | } |
| 9543 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9544 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9545 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9546 | out.writeInt(0); |
| 9547 | } else { |
| 9548 | out.writeInt(1); |
| 9549 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9550 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9551 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9552 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9553 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 9554 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9555 | } |
| 9556 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9557 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 9558 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 9559 | |
| 9560 | out.writeInt(u.mSpeedBins.length); |
| 9561 | for (int i = 0; i < u.mSpeedBins.length; i++) { |
| 9562 | LongSamplingCounter speedBin = u.mSpeedBins[i]; |
| 9563 | if (speedBin != null) { |
| 9564 | out.writeInt(1); |
| 9565 | speedBin.writeSummaryFromParcelLocked(out); |
| 9566 | } else { |
| 9567 | out.writeInt(0); |
| 9568 | } |
| 9569 | } |
| 9570 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9571 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 9572 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9573 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9574 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9575 | out.writeString(wakeStats.keyAt(iw)); |
| 9576 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9577 | if (wl.mTimerFull != null) { |
| 9578 | out.writeInt(1); |
| 9579 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9580 | } else { |
| 9581 | out.writeInt(0); |
| 9582 | } |
| 9583 | if (wl.mTimerPartial != null) { |
| 9584 | out.writeInt(1); |
| 9585 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9586 | } else { |
| 9587 | out.writeInt(0); |
| 9588 | } |
| 9589 | if (wl.mTimerWindow != null) { |
| 9590 | out.writeInt(1); |
| 9591 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9592 | } else { |
| 9593 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9594 | } |
| 9595 | } |
| 9596 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9597 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 9598 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9599 | out.writeInt(NS); |
| 9600 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9601 | out.writeString(syncStats.keyAt(is)); |
| 9602 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9603 | } |
| 9604 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9605 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 9606 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9607 | out.writeInt(NJ); |
| 9608 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9609 | out.writeString(jobStats.keyAt(ij)); |
| 9610 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9611 | } |
| 9612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | int NSE = u.mSensorStats.size(); |
| 9614 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9615 | for (int ise=0; ise<NSE; ise++) { |
| 9616 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 9617 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 9618 | if (se.mTimer != null) { |
| 9619 | out.writeInt(1); |
| 9620 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9621 | } else { |
| 9622 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9623 | } |
| 9624 | } |
| 9625 | |
| 9626 | int NP = u.mProcessStats.size(); |
| 9627 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9628 | for (int ip=0; ip<NP; ip++) { |
| 9629 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 9630 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 9631 | out.writeLong(ps.mUserTime); |
| 9632 | out.writeLong(ps.mSystemTime); |
| 9633 | out.writeLong(ps.mForegroundTime); |
| 9634 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9635 | out.writeInt(ps.mNumCrashes); |
| 9636 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9637 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9638 | } |
| 9639 | |
| 9640 | NP = u.mPackageStats.size(); |
| 9641 | out.writeInt(NP); |
| 9642 | if (NP > 0) { |
| 9643 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 9644 | : u.mPackageStats.entrySet()) { |
| 9645 | out.writeString(ent.getKey()); |
| 9646 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9647 | final int NWA = ps.mWakeupAlarms.size(); |
| 9648 | out.writeInt(NWA); |
| 9649 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9650 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 9651 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 9652 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9653 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9654 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9655 | for (int is=0; is<NS; is++) { |
| 9656 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 9657 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 9658 | long time = ss.getStartTimeToNowLocked( |
| 9659 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 9660 | out.writeLong(time); |
| 9661 | out.writeInt(ss.mStarts); |
| 9662 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9663 | } |
| 9664 | } |
| 9665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9666 | } |
| 9667 | } |
| 9668 | |
| 9669 | public void readFromParcel(Parcel in) { |
| 9670 | readFromParcelLocked(in); |
| 9671 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9673 | void readFromParcelLocked(Parcel in) { |
| 9674 | int magic = in.readInt(); |
| 9675 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9676 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9677 | } |
| 9678 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9679 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9682 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9683 | mStartPlatformVersion = in.readString(); |
| 9684 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9685 | mUptime = in.readLong(); |
| 9686 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9687 | mRealtime = in.readLong(); |
| 9688 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9689 | mOnBattery = in.readInt() != 0; |
| 9690 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9691 | mOnBatteryTimeBase.readFromParcel(in); |
| 9692 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 9693 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9694 | mScreenState = Display.STATE_UNKNOWN; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9695 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in); |
| 9696 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9697 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, |
| 9698 | in); |
| 9699 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9700 | mInteractive = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9701 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9702 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9703 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in); |
| 9704 | mDeviceIdleModeEnabledTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9705 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9706 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9707 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9708 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 9709 | null, mOnBatteryTimeBase, in); |
| 9710 | } |
| 9711 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase, in); |
| 9712 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9713 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 9714 | null, mOnBatteryTimeBase, in); |
| 9715 | } |
| 9716 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9717 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9718 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9719 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9720 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9721 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); |
| 9722 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, |
| 9723 | in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9724 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9725 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9726 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9727 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9728 | mWifiOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9729 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9730 | mGlobalWifiRunning = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9731 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9732 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9733 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, |
| 9734 | null, mOnBatteryTimeBase, in); |
| 9735 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9736 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9737 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, |
| 9738 | null, mOnBatteryTimeBase, in); |
| 9739 | } |
| 9740 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9741 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, |
| 9742 | null, mOnBatteryTimeBase, in); |
| 9743 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9744 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9745 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9746 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9747 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9748 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9749 | } |
| 9750 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9751 | mHasWifiEnergyReporting = in.readInt() != 0; |
| 9752 | mHasBluetoothEnergyReporting = in.readInt() != 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9753 | mNumConnectivityChange = in.readInt(); |
| 9754 | mLoadedNumConnectivityChange = in.readInt(); |
| 9755 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9756 | mAudioOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9757 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9758 | mVideoOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9759 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9760 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9761 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9762 | mCameraOnNesting = 0; |
| 9763 | mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9764 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9765 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9766 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9767 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9768 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9769 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9770 | mDischargeAmountScreenOn = in.readInt(); |
| 9771 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9772 | mDischargeAmountScreenOff = in.readInt(); |
| 9773 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9774 | mDischargeStepTracker.readFromParcel(in); |
| 9775 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9776 | mLastWriteTime = in.readLong(); |
| 9777 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9778 | mKernelWakelockStats.clear(); |
| 9779 | int NKW = in.readInt(); |
| 9780 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 9781 | if (in.readInt() != 0) { |
| 9782 | String wakelockName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9783 | SamplingTimer kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9784 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 9785 | } |
| 9786 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9787 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9788 | mWakeupReasonStats.clear(); |
| 9789 | int NWR = in.readInt(); |
| 9790 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 9791 | if (in.readInt() != 0) { |
| 9792 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9793 | SamplingTimer timer = new SamplingTimer(mOnBatteryTimeBase, in); |
| 9794 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9795 | } |
| 9796 | } |
| 9797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9798 | mPartialTimers.clear(); |
| 9799 | mFullTimers.clear(); |
| 9800 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9801 | mWifiRunningTimers.clear(); |
| 9802 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9803 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9804 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9805 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 9806 | mAudioTurnedOnTimers.clear(); |
| 9807 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9808 | mFlashlightTurnedOnTimers.clear(); |
| 9809 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9810 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9811 | sNumSpeedSteps = in.readInt(); |
| 9812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9813 | int numUids = in.readInt(); |
| 9814 | mUidStats.clear(); |
| 9815 | for (int i = 0; i < numUids; i++) { |
| 9816 | int uid = in.readInt(); |
| 9817 | Uid u = new Uid(uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9818 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9819 | mUidStats.append(uid, u); |
| 9820 | } |
| 9821 | } |
| 9822 | |
| 9823 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9824 | writeToParcelLocked(out, true, flags); |
| 9825 | } |
| 9826 | |
| 9827 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 9828 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9829 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9830 | |
| 9831 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9832 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9833 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9834 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9835 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9836 | // Pull the clock time. This may update the time and make a new history entry |
| 9837 | // if we had originally pulled a time before the RTC was set. |
| 9838 | long startClockTime = getStartClockTime(); |
| 9839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9840 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 9841 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9842 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 9843 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9845 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9846 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9847 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9849 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9850 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9851 | out.writeString(mStartPlatformVersion); |
| 9852 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9853 | out.writeLong(mUptime); |
| 9854 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9855 | out.writeLong(mRealtime); |
| 9856 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9857 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9858 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 9859 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 9860 | |
| 9861 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 9862 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9863 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 9864 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9865 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9866 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
| 9867 | mDeviceIdleModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9868 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9869 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 9870 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9871 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 9872 | } |
| 9873 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 9874 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9875 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 9876 | } |
| 9877 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9878 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 9879 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 9880 | } |
| 9881 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 9882 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9883 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9884 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 9885 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 9886 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 9887 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 9888 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9889 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9890 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9891 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9892 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 9893 | } |
| 9894 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9895 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 9896 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9897 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9898 | mBluetoothActivityCounters[i].writeToParcel(out); |
| 9899 | } |
| 9900 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9901 | mWifiActivityCounters[i].writeToParcel(out); |
| 9902 | } |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9903 | out.writeInt(mHasWifiEnergyReporting ? 1 : 0); |
| 9904 | out.writeInt(mHasBluetoothEnergyReporting ? 1 : 0); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9905 | out.writeInt(mNumConnectivityChange); |
| 9906 | out.writeInt(mLoadedNumConnectivityChange); |
| 9907 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9908 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9909 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9910 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9911 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9912 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9913 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9914 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 9915 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9916 | out.writeInt(mDischargeAmountScreenOn); |
| 9917 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 9918 | out.writeInt(mDischargeAmountScreenOff); |
| 9919 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9920 | mDischargeStepTracker.writeToParcel(out); |
| 9921 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | out.writeLong(mLastWriteTime); |
| 9923 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9924 | if (inclUids) { |
| 9925 | out.writeInt(mKernelWakelockStats.size()); |
| 9926 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9927 | SamplingTimer kwlt = ent.getValue(); |
| 9928 | if (kwlt != null) { |
| 9929 | out.writeInt(1); |
| 9930 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9931 | kwlt.writeToParcel(out, uSecRealtime); |
| 9932 | } else { |
| 9933 | out.writeInt(0); |
| 9934 | } |
| 9935 | } |
| 9936 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9937 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9938 | SamplingTimer timer = ent.getValue(); |
| 9939 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9940 | out.writeInt(1); |
| 9941 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9942 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9943 | } else { |
| 9944 | out.writeInt(0); |
| 9945 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9946 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9947 | } else { |
| 9948 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9949 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9950 | |
| 9951 | out.writeInt(sNumSpeedSteps); |
| 9952 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9953 | if (inclUids) { |
| 9954 | int size = mUidStats.size(); |
| 9955 | out.writeInt(size); |
| 9956 | for (int i = 0; i < size; i++) { |
| 9957 | out.writeInt(mUidStats.keyAt(i)); |
| 9958 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9959 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9960 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9961 | } |
| 9962 | } else { |
| 9963 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9964 | } |
| 9965 | } |
| 9966 | |
| 9967 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 9968 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 9969 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 9970 | return new BatteryStatsImpl(in); |
| 9971 | } |
| 9972 | |
| 9973 | public BatteryStatsImpl[] newArray(int size) { |
| 9974 | return new BatteryStatsImpl[size]; |
| 9975 | } |
| 9976 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9977 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9978 | public void prepareForDumpLocked() { |
| 9979 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9980 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9981 | |
| 9982 | // Pull the clock time. This may update the time and make a new history entry |
| 9983 | // if we had originally pulled a time before the RTC was set. |
| 9984 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9985 | } |
| 9986 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 9987 | 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] | 9988 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9989 | pw.println("mOnBatteryTimeBase:"); |
| 9990 | mOnBatteryTimeBase.dump(pw, " "); |
| 9991 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 9992 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9993 | Printer pr = new PrintWriterPrinter(pw); |
| 9994 | pr.println("*** Screen timer:"); |
| 9995 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9996 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9997 | pr.println("*** Screen brightness #" + i + ":"); |
| 9998 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9999 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10000 | pr.println("*** Interactive timer:"); |
| 10001 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10002 | pr.println("*** Power save mode timer:"); |
| 10003 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
| 10004 | pr.println("*** Device idle mode timer:"); |
| 10005 | mDeviceIdleModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10006 | pr.println("*** Device idling timer:"); |
| 10007 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10008 | pr.println("*** Phone timer:"); |
| 10009 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10010 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10011 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10012 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10013 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10014 | pr.println("*** Signal scanning :"); |
| 10015 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10016 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10017 | pr.println("*** Data connection type #" + i + ":"); |
| 10018 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10019 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10020 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10021 | pr.println("*** Mobile network active timer:"); |
| 10022 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10023 | pr.println("*** Mobile network active adjusted timer:"); |
| 10024 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10025 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10026 | pr.println("*** Wifi timer:"); |
| 10027 | mWifiOnTimer.logState(pr, " "); |
| 10028 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10029 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10030 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10031 | pr.println("*** Wifi state #" + i + ":"); |
| 10032 | mWifiStateTimer[i].logState(pr, " "); |
| 10033 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10034 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10035 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 10036 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 10037 | } |
| 10038 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10039 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 10040 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 10041 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10042 | pr.println("*** Flashlight timer:"); |
| 10043 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10044 | pr.println("*** Camera timer:"); |
| 10045 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10046 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 10047 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10048 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10049 | } |