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 | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 28 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 30 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 31 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 32 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 33 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 34 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.os.Parcel; |
| 36 | import android.os.ParcelFormatException; |
| 37 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 38 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 40 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 41 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 42 | import android.telephony.DataConnectionRealTimeInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 43 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 44 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 45 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 46 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 47 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 49 | import android.util.LogWriter; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 50 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 51 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 53 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 55 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 56 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 57 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 58 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 59 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 61 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 62 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 63 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 64 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 65 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 66 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 67 | import com.android.server.NetworkManagementSocketTagger; |
| 68 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 69 | import org.xmlpull.v1.XmlPullParser; |
| 70 | import org.xmlpull.v1.XmlPullParserException; |
| 71 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 72 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 73 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import java.io.File; |
| 75 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 76 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import java.io.FileOutputStream; |
| 78 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 79 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 80 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 82 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 84 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 86 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 87 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * All information we are collecting about things that can happen that impact |
| 91 | * battery life. All times are represented in microseconds except where indicated |
| 92 | * otherwise. |
| 93 | */ |
| 94 | public final class BatteryStatsImpl extends BatteryStats { |
| 95 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 96 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 97 | public static final boolean DEBUG_ENERGY = false; |
| 98 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY || false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 99 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 100 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 101 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 102 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | // In-memory Parcel magic number, used to detect attempts to unmarshall bad data |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 105 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
| 107 | // Current on-disk Parcel version |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 108 | private static final int VERSION = 135 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 109 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 110 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 111 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 112 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 113 | // No, really, THIS is the maximum number of items we will record in the history. |
| 114 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 115 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 116 | // The maximum number of names wakelocks we will keep track of |
| 117 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 118 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 119 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 120 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 121 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 122 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 123 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 125 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 126 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 127 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 128 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 129 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 130 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 131 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 132 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 133 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 134 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 135 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 136 | public interface BatteryCallback { |
| 137 | public void batteryNeedsCpuUpdate(); |
| 138 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 139 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 143 | public MyHandler(Looper looper) { |
| 144 | super(looper, null, true); |
| 145 | } |
| 146 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 147 | @Override |
| 148 | public void handleMessage(Message msg) { |
| 149 | BatteryCallback cb = mCallback; |
| 150 | switch (msg.what) { |
| 151 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 152 | synchronized (BatteryStatsImpl.this) { |
| 153 | updateCpuTimeLocked(); |
| 154 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 155 | if (cb != null) { |
| 156 | cb.batteryNeedsCpuUpdate(); |
| 157 | } |
| 158 | break; |
| 159 | case MSG_REPORT_POWER_CHANGE: |
| 160 | if (cb != null) { |
| 161 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 162 | } |
| 163 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 164 | case MSG_REPORT_CHARGING: |
| 165 | if (cb != null) { |
| 166 | final String action; |
| 167 | synchronized (BatteryStatsImpl.this) { |
| 168 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 169 | : BatteryManager.ACTION_DISCHARGING; |
| 170 | } |
| 171 | Intent intent = new Intent(action); |
| 172 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 173 | cb.batterySendBroadcast(intent); |
| 174 | } |
| 175 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 180 | public interface ExternalStatsSync { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 181 | void scheduleSync(String reason); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 182 | void scheduleWifiSync(String reason); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 183 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 186 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 187 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 188 | |
| 189 | private BatteryCallback mCallback; |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 192 | * Mapping isolated uids to the actual owning app uid. |
| 193 | */ |
| 194 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 195 | |
| 196 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | * The statistics we have collected organized by uids. |
| 198 | */ |
| 199 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = |
| 200 | new SparseArray<BatteryStatsImpl.Uid>(); |
| 201 | |
| 202 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 203 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 204 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 205 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 206 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 207 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 208 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 209 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 210 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 211 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 212 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 213 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 214 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 215 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 216 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 217 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 218 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 219 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 221 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 222 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | // These are the objects that will want to do something when the device |
| 225 | // is unplugged from power. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 226 | final TimeBase mOnBatteryTimeBase = new TimeBase(); |
| 227 | |
| 228 | // These are the objects that will want to do something when the device |
| 229 | // is unplugged from power *and* the screen is off. |
| 230 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 231 | |
| 232 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 233 | // CPU update, even if we aren't currently running wake locks. |
| 234 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 235 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 236 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 238 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 239 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 240 | long mHistoryBaseTime; |
| 241 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 242 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 243 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 244 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 245 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 246 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 247 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 248 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 249 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 250 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 251 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 252 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 253 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 254 | int[] mReadHistoryUids; |
| 255 | int mReadHistoryChars; |
| 256 | int mNextHistoryTagIdx = 0; |
| 257 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 258 | int mHistoryBufferLastPos = -1; |
| 259 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 260 | int mActiveHistoryStates = 0xffffffff; |
| 261 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 262 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 263 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 264 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 265 | |
| 266 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 267 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 268 | HistoryItem mHistory; |
| 269 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 270 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 271 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 272 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 273 | // Used by computeHistoryStepDetails |
| 274 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 275 | byte mLastHistoryStepLevel = 0; |
| 276 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 277 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 278 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 279 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 280 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 281 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 282 | */ |
| 283 | long mLastStepCpuUserTime; |
| 284 | long mCurStepCpuUserTime; |
| 285 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 286 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 287 | */ |
| 288 | long mLastStepCpuSystemTime; |
| 289 | long mCurStepCpuSystemTime; |
| 290 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 291 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 292 | */ |
| 293 | long mLastStepStatUserTime; |
| 294 | long mLastStepStatSystemTime; |
| 295 | long mLastStepStatIOWaitTime; |
| 296 | long mLastStepStatIrqTime; |
| 297 | long mLastStepStatSoftIrqTime; |
| 298 | long mLastStepStatIdleTime; |
| 299 | long mCurStepStatUserTime; |
| 300 | long mCurStepStatSystemTime; |
| 301 | long mCurStepStatIOWaitTime; |
| 302 | long mCurStepStatIrqTime; |
| 303 | long mCurStepStatSoftIrqTime; |
| 304 | long mCurStepStatIdleTime; |
| 305 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 306 | private HistoryItem mHistoryIterator; |
| 307 | private boolean mReadOverflow; |
| 308 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | int mStartCount; |
| 311 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 312 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 313 | String mStartPlatformVersion; |
| 314 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | long mUptime; |
| 317 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | long mRealtime; |
| 319 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 320 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 321 | int mWakeLockNesting; |
| 322 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 323 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 324 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 325 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 326 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 327 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 328 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 329 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 330 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 331 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 332 | boolean mInteractive; |
| 333 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 334 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 335 | boolean mPowerSaveModeEnabled; |
| 336 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 337 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 338 | boolean mDeviceIdling; |
| 339 | StopwatchTimer mDeviceIdlingTimer; |
| 340 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 341 | boolean mDeviceLightIdling; |
| 342 | StopwatchTimer mDeviceLightIdlingTimer; |
| 343 | |
| 344 | int mDeviceIdleMode; |
| 345 | long mLastIdleTimeStart; |
| 346 | long mLongestLightIdleTime; |
| 347 | long mLongestFullIdleTime; |
| 348 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 349 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 352 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 353 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 354 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 355 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 356 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 357 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 358 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 359 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 360 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 361 | StopwatchTimer mFlashlightOnTimer; |
| 362 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 363 | int mCameraOnNesting; |
| 364 | StopwatchTimer mCameraOnTimer; |
| 365 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 366 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 367 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 368 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 369 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 370 | |
| 371 | StopwatchTimer mPhoneSignalScanningTimer; |
| 372 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 373 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 374 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 375 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 376 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 377 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 378 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 379 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 380 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 381 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 382 | final LongSamplingCounter[] mBluetoothActivityCounters = |
| 383 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 384 | |
| 385 | final LongSamplingCounter[] mWifiActivityCounters = |
| 386 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 387 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 388 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 389 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 390 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 391 | boolean mGlobalWifiRunning; |
| 392 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 393 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 394 | int mWifiState = -1; |
| 395 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 396 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 397 | int mWifiSupplState = -1; |
| 398 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 399 | |
| 400 | int mWifiSignalStrengthBin = -1; |
| 401 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 402 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 403 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 404 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 405 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 406 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 407 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 408 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 409 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 410 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 411 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 412 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | /** |
| 415 | * These provide time bases that discount the time the device is plugged |
| 416 | * in to power. |
| 417 | */ |
| 418 | boolean mOnBattery; |
| 419 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 420 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 421 | /** |
| 422 | * External reporting of whether the device is actually charging. |
| 423 | */ |
| 424 | boolean mCharging = true; |
| 425 | int mLastChargingStateLevel; |
| 426 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 427 | /* |
| 428 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 429 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 430 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 431 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 432 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 433 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 434 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 435 | int mLowDischargeAmountSinceCharge; |
| 436 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 437 | int mDischargeScreenOnUnplugLevel; |
| 438 | int mDischargeScreenOffUnplugLevel; |
| 439 | int mDischargeAmountScreenOn; |
| 440 | int mDischargeAmountScreenOnSinceCharge; |
| 441 | int mDischargeAmountScreenOff; |
| 442 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 443 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 444 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 445 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 446 | int mInitStepMode = 0; |
| 447 | int mCurStepMode = 0; |
| 448 | int mModStepMode = 0; |
| 449 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 450 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 451 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 452 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 453 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 454 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 455 | |
| 456 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 457 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 458 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 459 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 460 | |
| 461 | static final int MAX_DAILY_ITEMS = 10; |
| 462 | |
| 463 | long mDailyStartTime = 0; |
| 464 | long mNextMinDailyDeadline = 0; |
| 465 | long mNextMaxDailyDeadline = 0; |
| 466 | |
| 467 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 470 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 471 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 472 | private int mPhoneServiceStateRaw = -1; |
| 473 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 474 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 475 | private int mNumConnectivityChange; |
| 476 | private int mLoadedNumConnectivityChange; |
| 477 | private int mUnpluggedNumConnectivityChange; |
| 478 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 479 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 480 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 481 | private PowerProfile mPowerProfile; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 482 | private boolean mHasWifiEnergyReporting = false; |
| 483 | private boolean mHasBluetoothEnergyReporting = false; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 484 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 485 | /* |
| 486 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 487 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 488 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 489 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 490 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 491 | return mKernelWakelockStats; |
| 492 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 493 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 494 | String mLastWakeupReason = null; |
| 495 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 496 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 497 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 498 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 499 | return mWakeupReasonStats; |
| 500 | } |
| 501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | public BatteryStatsImpl() { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 503 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 504 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 505 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 506 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 507 | mExternalSync = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 508 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 511 | public static interface TimeBaseObs { |
| 512 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 513 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 514 | } |
| 515 | |
| 516 | static class TimeBase { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 517 | private final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 518 | |
| 519 | private long mUptime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 520 | private long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 521 | |
| 522 | private boolean mRunning; |
| 523 | |
| 524 | private long mPastUptime; |
| 525 | private long mUptimeStart; |
| 526 | private long mPastRealtime; |
| 527 | private long mRealtimeStart; |
| 528 | private long mUnpluggedUptime; |
| 529 | private long mUnpluggedRealtime; |
| 530 | |
| 531 | public void dump(PrintWriter pw, String prefix) { |
| 532 | StringBuilder sb = new StringBuilder(128); |
| 533 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 534 | sb.setLength(0); |
| 535 | sb.append(prefix); |
| 536 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 537 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 538 | pw.println(sb.toString()); |
| 539 | sb.setLength(0); |
| 540 | sb.append(prefix); |
| 541 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 542 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 543 | pw.println(sb.toString()); |
| 544 | sb.setLength(0); |
| 545 | sb.append(prefix); |
| 546 | sb.append("mPastUptime="); |
| 547 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 548 | formatTimeMs(sb, mUptimeStart / 1000); |
| 549 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 550 | pw.println(sb.toString()); |
| 551 | sb.setLength(0); |
| 552 | sb.append(prefix); |
| 553 | sb.append("mPastRealtime="); |
| 554 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 555 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 556 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 557 | pw.println(sb.toString()); |
| 558 | } |
| 559 | |
| 560 | public void add(TimeBaseObs observer) { |
| 561 | mObservers.add(observer); |
| 562 | } |
| 563 | |
| 564 | public void remove(TimeBaseObs observer) { |
| 565 | if (!mObservers.remove(observer)) { |
| 566 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | public void init(long uptime, long realtime) { |
| 571 | mRealtime = 0; |
| 572 | mUptime = 0; |
| 573 | mPastUptime = 0; |
| 574 | mPastRealtime = 0; |
| 575 | mUptimeStart = uptime; |
| 576 | mRealtimeStart = realtime; |
| 577 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 578 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 579 | } |
| 580 | |
| 581 | public void reset(long uptime, long realtime) { |
| 582 | if (!mRunning) { |
| 583 | mPastUptime = 0; |
| 584 | mPastRealtime = 0; |
| 585 | } else { |
| 586 | mUptimeStart = uptime; |
| 587 | mRealtimeStart = realtime; |
| 588 | mUnpluggedUptime = getUptime(uptime); |
| 589 | mUnpluggedRealtime = getRealtime(realtime); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | public long computeUptime(long curTime, int which) { |
| 594 | switch (which) { |
| 595 | case STATS_SINCE_CHARGED: |
| 596 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 597 | case STATS_CURRENT: |
| 598 | return getUptime(curTime); |
| 599 | case STATS_SINCE_UNPLUGGED: |
| 600 | return getUptime(curTime) - mUnpluggedUptime; |
| 601 | } |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | public long computeRealtime(long curTime, int which) { |
| 606 | switch (which) { |
| 607 | case STATS_SINCE_CHARGED: |
| 608 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 609 | case STATS_CURRENT: |
| 610 | return getRealtime(curTime); |
| 611 | case STATS_SINCE_UNPLUGGED: |
| 612 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 613 | } |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | public long getUptime(long curTime) { |
| 618 | long time = mPastUptime; |
| 619 | if (mRunning) { |
| 620 | time += curTime - mUptimeStart; |
| 621 | } |
| 622 | return time; |
| 623 | } |
| 624 | |
| 625 | public long getRealtime(long curTime) { |
| 626 | long time = mPastRealtime; |
| 627 | if (mRunning) { |
| 628 | time += curTime - mRealtimeStart; |
| 629 | } |
| 630 | return time; |
| 631 | } |
| 632 | |
| 633 | public long getUptimeStart() { |
| 634 | return mUptimeStart; |
| 635 | } |
| 636 | |
| 637 | public long getRealtimeStart() { |
| 638 | return mRealtimeStart; |
| 639 | } |
| 640 | |
| 641 | public boolean isRunning() { |
| 642 | return mRunning; |
| 643 | } |
| 644 | |
| 645 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 646 | if (mRunning != running) { |
| 647 | mRunning = running; |
| 648 | if (running) { |
| 649 | mUptimeStart = uptime; |
| 650 | mRealtimeStart = realtime; |
| 651 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 652 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 653 | |
| 654 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 655 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 656 | } |
| 657 | } else { |
| 658 | mPastUptime += uptime - mUptimeStart; |
| 659 | mPastRealtime += realtime - mRealtimeStart; |
| 660 | |
| 661 | long batteryUptime = getUptime(uptime); |
| 662 | long batteryRealtime = getRealtime(realtime); |
| 663 | |
| 664 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 665 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 666 | } |
| 667 | } |
| 668 | return true; |
| 669 | } |
| 670 | return false; |
| 671 | } |
| 672 | |
| 673 | public void readSummaryFromParcel(Parcel in) { |
| 674 | mUptime = in.readLong(); |
| 675 | mRealtime = in.readLong(); |
| 676 | } |
| 677 | |
| 678 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 679 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 680 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 681 | } |
| 682 | |
| 683 | public void readFromParcel(Parcel in) { |
| 684 | mRunning = false; |
| 685 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 686 | mPastUptime = in.readLong(); |
| 687 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 688 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 689 | mPastRealtime = in.readLong(); |
| 690 | mRealtimeStart = in.readLong(); |
| 691 | mUnpluggedUptime = in.readLong(); |
| 692 | mUnpluggedRealtime = in.readLong(); |
| 693 | } |
| 694 | |
| 695 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 696 | final long runningUptime = getUptime(uptime); |
| 697 | final long runningRealtime = getRealtime(realtime); |
| 698 | out.writeLong(mUptime); |
| 699 | out.writeLong(runningUptime); |
| 700 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 701 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 702 | out.writeLong(runningRealtime); |
| 703 | out.writeLong(mRealtimeStart); |
| 704 | out.writeLong(mUnpluggedUptime); |
| 705 | out.writeLong(mUnpluggedRealtime); |
| 706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 710 | * State for keeping track of counting information. |
| 711 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 712 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 713 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 714 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 715 | int mLoadedCount; |
| 716 | int mLastCount; |
| 717 | int mUnpluggedCount; |
| 718 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 719 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 720 | Counter(TimeBase timeBase, Parcel in) { |
| 721 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 722 | mPluggedCount = in.readInt(); |
| 723 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 724 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 725 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 726 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 727 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 730 | Counter(TimeBase timeBase) { |
| 731 | mTimeBase = timeBase; |
| 732 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 733 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 734 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 735 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 736 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 737 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 738 | out.writeInt(mUnpluggedCount); |
| 739 | } |
| 740 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 741 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 742 | mUnpluggedCount = mPluggedCount; |
| 743 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 746 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 747 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 748 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 749 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 750 | /** |
| 751 | * Writes a possibly null Counter to a Parcel. |
| 752 | * |
| 753 | * @param out the Parcel to be written to. |
| 754 | * @param counter a Counter, or null. |
| 755 | */ |
| 756 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 757 | if (counter == null) { |
| 758 | out.writeInt(0); // indicates null |
| 759 | return; |
| 760 | } |
| 761 | out.writeInt(1); // indicates non-null |
| 762 | |
| 763 | counter.writeToParcel(out); |
| 764 | } |
| 765 | |
| 766 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 767 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 768 | int val = mCount.get(); |
| 769 | if (which == STATS_SINCE_UNPLUGGED) { |
| 770 | val -= mUnpluggedCount; |
| 771 | } else if (which != STATS_SINCE_CHARGED) { |
| 772 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | return val; |
| 776 | } |
| 777 | |
| 778 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 779 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 780 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 781 | + " mUnpluggedCount=" + mUnpluggedCount |
| 782 | + " mPluggedCount=" + mPluggedCount); |
| 783 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 784 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 785 | void stepAtomic() { |
| 786 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 789 | /** |
| 790 | * Clear state of this counter. |
| 791 | */ |
| 792 | void reset(boolean detachIfReset) { |
| 793 | mCount.set(0); |
| 794 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 795 | if (detachIfReset) { |
| 796 | detach(); |
| 797 | } |
| 798 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 799 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 800 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 801 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 802 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 803 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 804 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 805 | int count = mCount.get(); |
| 806 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 810 | mLoadedCount = in.readInt(); |
| 811 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 812 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 813 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 816 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 817 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 818 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 819 | long mCount; |
| 820 | long mLoadedCount; |
| 821 | long mLastCount; |
| 822 | long mUnpluggedCount; |
| 823 | long mPluggedCount; |
| 824 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 825 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 826 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 827 | mPluggedCount = in.readLong(); |
| 828 | mCount = mPluggedCount; |
| 829 | mLoadedCount = in.readLong(); |
| 830 | mLastCount = 0; |
| 831 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 832 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 835 | LongSamplingCounter(TimeBase timeBase) { |
| 836 | mTimeBase = timeBase; |
| 837 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | public void writeToParcel(Parcel out) { |
| 841 | out.writeLong(mCount); |
| 842 | out.writeLong(mLoadedCount); |
| 843 | out.writeLong(mUnpluggedCount); |
| 844 | } |
| 845 | |
| 846 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 847 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 848 | mUnpluggedCount = mPluggedCount; |
| 849 | mCount = mPluggedCount; |
| 850 | } |
| 851 | |
| 852 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 853 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 854 | mPluggedCount = mCount; |
| 855 | } |
| 856 | |
| 857 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 858 | long val = mCount; |
| 859 | if (which == STATS_SINCE_UNPLUGGED) { |
| 860 | val -= mUnpluggedCount; |
| 861 | } else if (which != STATS_SINCE_CHARGED) { |
| 862 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | return val; |
| 866 | } |
| 867 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 868 | @Override |
| 869 | public void logState(Printer pw, String prefix) { |
| 870 | pw.println(prefix + "mCount=" + mCount |
| 871 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 872 | + " mUnpluggedCount=" + mUnpluggedCount |
| 873 | + " mPluggedCount=" + mPluggedCount); |
| 874 | } |
| 875 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 876 | void addCountLocked(long count) { |
| 877 | mCount += count; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * Clear state of this counter. |
| 882 | */ |
| 883 | void reset(boolean detachIfReset) { |
| 884 | mCount = 0; |
| 885 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 886 | if (detachIfReset) { |
| 887 | detach(); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 892 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | void writeSummaryFromParcelLocked(Parcel out) { |
| 896 | out.writeLong(mCount); |
| 897 | } |
| 898 | |
| 899 | void readSummaryFromParcelLocked(Parcel in) { |
| 900 | mLoadedCount = in.readLong(); |
| 901 | mCount = mLoadedCount; |
| 902 | mLastCount = 0; |
| 903 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 904 | } |
| 905 | } |
| 906 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 907 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | * State for keeping track of timing information. |
| 909 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 910 | 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] | 911 | final int mType; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 912 | final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | int mCount; |
| 915 | int mLoadedCount; |
| 916 | int mLastCount; |
| 917 | int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | // Times are in microseconds for better accuracy when dividing by the |
| 920 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | /** |
| 923 | * The total time we have accumulated since the start of the original |
| 924 | * boot, to the last time something interesting happened in the |
| 925 | * current run. |
| 926 | */ |
| 927 | long mTotalTime; |
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 total time we loaded for the previous runs. Subtract this from |
| 931 | * mTotalTime to find the time for the current run of the system. |
| 932 | */ |
| 933 | long mLoadedTime; |
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 run time of the last run of the system, as loaded from the |
| 937 | * saved data. |
| 938 | */ |
| 939 | long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | /** |
| 942 | * The value of mTotalTime when unplug() was last called. Subtract |
| 943 | * this from mTotalTime to find the time since the last unplug from |
| 944 | * power. |
| 945 | */ |
| 946 | long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 947 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 948 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 949 | * The total time this timer has been running until the latest mark has been set. |
| 950 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 951 | */ |
| 952 | long mTimeBeforeMark; |
| 953 | |
| 954 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 955 | * Constructs from a parcel. |
| 956 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 957 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 958 | * @param in |
| 959 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 960 | Timer(int type, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 962 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | mCount = in.readInt(); |
| 965 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 966 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | mUnpluggedCount = in.readInt(); |
| 968 | mTotalTime = in.readLong(); |
| 969 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 970 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 972 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 973 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 974 | 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] | 975 | } |
| 976 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 977 | Timer(int type, TimeBase timeBase) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 979 | mTimeBase = timeBase; |
| 980 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 982 | |
| 983 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 984 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 985 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 986 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 987 | /** |
| 988 | * Clear state of this timer. Returns true if the timer is inactive |
| 989 | * so can be completely dropped. |
| 990 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 991 | boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 992 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 993 | mCount = mLoadedCount = mLastCount = 0; |
| 994 | if (detachIfReset) { |
| 995 | detach(); |
| 996 | } |
| 997 | return true; |
| 998 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 999 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1000 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1001 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1002 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1003 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1004 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1005 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1006 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | out.writeInt(mCount); |
| 1008 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1010 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1013 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1016 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1017 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1019 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1021 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1022 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1023 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | mUnpluggedCount = mCount; |
| 1025 | if (DEBUG && mType < 0) { |
| 1026 | Log.v(TAG, "unplug #" + mType |
| 1027 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1028 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1029 | } |
| 1030 | } |
| 1031 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1032 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1033 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1034 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1035 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1036 | + " old mTotalTime=" + mTotalTime); |
| 1037 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1038 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1039 | mCount = computeCurrentCountLocked(); |
| 1040 | if (DEBUG && mType < 0) { |
| 1041 | Log.v(TAG, "plug #" + mType |
| 1042 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | } |
| 1044 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | /** |
| 1047 | * Writes a possibly null Timer to a Parcel. |
| 1048 | * |
| 1049 | * @param out the Parcel to be written to. |
| 1050 | * @param timer a Timer, or null. |
| 1051 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1052 | 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] | 1053 | if (timer == null) { |
| 1054 | out.writeInt(0); // indicates null |
| 1055 | return; |
| 1056 | } |
| 1057 | out.writeInt(1); // indicates non-null |
| 1058 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1059 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1063 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1064 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1065 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1066 | val -= mUnpluggedTime; |
| 1067 | } else if (which != STATS_SINCE_CHARGED) { |
| 1068 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | return val; |
| 1072 | } |
| 1073 | |
| 1074 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1075 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1076 | int val = computeCurrentCountLocked(); |
| 1077 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1078 | val -= mUnpluggedCount; |
| 1079 | } else if (which != STATS_SINCE_CHARGED) { |
| 1080 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | return val; |
| 1084 | } |
| 1085 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1086 | @Override |
| 1087 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1088 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1089 | return val - mTimeBeforeMark; |
| 1090 | } |
| 1091 | |
| 1092 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1093 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1094 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1096 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1097 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1099 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1101 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1102 | |
| 1103 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1104 | void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1105 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1106 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1107 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void readSummaryFromParcelLocked(Parcel in) { |
| 1111 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1112 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1113 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1114 | mUnpluggedTime = mTotalTime; |
| 1115 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1116 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1117 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1118 | |
| 1119 | // When reading the summary, we set the mark to be the latest information. |
| 1120 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1121 | } |
| 1122 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1123 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1124 | public static final class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1125 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1126 | /** |
| 1127 | * The most recent reported count from /proc/wakelocks. |
| 1128 | */ |
| 1129 | int mCurrentReportedCount; |
| 1130 | |
| 1131 | /** |
| 1132 | * The reported count from /proc/wakelocks when unplug() was last |
| 1133 | * called. |
| 1134 | */ |
| 1135 | int mUnpluggedReportedCount; |
| 1136 | |
| 1137 | /** |
| 1138 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1139 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1140 | long mCurrentReportedTotalTime; |
| 1141 | |
| 1142 | |
| 1143 | /** |
| 1144 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1145 | * called. |
| 1146 | */ |
| 1147 | long mUnpluggedReportedTotalTime; |
| 1148 | |
| 1149 | /** |
| 1150 | * Whether we are currently in a discharge cycle. |
| 1151 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1152 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1153 | |
| 1154 | /** |
| 1155 | * Whether we are currently recording reported values. |
| 1156 | */ |
| 1157 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1158 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1159 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1160 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1161 | */ |
| 1162 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1163 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1164 | SamplingTimer(TimeBase timeBase, Parcel in) { |
| 1165 | super(0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1166 | mCurrentReportedCount = in.readInt(); |
| 1167 | mUnpluggedReportedCount = in.readInt(); |
| 1168 | mCurrentReportedTotalTime = in.readLong(); |
| 1169 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1170 | mTrackingReportedValues = in.readInt() == 1; |
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 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1174 | SamplingTimer(TimeBase timeBase, boolean trackReportedValues) { |
| 1175 | super(0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1176 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1177 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 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 setStale() { |
| 1181 | mTrackingReportedValues = false; |
| 1182 | mUnpluggedReportedTotalTime = 0; |
| 1183 | mUnpluggedReportedCount = 0; |
| 1184 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1185 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1186 | public void setUpdateVersion(int version) { |
| 1187 | mUpdateVersion = version; |
| 1188 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1189 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1190 | public int getUpdateVersion() { |
| 1191 | return mUpdateVersion; |
| 1192 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1193 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1194 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1195 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1196 | // Updating the reported value for the first time. |
| 1197 | mUnpluggedReportedCount = count; |
| 1198 | // If we are receiving an update update mTrackingReportedValues; |
| 1199 | mTrackingReportedValues = true; |
| 1200 | } |
| 1201 | mCurrentReportedCount = count; |
| 1202 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1203 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1204 | public void addCurrentReportedCount(int delta) { |
| 1205 | updateCurrentReportedCount(mCurrentReportedCount + delta); |
| 1206 | } |
| 1207 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1208 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1209 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1210 | // Updating the reported value for the first time. |
| 1211 | mUnpluggedReportedTotalTime = totalTime; |
| 1212 | // If we are receiving an update update mTrackingReportedValues; |
| 1213 | mTrackingReportedValues = true; |
| 1214 | } |
| 1215 | mCurrentReportedTotalTime = totalTime; |
| 1216 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1217 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1218 | public void addCurrentReportedTotalTime(long delta) { |
| 1219 | updateCurrentReportedTotalTime(mCurrentReportedTotalTime + delta); |
| 1220 | } |
| 1221 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1222 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1223 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1224 | if (mTrackingReportedValues) { |
| 1225 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1226 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1227 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1228 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1231 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1232 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1233 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1234 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1235 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1236 | public void logState(Printer pw, String prefix) { |
| 1237 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1238 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1239 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1240 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1241 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1242 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1243 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1244 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1245 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1246 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1247 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1248 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1249 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1250 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1251 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1252 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1253 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1254 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1255 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1256 | out.writeInt(mCurrentReportedCount); |
| 1257 | out.writeInt(mUnpluggedReportedCount); |
| 1258 | out.writeLong(mCurrentReportedTotalTime); |
| 1259 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1260 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1261 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1262 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1263 | boolean reset(boolean detachIfReset) { |
| 1264 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1265 | setStale(); |
| 1266 | return true; |
| 1267 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1268 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1269 | void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
| 1270 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1271 | out.writeLong(mCurrentReportedTotalTime); |
| 1272 | out.writeInt(mCurrentReportedCount); |
| 1273 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1274 | } |
| 1275 | |
| 1276 | void readSummaryFromParcelLocked(Parcel in) { |
| 1277 | super.readSummaryFromParcelLocked(in); |
| 1278 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1279 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1280 | mTrackingReportedValues = in.readInt() == 1; |
| 1281 | } |
| 1282 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1283 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1284 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1285 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1286 | * for a pre-determined amount. |
| 1287 | */ |
| 1288 | public static final class BatchTimer extends Timer { |
| 1289 | final Uid mUid; |
| 1290 | |
| 1291 | /** |
| 1292 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1293 | */ |
| 1294 | long mLastAddedTime; |
| 1295 | |
| 1296 | /** |
| 1297 | * The last duration that we added to the timer. This is in microseconds. |
| 1298 | */ |
| 1299 | long mLastAddedDuration; |
| 1300 | |
| 1301 | /** |
| 1302 | * Whether we are currently in a discharge cycle. |
| 1303 | */ |
| 1304 | boolean mInDischarge; |
| 1305 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1306 | BatchTimer(Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1307 | super(type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1308 | mUid = uid; |
| 1309 | mLastAddedTime = in.readLong(); |
| 1310 | mLastAddedDuration = in.readLong(); |
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 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1314 | BatchTimer(Uid uid, int type, TimeBase timeBase) { |
| 1315 | super(type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1316 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1317 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1321 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1322 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1323 | out.writeLong(mLastAddedTime); |
| 1324 | out.writeLong(mLastAddedDuration); |
| 1325 | } |
| 1326 | |
| 1327 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1328 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1329 | recomputeLastDuration(SystemClock.elapsedRealtime() * 1000, false); |
| 1330 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1331 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1335 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1336 | recomputeLastDuration(elapsedRealtime, false); |
| 1337 | mInDischarge = true; |
| 1338 | // If we are still within the last added duration, then re-added whatever remains. |
| 1339 | if (mLastAddedTime == elapsedRealtime) { |
| 1340 | mTotalTime += mLastAddedDuration; |
| 1341 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1342 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | @Override |
| 1346 | public void logState(Printer pw, String prefix) { |
| 1347 | super.logState(pw, prefix); |
| 1348 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1349 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1350 | } |
| 1351 | |
| 1352 | private long computeOverage(long curTime) { |
| 1353 | if (mLastAddedTime > 0) { |
| 1354 | return mLastTime + mLastAddedDuration - curTime; |
| 1355 | } |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1360 | final long overage = computeOverage(curTime); |
| 1361 | if (overage > 0) { |
| 1362 | // Aborting before the duration ran out -- roll back the remaining |
| 1363 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1364 | // actually add the time. |
| 1365 | if (mInDischarge) { |
| 1366 | mTotalTime -= overage; |
| 1367 | } |
| 1368 | if (abort) { |
| 1369 | mLastAddedTime = 0; |
| 1370 | } else { |
| 1371 | mLastAddedTime = curTime; |
| 1372 | mLastAddedDuration -= overage; |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
| 1378 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1379 | recomputeLastDuration(now, true); |
| 1380 | mLastAddedTime = now; |
| 1381 | mLastAddedDuration = durationMillis * 1000; |
| 1382 | if (mInDischarge) { |
| 1383 | mTotalTime += mLastAddedDuration; |
| 1384 | mCount++; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | public void abortLastDuration(BatteryStatsImpl stats) { |
| 1389 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1390 | recomputeLastDuration(now, true); |
| 1391 | } |
| 1392 | |
| 1393 | @Override |
| 1394 | protected int computeCurrentCountLocked() { |
| 1395 | return mCount; |
| 1396 | } |
| 1397 | |
| 1398 | @Override |
| 1399 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
| 1400 | final long overage = computeOverage(SystemClock.elapsedRealtime() * 1000); |
| 1401 | if (overage > 0) { |
| 1402 | return mTotalTime = overage; |
| 1403 | } |
| 1404 | return mTotalTime; |
| 1405 | } |
| 1406 | |
| 1407 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1408 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1409 | final long now = SystemClock.elapsedRealtime() * 1000; |
| 1410 | recomputeLastDuration(now, true); |
| 1411 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1412 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1413 | return !stillActive; |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1418 | * State for keeping track of timing information. |
| 1419 | */ |
| 1420 | public static final class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1421 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1422 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1423 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1424 | int mNesting; |
| 1425 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1426 | /** |
| 1427 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1428 | * subtract this from the current battery time to find the amount of |
| 1429 | * time we have been running since we last computed an update. |
| 1430 | */ |
| 1431 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1432 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1433 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1434 | * 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] | 1435 | * was actually held for an interesting duration. |
| 1436 | */ |
| 1437 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1438 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1439 | long mTimeout; |
| 1440 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1441 | /** |
| 1442 | * For partial wake locks, keep track of whether we are in the list |
| 1443 | * to consume CPU cycles. |
| 1444 | */ |
| 1445 | boolean mInList; |
| 1446 | |
| 1447 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1448 | TimeBase timeBase, Parcel in) { |
| 1449 | super(type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1450 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1451 | mTimerPool = timerPool; |
| 1452 | mUpdateTime = in.readLong(); |
| 1453 | } |
| 1454 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1455 | StopwatchTimer(Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1456 | TimeBase timeBase) { |
| 1457 | super(type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1458 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1459 | mTimerPool = timerPool; |
| 1460 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1461 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1462 | void setTimeout(long timeout) { |
| 1463 | mTimeout = timeout; |
| 1464 | } |
| 1465 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1466 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1467 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1468 | out.writeLong(mUpdateTime); |
| 1469 | } |
| 1470 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1471 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1472 | if (mNesting > 0) { |
| 1473 | if (DEBUG && mType < 0) { |
| 1474 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1475 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1476 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1477 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1478 | if (DEBUG && mType < 0) { |
| 1479 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | public void logState(Printer pw, String prefix) { |
| 1485 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1486 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | + " mAcquireTime=" + mAcquireTime); |
| 1488 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1489 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1490 | void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1492 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1493 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | if (mTimerPool != null) { |
| 1495 | // Accumulate time to all currently active timers before adding |
| 1496 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1497 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | // Add this timer to the active pool |
| 1499 | mTimerPool.add(this); |
| 1500 | } |
| 1501 | // Increment the count |
| 1502 | mCount++; |
| 1503 | mAcquireTime = mTotalTime; |
| 1504 | if (DEBUG && mType < 0) { |
| 1505 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1506 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1507 | + " mAcquireTime=" + mAcquireTime); |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1512 | boolean isRunningLocked() { |
| 1513 | return mNesting > 0; |
| 1514 | } |
| 1515 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1516 | void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | // Ignore attempt to stop a timer that isn't running |
| 1518 | if (mNesting == 0) { |
| 1519 | return; |
| 1520 | } |
| 1521 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1522 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | if (mTimerPool != null) { |
| 1524 | // Accumulate time to all active counters, scaled by the total |
| 1525 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1526 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | // Remove this timer from the active pool |
| 1528 | mTimerPool.remove(this); |
| 1529 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | mNesting = 1; |
| 1531 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1532 | mNesting = 0; |
| 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 (DEBUG && mType < 0) { |
| 1536 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1537 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1538 | + " mAcquireTime=" + mAcquireTime); |
| 1539 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | if (mTotalTime == mAcquireTime) { |
| 1542 | // If there was no change in the time, then discard this |
| 1543 | // count. A somewhat cheezy strategy, but hey. |
| 1544 | mCount--; |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1549 | void stopAllRunningLocked(long elapsedRealtimeMs) { |
| 1550 | if (mNesting > 0) { |
| 1551 | mNesting = 1; |
| 1552 | stopRunningLocked(elapsedRealtimeMs); |
| 1553 | } |
| 1554 | } |
| 1555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | // Update the total time for all other running Timers with the same type as this Timer |
| 1557 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1558 | private static long refreshTimersLocked(long batteryRealtime, |
| 1559 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1560 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | final int N = pool.size(); |
| 1562 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1563 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1565 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1566 | final long myTime = heldTime / N; |
| 1567 | if (t == self) { |
| 1568 | selfTime = myTime; |
| 1569 | } |
| 1570 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | } |
| 1572 | t.mUpdateTime = batteryRealtime; |
| 1573 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1574 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1577 | @Override |
| 1578 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1579 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1580 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1581 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | return mTotalTime + (mNesting > 0 |
| 1583 | ? (curBatteryRealtime - mUpdateTime) |
| 1584 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1585 | : 0); |
| 1586 | } |
| 1587 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1588 | @Override |
| 1589 | protected int computeCurrentCountLocked() { |
| 1590 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1593 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1594 | boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1595 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1596 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1597 | if (mNesting > 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1598 | mUpdateTime = mTimeBase.getRealtime(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1599 | } |
| 1600 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1601 | return canDetach; |
| 1602 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1603 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1604 | @Override |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1605 | void detach() { |
| 1606 | super.detach(); |
| 1607 | if (mTimerPool != null) { |
| 1608 | mTimerPool.remove(this); |
| 1609 | } |
| 1610 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1611 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1612 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1614 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | mNesting = 0; |
| 1616 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1617 | |
| 1618 | /** |
| 1619 | * Set the mark so that we can query later for the total time the timer has |
| 1620 | * accumulated since this point. The timer can be running or not. |
| 1621 | * |
| 1622 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1623 | */ |
| 1624 | public void setMark(long elapsedRealtimeMs) { |
| 1625 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1626 | if (mNesting > 0) { |
| 1627 | // We are running. |
| 1628 | if (mTimerPool != null) { |
| 1629 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1630 | } else { |
| 1631 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1632 | mUpdateTime = batteryRealtime; |
| 1633 | } |
| 1634 | } |
| 1635 | mTimeBeforeMark = mTotalTime; |
| 1636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1638 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1639 | public abstract class OverflowArrayMap<T> { |
| 1640 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1641 | |
| 1642 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1643 | T mCurOverflow; |
| 1644 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1645 | |
| 1646 | public OverflowArrayMap() { |
| 1647 | } |
| 1648 | |
| 1649 | public ArrayMap<String, T> getMap() { |
| 1650 | return mMap; |
| 1651 | } |
| 1652 | |
| 1653 | public void clear() { |
| 1654 | mMap.clear(); |
| 1655 | mCurOverflow = null; |
| 1656 | mActiveOverflow = null; |
| 1657 | } |
| 1658 | |
| 1659 | public void add(String name, T obj) { |
| 1660 | mMap.put(name, obj); |
| 1661 | if (OVERFLOW_NAME.equals(name)) { |
| 1662 | mCurOverflow = obj; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | public void cleanup() { |
| 1667 | if (mActiveOverflow != null) { |
| 1668 | if (mActiveOverflow.size() == 0) { |
| 1669 | mActiveOverflow = null; |
| 1670 | } |
| 1671 | } |
| 1672 | if (mActiveOverflow == null) { |
| 1673 | // There is no currently active overflow, so we should no longer have |
| 1674 | // an overflow entry. |
| 1675 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1676 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1677 | + mMap.get(OVERFLOW_NAME)); |
| 1678 | mMap.remove(OVERFLOW_NAME); |
| 1679 | } |
| 1680 | mCurOverflow = null; |
| 1681 | } else { |
| 1682 | // There is currently active overflow, so we should still have an overflow entry. |
| 1683 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1684 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1685 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | public T startObject(String name) { |
| 1691 | T obj = mMap.get(name); |
| 1692 | if (obj != null) { |
| 1693 | return obj; |
| 1694 | } |
| 1695 | |
| 1696 | // No object exists for the given name, but do we currently have it |
| 1697 | // running as part of the overflow? |
| 1698 | if (mActiveOverflow != null) { |
| 1699 | MutableInt over = mActiveOverflow.get(name); |
| 1700 | if (over != null) { |
| 1701 | // We are already actively counting this name in the overflow object. |
| 1702 | obj = mCurOverflow; |
| 1703 | if (obj == null) { |
| 1704 | // Shouldn't be here, but we'll try to recover. |
| 1705 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1706 | obj = mCurOverflow = instantiateObject(); |
| 1707 | mMap.put(OVERFLOW_NAME, obj); |
| 1708 | } |
| 1709 | over.value++; |
| 1710 | return obj; |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | // No object exists for given name nor in the overflow; we need to make |
| 1715 | // a new one. |
| 1716 | final int N = mMap.size(); |
| 1717 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1718 | // Went over the limit on number of objects to track; this one goes |
| 1719 | // in to the overflow. |
| 1720 | obj = mCurOverflow; |
| 1721 | if (obj == null) { |
| 1722 | // Need to start overflow now... |
| 1723 | obj = mCurOverflow = instantiateObject(); |
| 1724 | mMap.put(OVERFLOW_NAME, obj); |
| 1725 | } |
| 1726 | if (mActiveOverflow == null) { |
| 1727 | mActiveOverflow = new ArrayMap<>(); |
| 1728 | } |
| 1729 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1730 | return obj; |
| 1731 | } |
| 1732 | |
| 1733 | // Normal case where we just need to make a new object. |
| 1734 | obj = instantiateObject(); |
| 1735 | mMap.put(name, obj); |
| 1736 | return obj; |
| 1737 | } |
| 1738 | |
| 1739 | public T stopObject(String name) { |
| 1740 | T obj = mMap.get(name); |
| 1741 | if (obj != null) { |
| 1742 | return obj; |
| 1743 | } |
| 1744 | |
| 1745 | // No object exists for the given name, but do we currently have it |
| 1746 | // running as part of the overflow? |
| 1747 | if (mActiveOverflow != null) { |
| 1748 | MutableInt over = mActiveOverflow.get(name); |
| 1749 | if (over != null) { |
| 1750 | // We are already actively counting this name in the overflow object. |
| 1751 | obj = mCurOverflow; |
| 1752 | if (obj != null) { |
| 1753 | over.value--; |
| 1754 | if (over.value <= 0) { |
| 1755 | mActiveOverflow.remove(name); |
| 1756 | } |
| 1757 | return obj; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | // Huh, they are stopping an active operation but we can't find one! |
| 1763 | // That's not good. |
| 1764 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1765 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1766 | + " curoverflow=" + mCurOverflow); |
| 1767 | return null; |
| 1768 | } |
| 1769 | |
| 1770 | public abstract T instantiateObject(); |
| 1771 | } |
| 1772 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1773 | /* |
| 1774 | * Get the wakeup reason counter, and create a new one if one |
| 1775 | * doesn't already exist. |
| 1776 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1777 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 1778 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 1779 | if (timer == null) { |
| 1780 | timer = new SamplingTimer(mOnBatteryTimeBase, true); |
| 1781 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1782 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1783 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1786 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1787 | * 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] | 1788 | * doesn't already exist. |
| 1789 | */ |
| 1790 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 1791 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 1792 | if (kwlt == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1793 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1794 | mKernelWakelockStats.put(name, kwlt); |
| 1795 | } |
| 1796 | return kwlt; |
| 1797 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 1798 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1799 | private int writeHistoryTag(HistoryTag tag) { |
| 1800 | Integer idxObj = mHistoryTagPool.get(tag); |
| 1801 | int idx; |
| 1802 | if (idxObj != null) { |
| 1803 | idx = idxObj; |
| 1804 | } else { |
| 1805 | idx = mNextHistoryTagIdx; |
| 1806 | HistoryTag key = new HistoryTag(); |
| 1807 | key.setTo(tag); |
| 1808 | tag.poolIdx = idx; |
| 1809 | mHistoryTagPool.put(key, idx); |
| 1810 | mNextHistoryTagIdx++; |
| 1811 | mNumHistoryTagChars += key.string.length() + 1; |
| 1812 | } |
| 1813 | return idx; |
| 1814 | } |
| 1815 | |
| 1816 | private void readHistoryTag(int index, HistoryTag tag) { |
| 1817 | tag.string = mReadHistoryStrings[index]; |
| 1818 | tag.uid = mReadHistoryUids[index]; |
| 1819 | tag.poolIdx = index; |
| 1820 | } |
| 1821 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1822 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1823 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 1824 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 1825 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 1826 | 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] | 1827 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1828 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1829 | // 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] | 1830 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 1831 | // Flag in delta int: a new full state2 int follows. |
| 1832 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1833 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1834 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1835 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1836 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1837 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1838 | static final int DELTA_STATE_MASK = 0xff000000; |
| 1839 | |
| 1840 | // These are the pieces of battery state that are packed in to the upper bits of |
| 1841 | // the state int that have been packed in to the first delta int. They must fit |
| 1842 | // in DELTA_STATE_MASK. |
| 1843 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 1844 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 1845 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 1846 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 1847 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 1848 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1849 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1850 | // We use the low bit of the battery state int to indicate that we have full details |
| 1851 | // from a battery level change. |
| 1852 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 1853 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1854 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1855 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1856 | dest.writeInt(DELTA_TIME_ABS); |
| 1857 | cur.writeToParcel(dest, 0); |
| 1858 | return; |
| 1859 | } |
| 1860 | |
| 1861 | final long deltaTime = cur.time - last.time; |
| 1862 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 1863 | final int lastStateInt = buildStateInt(last); |
| 1864 | |
| 1865 | int deltaTimeToken; |
| 1866 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 1867 | deltaTimeToken = DELTA_TIME_LONG; |
| 1868 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 1869 | deltaTimeToken = DELTA_TIME_INT; |
| 1870 | } else { |
| 1871 | deltaTimeToken = (int)deltaTime; |
| 1872 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1873 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1874 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 1875 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 1876 | final boolean computeStepDetails = includeStepDetails != 0 |
| 1877 | || mLastHistoryStepDetails == null; |
| 1878 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1879 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 1880 | if (batteryLevelIntChanged) { |
| 1881 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 1882 | } |
| 1883 | final int stateInt = buildStateInt(cur); |
| 1884 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 1885 | if (stateIntChanged) { |
| 1886 | firstToken |= DELTA_STATE_FLAG; |
| 1887 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1888 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 1889 | if (state2IntChanged) { |
| 1890 | firstToken |= DELTA_STATE2_FLAG; |
| 1891 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1892 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1893 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 1894 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1895 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 1896 | firstToken |= DELTA_EVENT_FLAG; |
| 1897 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1898 | dest.writeInt(firstToken); |
| 1899 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 1900 | + " deltaTime=" + deltaTime); |
| 1901 | |
| 1902 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 1903 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 1904 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 1905 | dest.writeInt((int)deltaTime); |
| 1906 | } else { |
| 1907 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 1908 | dest.writeLong(deltaTime); |
| 1909 | } |
| 1910 | } |
| 1911 | if (batteryLevelIntChanged) { |
| 1912 | dest.writeInt(batteryLevelInt); |
| 1913 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 1914 | + Integer.toHexString(batteryLevelInt) |
| 1915 | + " batteryLevel=" + cur.batteryLevel |
| 1916 | + " batteryTemp=" + cur.batteryTemperature |
| 1917 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 1918 | } |
| 1919 | if (stateIntChanged) { |
| 1920 | dest.writeInt(stateInt); |
| 1921 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 1922 | + Integer.toHexString(stateInt) |
| 1923 | + " batteryStatus=" + cur.batteryStatus |
| 1924 | + " batteryHealth=" + cur.batteryHealth |
| 1925 | + " batteryPlugType=" + cur.batteryPlugType |
| 1926 | + " states=0x" + Integer.toHexString(cur.states)); |
| 1927 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1928 | if (state2IntChanged) { |
| 1929 | dest.writeInt(cur.states2); |
| 1930 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 1931 | + Integer.toHexString(cur.states2)); |
| 1932 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1933 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 1934 | int wakeLockIndex; |
| 1935 | int wakeReasonIndex; |
| 1936 | if (cur.wakelockTag != null) { |
| 1937 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 1938 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 1939 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 1940 | } else { |
| 1941 | wakeLockIndex = 0xffff; |
| 1942 | } |
| 1943 | if (cur.wakeReasonTag != null) { |
| 1944 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 1945 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 1946 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 1947 | } else { |
| 1948 | wakeReasonIndex = 0xffff; |
| 1949 | } |
| 1950 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1951 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1952 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1953 | int index = writeHistoryTag(cur.eventTag); |
| 1954 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1955 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1956 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 1957 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 1958 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1959 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1960 | if (computeStepDetails) { |
| 1961 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 1962 | if (includeStepDetails != 0) { |
| 1963 | mCurHistoryStepDetails.writeToParcel(dest); |
| 1964 | } |
| 1965 | cur.stepDetails = mCurHistoryStepDetails; |
| 1966 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 1967 | } else { |
| 1968 | cur.stepDetails = null; |
| 1969 | } |
| 1970 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 1971 | mLastHistoryStepDetails = null; |
| 1972 | } |
| 1973 | mLastHistoryStepLevel = cur.batteryLevel; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | private int buildBatteryLevelInt(HistoryItem h) { |
| 1977 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1978 | | ((((int)h.batteryTemperature)<<14)&0x01ff8000) |
| 1979 | | ((((int)h.batteryVoltage)<<1)&0x00007fff); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1983 | int plugType = 0; |
| 1984 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 1985 | plugType = 1; |
| 1986 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 1987 | plugType = 2; |
| 1988 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 1989 | plugType = 3; |
| 1990 | } |
| 1991 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 1992 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 1993 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1994 | | (h.states&(~DELTA_STATE_MASK)); |
| 1995 | } |
| 1996 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1997 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 1998 | final HistoryStepDetails last) { |
| 1999 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2000 | |
| 2001 | // Perform a CPU update right after we do this collection, so we have started |
| 2002 | // collecting good data for the next step. |
| 2003 | requestImmediateCpuUpdate(); |
| 2004 | |
| 2005 | if (last == null) { |
| 2006 | // We are not generating a delta, so all we need to do is reset the stats |
| 2007 | // we will later be doing a delta from. |
| 2008 | final int NU = mUidStats.size(); |
| 2009 | for (int i=0; i<NU; i++) { |
| 2010 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2011 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2012 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2013 | } |
| 2014 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2015 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2016 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2017 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2018 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2019 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2020 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2021 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2022 | tmp.clear(); |
| 2023 | return; |
| 2024 | } |
| 2025 | if (DEBUG) { |
| 2026 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2027 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2028 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2029 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2030 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2031 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2032 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2033 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2034 | } |
| 2035 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2036 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2037 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2038 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2039 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2040 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2041 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2042 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2043 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2044 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2045 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2046 | final int NU = mUidStats.size(); |
| 2047 | for (int i=0; i<NU; i++) { |
| 2048 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2049 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2050 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2051 | final int totalTime = totalUTime + totalSTime; |
| 2052 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2053 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2054 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2055 | continue; |
| 2056 | } |
| 2057 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2058 | out.appCpuUid3 = uid.mUid; |
| 2059 | out.appCpuUTime3 = totalUTime; |
| 2060 | out.appCpuSTime3 = totalSTime; |
| 2061 | } else { |
| 2062 | out.appCpuUid3 = out.appCpuUid2; |
| 2063 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2064 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2065 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2066 | out.appCpuUid2 = uid.mUid; |
| 2067 | out.appCpuUTime2 = totalUTime; |
| 2068 | out.appCpuSTime2 = totalSTime; |
| 2069 | } else { |
| 2070 | out.appCpuUid2 = out.appCpuUid1; |
| 2071 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2072 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2073 | out.appCpuUid1 = uid.mUid; |
| 2074 | out.appCpuUTime1 = totalUTime; |
| 2075 | out.appCpuSTime1 = totalSTime; |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2080 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2081 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2082 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2083 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2084 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2085 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2086 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2087 | } |
| 2088 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2089 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2090 | int firstToken = src.readInt(); |
| 2091 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2092 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2093 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2094 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2095 | + " deltaTimeToken=" + deltaTimeToken); |
| 2096 | |
| 2097 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2098 | cur.time += deltaTimeToken; |
| 2099 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2100 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2101 | cur.numReadInts += 2; |
| 2102 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2103 | cur.readFromParcel(src); |
| 2104 | return; |
| 2105 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2106 | int delta = src.readInt(); |
| 2107 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2108 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2109 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2110 | } else { |
| 2111 | long delta = src.readLong(); |
| 2112 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2113 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2114 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2115 | } |
| 2116 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2117 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2118 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2119 | batteryLevelInt = src.readInt(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2120 | cur.batteryLevel = (byte)((batteryLevelInt>>25)&0x7f); |
| 2121 | cur.batteryTemperature = (short)((batteryLevelInt<<7)>>21); |
| 2122 | cur.batteryVoltage = (char)(batteryLevelInt&0x3fff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2123 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2124 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2125 | + Integer.toHexString(batteryLevelInt) |
| 2126 | + " batteryLevel=" + cur.batteryLevel |
| 2127 | + " batteryTemp=" + cur.batteryTemperature |
| 2128 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2129 | } else { |
| 2130 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2134 | int stateInt = src.readInt(); |
| 2135 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2136 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2137 | & STATE_BATTERY_STATUS_MASK); |
| 2138 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2139 | & STATE_BATTERY_HEALTH_MASK); |
| 2140 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2141 | & STATE_BATTERY_PLUG_MASK); |
| 2142 | switch (cur.batteryPlugType) { |
| 2143 | case 1: |
| 2144 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2145 | break; |
| 2146 | case 2: |
| 2147 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2148 | break; |
| 2149 | case 3: |
| 2150 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2151 | break; |
| 2152 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2153 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2154 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2155 | + Integer.toHexString(stateInt) |
| 2156 | + " batteryStatus=" + cur.batteryStatus |
| 2157 | + " batteryHealth=" + cur.batteryHealth |
| 2158 | + " batteryPlugType=" + cur.batteryPlugType |
| 2159 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2160 | } else { |
| 2161 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 2162 | } |
| 2163 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2164 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2165 | cur.states2 = src.readInt(); |
| 2166 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2167 | + Integer.toHexString(cur.states2)); |
| 2168 | } |
| 2169 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2170 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2171 | int indexes = src.readInt(); |
| 2172 | int wakeLockIndex = indexes&0xffff; |
| 2173 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2174 | if (wakeLockIndex != 0xffff) { |
| 2175 | cur.wakelockTag = cur.localWakelockTag; |
| 2176 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2177 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2178 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2179 | } else { |
| 2180 | cur.wakelockTag = null; |
| 2181 | } |
| 2182 | if (wakeReasonIndex != 0xffff) { |
| 2183 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2184 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2185 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2186 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2187 | } else { |
| 2188 | cur.wakeReasonTag = null; |
| 2189 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2190 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2191 | } else { |
| 2192 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2193 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2194 | } |
| 2195 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2196 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2197 | cur.eventTag = cur.localEventTag; |
| 2198 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2199 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2200 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2201 | readHistoryTag(index, cur.eventTag); |
| 2202 | cur.numReadInts += 1; |
| 2203 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2204 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2205 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2206 | } else { |
| 2207 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2208 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2209 | |
| 2210 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2211 | cur.stepDetails = mReadHistoryStepDetails; |
| 2212 | cur.stepDetails.readFromParcel(src); |
| 2213 | } else { |
| 2214 | cur.stepDetails = null; |
| 2215 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2216 | } |
| 2217 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2218 | @Override |
| 2219 | public void commitCurrentHistoryBatchLocked() { |
| 2220 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2221 | } |
| 2222 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2223 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2224 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2225 | return; |
| 2226 | } |
| 2227 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2228 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2229 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2230 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2231 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2232 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2233 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2234 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2235 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2236 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2237 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2238 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2239 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2240 | && (diffStates2&lastDiffStates2) == 0 |
| 2241 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2242 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2243 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2244 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2245 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2246 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2247 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2248 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2249 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2250 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2251 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2252 | // 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] | 2253 | // 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] | 2254 | // as long as no bit has changed both between now and the last entry, as |
| 2255 | // well as the last entry and the one before it (so we capture any toggles). |
| 2256 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2257 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2258 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2259 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2260 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2261 | // If the last written history had a wakelock tag, we need to retain it. |
| 2262 | // Note that the condition above made sure that we aren't in a case where |
| 2263 | // both it and the current history item have a wakelock tag. |
| 2264 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2265 | cur.wakelockTag = cur.localWakelockTag; |
| 2266 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2267 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2268 | // If the last written history had a wake reason tag, we need to retain it. |
| 2269 | // Note that the condition above made sure that we aren't in a case where |
| 2270 | // both it and the current history item have a wakelock tag. |
| 2271 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2272 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2273 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2274 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2275 | // If the last written history had an event, we need to retain it. |
| 2276 | // Note that the condition above made sure that we aren't in a case where |
| 2277 | // both it and the current history item have an event. |
| 2278 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2279 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2280 | cur.eventTag = cur.localEventTag; |
| 2281 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2282 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2283 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2287 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2288 | if (!mHistoryOverflow) { |
| 2289 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2290 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2291 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2292 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2295 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2296 | boolean writeAnyway = false; |
| 2297 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2298 | & mActiveHistoryStates; |
| 2299 | if (mHistoryLastWritten.states != curStates) { |
| 2300 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2301 | // forced to 0. |
| 2302 | int old = mActiveHistoryStates; |
| 2303 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2304 | writeAnyway |= old != mActiveHistoryStates; |
| 2305 | } |
| 2306 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2307 | & mActiveHistoryStates2; |
| 2308 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2309 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2310 | // forced to 0. |
| 2311 | int old = mActiveHistoryStates2; |
| 2312 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2313 | writeAnyway |= old != mActiveHistoryStates2; |
| 2314 | } |
| 2315 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2316 | // Once we've reached the maximum number of items, we only |
| 2317 | // record changes to the battery level and the most interesting states. |
| 2318 | // Once we've reached the maximum maximum number of items, we only |
| 2319 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2320 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2321 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2322 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2323 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2324 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2325 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2326 | return; |
| 2327 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2328 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2329 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2330 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2333 | if (dataSize == 0) { |
| 2334 | // The history is currently empty; we need it to start with a time stamp. |
| 2335 | cur.currentTime = System.currentTimeMillis(); |
| 2336 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2337 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2338 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2341 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2342 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2343 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2344 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2345 | } |
| 2346 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2347 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2348 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2349 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2350 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2351 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2352 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2353 | cur.wakelockTag = null; |
| 2354 | cur.wakeReasonTag = null; |
| 2355 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2356 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2357 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2358 | + " now " + mHistoryBuffer.dataPosition() |
| 2359 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2362 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2363 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2364 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2365 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2366 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2367 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2368 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2369 | if (diffUptime < (diffElapsed-20)) { |
| 2370 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2371 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2372 | mHistoryAddTmp.wakelockTag = null; |
| 2373 | mHistoryAddTmp.wakeReasonTag = null; |
| 2374 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2375 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2376 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2377 | } |
| 2378 | } |
| 2379 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2380 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2381 | mTrackRunningHistoryUptime = uptimeMs; |
| 2382 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2383 | } |
| 2384 | |
| 2385 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2386 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2387 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2388 | if (!USE_OLD_HISTORY) { |
| 2389 | return; |
| 2390 | } |
| 2391 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2392 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2393 | return; |
| 2394 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2395 | |
| 2396 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2397 | // and no states have since the last recorded entry changed and |
| 2398 | // are now resetting back to their original value, then just collapse |
| 2399 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2400 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2401 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2402 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2403 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2404 | // If the current is the same as the one before, then we no |
| 2405 | // longer need the entry. |
| 2406 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2407 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2408 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2409 | mHistoryLastEnd.next = null; |
| 2410 | mHistoryEnd.next = mHistoryCache; |
| 2411 | mHistoryCache = mHistoryEnd; |
| 2412 | mHistoryEnd = mHistoryLastEnd; |
| 2413 | mHistoryLastEnd = null; |
| 2414 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2415 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2416 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2417 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2418 | } |
| 2419 | return; |
| 2420 | } |
| 2421 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2422 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2423 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2424 | |
| 2425 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2426 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2427 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2430 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2431 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2432 | // record changes to the battery level and the most interesting states. |
| 2433 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2434 | // record changes to the battery level. |
| 2435 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2436 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2437 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2438 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2439 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2440 | return; |
| 2441 | } |
| 2442 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2443 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2444 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2445 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2446 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2447 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2448 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2449 | mHistoryCur.eventCode = code; |
| 2450 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2451 | mHistoryCur.eventTag.string = name; |
| 2452 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2453 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2454 | } |
| 2455 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2456 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2457 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2458 | if (rec != null) { |
| 2459 | mHistoryCache = rec.next; |
| 2460 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2461 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2462 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2463 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2464 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2465 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2466 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2467 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2468 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2469 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2470 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2471 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2472 | if (mHistoryEnd != null) { |
| 2473 | mHistoryEnd.next = rec; |
| 2474 | mHistoryEnd = rec; |
| 2475 | } else { |
| 2476 | mHistory = mHistoryEnd = rec; |
| 2477 | } |
| 2478 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2479 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2480 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2481 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2482 | if (USE_OLD_HISTORY) { |
| 2483 | if (mHistory != null) { |
| 2484 | mHistoryEnd.next = mHistoryCache; |
| 2485 | mHistoryCache = mHistory; |
| 2486 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2487 | } |
| 2488 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2489 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2490 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2491 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2492 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2493 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2494 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2495 | |
| 2496 | mHistoryBuffer.setDataSize(0); |
| 2497 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2498 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2499 | mHistoryLastLastWritten.clear(); |
| 2500 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2501 | mHistoryTagPool.clear(); |
| 2502 | mNextHistoryTagIdx = 0; |
| 2503 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2504 | mHistoryBufferLastPos = -1; |
| 2505 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2506 | mActiveHistoryStates = 0xffffffff; |
| 2507 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2508 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2509 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2510 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2511 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2512 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2513 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2514 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2515 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2516 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2517 | if (DEBUG_ENERGY_CPU) { |
| 2518 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 2519 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2520 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2521 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2522 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | } |
| 2524 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2525 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2526 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2527 | mIsolatedUids.put(isolatedUid, appUid); |
| 2528 | } |
| 2529 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2530 | /** |
| 2531 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 2532 | * @see #removeIsolatedUidLocked(int) |
| 2533 | */ |
| 2534 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2535 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2536 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2537 | if (mExternalSync != null) { |
| 2538 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 2539 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2540 | } |
| 2541 | } |
| 2542 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2543 | /** |
| 2544 | * This should only be called after the cpu times have been read. |
| 2545 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 2546 | */ |
| 2547 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 2548 | mIsolatedUids.delete(isolatedUid); |
| 2549 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 2550 | } |
| 2551 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2552 | public int mapUid(int uid) { |
| 2553 | int isolated = mIsolatedUids.get(uid, -1); |
| 2554 | return isolated > 0 ? isolated : uid; |
| 2555 | } |
| 2556 | |
| 2557 | public void noteEventLocked(int code, String name, int uid) { |
| 2558 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2559 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2560 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2561 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2562 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2563 | final long uptime = SystemClock.uptimeMillis(); |
| 2564 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2565 | } |
| 2566 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2567 | boolean ensureStartClockTime(final long currentTime) { |
| 2568 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 2569 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 2570 | // If the start clock time has changed by more than a year, then presumably |
| 2571 | // the previous time was completely bogus. So we are going to figure out a |
| 2572 | // new time based on how much time has elapsed since we started counting. |
| 2573 | mStartClockTime = currentTime - (SystemClock.elapsedRealtime()-(mRealtimeStart/1000)); |
| 2574 | return true; |
| 2575 | } |
| 2576 | return false; |
| 2577 | } |
| 2578 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2579 | public void noteCurrentTimeChangedLocked() { |
| 2580 | final long currentTime = System.currentTimeMillis(); |
| 2581 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2582 | final long uptime = SystemClock.uptimeMillis(); |
| 2583 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2584 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2587 | public void noteProcessStartLocked(String name, int uid) { |
| 2588 | uid = mapUid(uid); |
| 2589 | if (isOnBattery()) { |
| 2590 | Uid u = getUidStatsLocked(uid); |
| 2591 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2592 | } |
| 2593 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2594 | return; |
| 2595 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2596 | if (!mRecordAllHistory) { |
| 2597 | return; |
| 2598 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2599 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2600 | final long uptime = SystemClock.uptimeMillis(); |
| 2601 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2602 | } |
| 2603 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2604 | public void noteProcessCrashLocked(String name, int uid) { |
| 2605 | uid = mapUid(uid); |
| 2606 | if (isOnBattery()) { |
| 2607 | Uid u = getUidStatsLocked(uid); |
| 2608 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | public void noteProcessAnrLocked(String name, int uid) { |
| 2613 | uid = mapUid(uid); |
| 2614 | if (isOnBattery()) { |
| 2615 | Uid u = getUidStatsLocked(uid); |
| 2616 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2617 | } |
| 2618 | } |
| 2619 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2620 | public void noteProcessStateLocked(String name, int uid, int state) { |
| 2621 | uid = mapUid(uid); |
| 2622 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2623 | getUidStatsLocked(uid).updateProcessStateLocked(name, state, elapsedRealtime); |
| 2624 | } |
| 2625 | |
| 2626 | public void noteProcessFinishLocked(String name, int uid) { |
| 2627 | uid = mapUid(uid); |
| 2628 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2629 | return; |
| 2630 | } |
| 2631 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2632 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2633 | getUidStatsLocked(uid).updateProcessStateLocked(name, Uid.PROCESS_STATE_NONE, |
| 2634 | elapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2635 | if (!mRecordAllHistory) { |
| 2636 | return; |
| 2637 | } |
| 2638 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2641 | public void noteSyncStartLocked(String name, int uid) { |
| 2642 | uid = mapUid(uid); |
| 2643 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2644 | final long uptime = SystemClock.uptimeMillis(); |
| 2645 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2646 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2647 | return; |
| 2648 | } |
| 2649 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2650 | } |
| 2651 | |
| 2652 | public void noteSyncFinishLocked(String name, int uid) { |
| 2653 | uid = mapUid(uid); |
| 2654 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2655 | final long uptime = SystemClock.uptimeMillis(); |
| 2656 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2657 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2658 | return; |
| 2659 | } |
| 2660 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2661 | } |
| 2662 | |
| 2663 | public void noteJobStartLocked(String name, int uid) { |
| 2664 | uid = mapUid(uid); |
| 2665 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2666 | final long uptime = SystemClock.uptimeMillis(); |
| 2667 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2668 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2669 | return; |
| 2670 | } |
| 2671 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2672 | } |
| 2673 | |
| 2674 | public void noteJobFinishLocked(String name, int uid) { |
| 2675 | uid = mapUid(uid); |
| 2676 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2677 | final long uptime = SystemClock.uptimeMillis(); |
| 2678 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2679 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2680 | return; |
| 2681 | } |
| 2682 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2683 | } |
| 2684 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2685 | public void noteAlarmStartLocked(String name, int uid) { |
| 2686 | if (!mRecordAllHistory) { |
| 2687 | return; |
| 2688 | } |
| 2689 | uid = mapUid(uid); |
| 2690 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2691 | final long uptime = SystemClock.uptimeMillis(); |
| 2692 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 2693 | return; |
| 2694 | } |
| 2695 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 2696 | } |
| 2697 | |
| 2698 | public void noteAlarmFinishLocked(String name, int uid) { |
| 2699 | if (!mRecordAllHistory) { |
| 2700 | return; |
| 2701 | } |
| 2702 | uid = mapUid(uid); |
| 2703 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 2704 | final long uptime = SystemClock.uptimeMillis(); |
| 2705 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 2706 | return; |
| 2707 | } |
| 2708 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 2709 | } |
| 2710 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2711 | private void requestWakelockCpuUpdate() { |
| 2712 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2713 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2714 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2715 | } |
| 2716 | } |
| 2717 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2718 | private void requestImmediateCpuUpdate() { |
| 2719 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2720 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 2721 | } |
| 2722 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2723 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 2724 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2725 | if (!enabled) { |
| 2726 | // Clear out any existing state. |
| 2727 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2728 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2729 | // Record the currently running processes as stopping, now that we are no |
| 2730 | // longer tracking them. |
| 2731 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2732 | HistoryItem.EVENT_PROC); |
| 2733 | if (active != null) { |
| 2734 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2735 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2736 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2737 | SparseIntArray uids = ent.getValue(); |
| 2738 | for (int j=0; j<uids.size(); j++) { |
| 2739 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2740 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 2741 | } |
| 2742 | } |
| 2743 | } |
| 2744 | } else { |
| 2745 | // Record the currently running processes as starting, now that we are tracking them. |
| 2746 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2747 | HistoryItem.EVENT_PROC); |
| 2748 | if (active != null) { |
| 2749 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 2750 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 2751 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2752 | SparseIntArray uids = ent.getValue(); |
| 2753 | for (int j=0; j<uids.size(); j++) { |
| 2754 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2755 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 2756 | } |
| 2757 | } |
| 2758 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2759 | } |
| 2760 | } |
| 2761 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2762 | public void setNoAutoReset(boolean enabled) { |
| 2763 | mNoAutoReset = enabled; |
| 2764 | } |
| 2765 | |
| 2766 | private String mInitialAcquireWakeName; |
| 2767 | private int mInitialAcquireWakeUid = -1; |
| 2768 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2769 | 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] | 2770 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2771 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2772 | if (type == WAKE_TYPE_PARTIAL) { |
| 2773 | // Only care about partial wake locks, since full wake locks |
| 2774 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2775 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2776 | if (historyName == null) { |
| 2777 | historyName = name; |
| 2778 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2779 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2780 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 2781 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2782 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2783 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2784 | } |
| 2785 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2786 | if (mWakeLockNesting == 0) { |
| 2787 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2788 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 2789 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2790 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2791 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2792 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2793 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2794 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2795 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 2796 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2797 | if (mHistoryLastWritten.wakelockTag != null) { |
| 2798 | // We'll try to update the last tag. |
| 2799 | mHistoryLastWritten.wakelockTag = null; |
| 2800 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2801 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2802 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2803 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2804 | } |
| 2805 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2806 | } |
| 2807 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2808 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2809 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2810 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2811 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 2812 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 2813 | if (DEBUG_ENERGY_CPU) { |
| 2814 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 2815 | } |
| 2816 | requestWakelockCpuUpdate(); |
| 2817 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2818 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2819 | } |
| 2820 | } |
| 2821 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2822 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 2823 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2824 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2825 | if (type == WAKE_TYPE_PARTIAL) { |
| 2826 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2827 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2828 | if (historyName == null) { |
| 2829 | historyName = name; |
| 2830 | } |
| 2831 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 2832 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2833 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2834 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 2835 | } |
| 2836 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2837 | if (mWakeLockNesting == 0) { |
| 2838 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 2839 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 2840 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2841 | mInitialAcquireWakeName = null; |
| 2842 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2843 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2844 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2845 | } |
| 2846 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2847 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2848 | if (DEBUG_ENERGY_CPU) { |
| 2849 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 2850 | } |
| 2851 | requestWakelockCpuUpdate(); |
| 2852 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2853 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2854 | } |
| 2855 | } |
| 2856 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2857 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2858 | String historyName, int type, boolean unimportantForLogging) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2859 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2860 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2861 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2862 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2863 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2864 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2865 | } |
| 2866 | } |
| 2867 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2868 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 2869 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2870 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
| 2871 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2872 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2873 | // For correct semantics, we start the need worksources first, so that we won't |
| 2874 | // make inappropriate history items as if all wake locks went away and new ones |
| 2875 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2876 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2877 | for (int i=0; i<NN; i++) { |
| 2878 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2879 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2880 | } |
| 2881 | final int NO = ws.size(); |
| 2882 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2883 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2884 | } |
| 2885 | } |
| 2886 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2887 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 2888 | String historyName, int type) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2889 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2890 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2891 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2892 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2893 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2894 | } |
| 2895 | } |
| 2896 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2897 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 2898 | if (mLastWakeupReason != null) { |
| 2899 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2900 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
| 2901 | timer.addCurrentReportedCount(1); |
| 2902 | timer.addCurrentReportedTotalTime(deltaUptime * 1000); // time is in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2903 | mLastWakeupReason = null; |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | public void noteWakeupReasonLocked(String reason) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2908 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2909 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2910 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2911 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2912 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2913 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 2914 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2915 | mHistoryCur.wakeReasonTag.uid = 0; |
| 2916 | mLastWakeupReason = reason; |
| 2917 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2918 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2919 | } |
| 2920 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2921 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2922 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2923 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2926 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 2927 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 2928 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2929 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 2930 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 2931 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 2932 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 2933 | mCurStepCpuUserTime += totalUTime; |
| 2934 | mCurStepCpuSystemTime += totalSTime; |
| 2935 | mCurStepStatUserTime += statUserTime; |
| 2936 | mCurStepStatSystemTime += statSystemTime; |
| 2937 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 2938 | mCurStepStatIrqTime += statIrqTime; |
| 2939 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 2940 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2943 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2944 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2945 | Uid u = mUidStats.get(uid); |
| 2946 | if (u != null) { |
| 2947 | u.mPids.remove(pid); |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2952 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2953 | Uid u = mUidStats.get(uid); |
| 2954 | if (u != null) { |
| 2955 | Uid.Pid p = u.mPids.get(pid); |
| 2956 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2957 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2958 | } |
| 2959 | } |
| 2960 | return 0; |
| 2961 | } |
| 2962 | |
| 2963 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2964 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2965 | Uid u = mUidStats.get(uid); |
| 2966 | if (u != null) { |
| 2967 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 2968 | } |
| 2969 | } |
| 2970 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2971 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2972 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2973 | Uid u = mUidStats.get(uid); |
| 2974 | if (u != null) { |
| 2975 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 2976 | } |
| 2977 | } |
| 2978 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2979 | int mSensorNesting; |
| 2980 | |
| 2981 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2982 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2983 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2984 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2985 | if (mSensorNesting == 0) { |
| 2986 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 2987 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 2988 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2989 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2990 | } |
| 2991 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2992 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2996 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2997 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2998 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2999 | mSensorNesting--; |
| 3000 | if (mSensorNesting == 0) { |
| 3001 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3002 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3003 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3004 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3005 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3006 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3009 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3010 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3011 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3012 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3013 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3014 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3015 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3016 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3017 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3018 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3019 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3020 | } |
| 3021 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3022 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3024 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3025 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3026 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3027 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3028 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3029 | mGpsNesting--; |
| 3030 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3031 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3032 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3033 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3034 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3035 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3036 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3038 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3039 | public void noteScreenStateLocked(int state) { |
| 3040 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3041 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3042 | final int oldState = mScreenState; |
| 3043 | mScreenState = state; |
| 3044 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3045 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3046 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3047 | if (state != Display.STATE_UNKNOWN) { |
| 3048 | int stepState = state-1; |
| 3049 | if (stepState < 4) { |
| 3050 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3051 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3052 | } else { |
| 3053 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3054 | } |
| 3055 | } |
| 3056 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3057 | if (state == Display.STATE_ON) { |
| 3058 | // Screen turning on. |
| 3059 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3060 | final long uptime = SystemClock.uptimeMillis(); |
| 3061 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3062 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3063 | + Integer.toHexString(mHistoryCur.states)); |
| 3064 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3065 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3066 | if (mScreenBrightnessBin >= 0) { |
| 3067 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3068 | } |
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 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
| 3071 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3072 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3073 | // Fake a wake lock, so we consider the device waked as long |
| 3074 | // as the screen is on. |
| 3075 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3076 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3077 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3078 | // Update discharge amounts. |
| 3079 | if (mOnBatteryInternal) { |
| 3080 | updateDischargeScreenLevelsLocked(false, true); |
| 3081 | } |
| 3082 | } else if (oldState == Display.STATE_ON) { |
| 3083 | // Screen turning off or dozing. |
| 3084 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3085 | final long uptime = SystemClock.uptimeMillis(); |
| 3086 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3087 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3088 | + Integer.toHexString(mHistoryCur.states)); |
| 3089 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3090 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3091 | if (mScreenBrightnessBin >= 0) { |
| 3092 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3093 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3094 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3095 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3096 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3097 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3098 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
| 3099 | SystemClock.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3100 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3101 | // Update discharge amounts. |
| 3102 | if (mOnBatteryInternal) { |
| 3103 | updateDischargeScreenLevelsLocked(true, false); |
| 3104 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3105 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3106 | } |
| 3107 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3108 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3109 | public void noteScreenBrightnessLocked(int brightness) { |
| 3110 | // Bin the brightness. |
| 3111 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3112 | if (bin < 0) bin = 0; |
| 3113 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3114 | if (mScreenBrightnessBin != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3115 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3116 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3117 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3118 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3119 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3120 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3121 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3122 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3123 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3124 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3125 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3126 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3127 | } |
| 3128 | mScreenBrightnessBin = bin; |
| 3129 | } |
| 3130 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3131 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3132 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3133 | if (mOnBatteryInternal) { |
| 3134 | uid = mapUid(uid); |
| 3135 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3136 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3138 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3139 | public void noteWakeUpLocked(String reason, int reasonUid) { |
| 3140 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3141 | final long uptime = SystemClock.uptimeMillis(); |
| 3142 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3143 | reason, reasonUid); |
| 3144 | } |
| 3145 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3146 | public void noteInteractiveLocked(boolean interactive) { |
| 3147 | if (mInteractive != interactive) { |
| 3148 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3149 | mInteractive = interactive; |
| 3150 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3151 | if (interactive) { |
| 3152 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3153 | } else { |
| 3154 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3155 | } |
| 3156 | } |
| 3157 | } |
| 3158 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3159 | public void noteConnectivityChangedLocked(int type, String extra) { |
| 3160 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3161 | final long uptime = SystemClock.uptimeMillis(); |
| 3162 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3163 | extra, type); |
| 3164 | mNumConnectivityChange++; |
| 3165 | } |
| 3166 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3167 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
| 3168 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3169 | final long uptime = SystemClock.uptimeMillis(); |
| 3170 | if (mMobileRadioPowerState != powerState) { |
| 3171 | long realElapsedRealtimeMs; |
| 3172 | final boolean active = |
| 3173 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3174 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3175 | if (active) { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3176 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3177 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3178 | } else { |
| 3179 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3180 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3181 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3182 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3183 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3184 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3185 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3186 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3187 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3188 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3189 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3190 | } |
| 3191 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3192 | + Integer.toHexString(mHistoryCur.states)); |
| 3193 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3194 | mMobileRadioPowerState = powerState; |
| 3195 | if (active) { |
| 3196 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3197 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3198 | } else { |
| 3199 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 3200 | updateMobileRadioStateLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3201 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3202 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3206 | public void notePowerSaveMode(boolean enabled) { |
| 3207 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3208 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3209 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3210 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3211 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3212 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3213 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3214 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3215 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3216 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3217 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3218 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3219 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3220 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3221 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3222 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3223 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3224 | } |
| 3225 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3226 | } |
| 3227 | } |
| 3228 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3229 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3230 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3231 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3232 | boolean nowIdling = mode == DEVICE_IDLE_MODE_FULL; |
| 3233 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3234 | // We don't go out of general idling mode until explicitly taken out of |
| 3235 | // device idle through going active or significant motion. |
| 3236 | nowIdling = true; |
| 3237 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3238 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 3239 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 3240 | // We don't go out of general light idling mode until explicitly taken out of |
| 3241 | // device idle through going active or significant motion. |
| 3242 | nowLightIdling = true; |
| 3243 | } |
| 3244 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 3245 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3246 | activeReason, activeUid); |
| 3247 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3248 | if (mDeviceIdling != nowIdling) { |
| 3249 | mDeviceIdling = nowIdling; |
| 3250 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3251 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3252 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3253 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3254 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3255 | } else { |
| 3256 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3257 | } |
| 3258 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3259 | if (mDeviceLightIdling != nowLightIdling) { |
| 3260 | mDeviceLightIdling = nowLightIdling; |
| 3261 | if (nowLightIdling) { |
| 3262 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3263 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3264 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3265 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3266 | } |
| 3267 | if (mDeviceIdleMode != mode) { |
| 3268 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 3269 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 3270 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 3271 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3272 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 3273 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 3274 | mLastIdleTimeStart = elapsedRealtime; |
| 3275 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 3276 | if (lastDuration > mLongestLightIdleTime) { |
| 3277 | mLongestLightIdleTime = lastDuration; |
| 3278 | } |
| 3279 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
| 3280 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_FULL) { |
| 3281 | if (lastDuration > mLongestFullIdleTime) { |
| 3282 | mLongestFullIdleTime = lastDuration; |
| 3283 | } |
| 3284 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 3285 | } |
| 3286 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 3287 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
| 3288 | } else if (mode == DEVICE_IDLE_MODE_FULL) { |
| 3289 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 3290 | } |
| 3291 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
| 3296 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3297 | final long uptime = SystemClock.uptimeMillis(); |
| 3298 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3299 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3300 | PackageChange pc = new PackageChange(); |
| 3301 | pc.mPackageName = pkgName; |
| 3302 | pc.mUpdate = true; |
| 3303 | pc.mVersionCode = versionCode; |
| 3304 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | public void notePackageUninstalledLocked(String pkgName) { |
| 3308 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3309 | final long uptime = SystemClock.uptimeMillis(); |
| 3310 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3311 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3312 | PackageChange pc = new PackageChange(); |
| 3313 | pc.mPackageName = pkgName; |
| 3314 | pc.mUpdate = true; |
| 3315 | addPackageChange(pc); |
| 3316 | } |
| 3317 | |
| 3318 | private void addPackageChange(PackageChange pc) { |
| 3319 | if (mDailyPackageChanges == null) { |
| 3320 | mDailyPackageChanges = new ArrayList<>(); |
| 3321 | } |
| 3322 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3323 | } |
| 3324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | public void notePhoneOnLocked() { |
| 3326 | if (!mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3327 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3328 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3329 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3330 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3331 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3332 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3334 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | } |
| 3336 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | public void notePhoneOffLocked() { |
| 3339 | if (mPhoneOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3340 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3341 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3342 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3343 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3344 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3345 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3347 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | } |
| 3349 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3350 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3351 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3352 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3353 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3354 | if (i == except) { |
| 3355 | continue; |
| 3356 | } |
| 3357 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3358 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3359 | } |
| 3360 | } |
| 3361 | } |
| 3362 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3363 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3364 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3365 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3366 | // to infer that we are scanning from other data. |
| 3367 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3368 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3369 | state = ServiceState.STATE_IN_SERVICE; |
| 3370 | } |
| 3371 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3372 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3373 | return state; |
| 3374 | } |
| 3375 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3376 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3377 | boolean scanning = false; |
| 3378 | boolean newHistory = false; |
| 3379 | |
| 3380 | mPhoneServiceStateRaw = state; |
| 3381 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3382 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3383 | |
| 3384 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3385 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3386 | |
| 3387 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3388 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3389 | // to infer that we are scanning from other data. |
| 3390 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3391 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3392 | state = ServiceState.STATE_IN_SERVICE; |
| 3393 | } |
| 3394 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3395 | |
| 3396 | // If the phone is powered off, stop all timers. |
| 3397 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3398 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3399 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3400 | // If we are in service, make sure the correct signal string timer is running. |
| 3401 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3402 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3403 | |
| 3404 | // If we're out of service, we are in the lowest signal strength |
| 3405 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3406 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3407 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3408 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3409 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3410 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3411 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3412 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3413 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3414 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3415 | } |
| 3416 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3417 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3418 | if (!scanning) { |
| 3419 | // If we are no longer scanning, then stop the scanning timer. |
| 3420 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3421 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3422 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3423 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3424 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3425 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3429 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3430 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3431 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3432 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3433 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3434 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3435 | mPhoneServiceState = state; |
| 3436 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3437 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3438 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3439 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3440 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3441 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3442 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3443 | if (strengthBin >= 0) { |
| 3444 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3445 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3446 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3447 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3448 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3449 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3450 | + Integer.toHexString(mHistoryCur.states)); |
| 3451 | newHistory = true; |
| 3452 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3453 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3454 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3455 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3459 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | /** |
| 3464 | * Telephony stack updates the phone state. |
| 3465 | * @param state phone state from ServiceState.getState() |
| 3466 | */ |
| 3467 | public void notePhoneStateLocked(int state, int simState) { |
| 3468 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3471 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3472 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3473 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3474 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3475 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3476 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3477 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3478 | int bin = DATA_CONNECTION_NONE; |
| 3479 | if (hasData) { |
| 3480 | switch (dataType) { |
| 3481 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3482 | bin = DATA_CONNECTION_EDGE; |
| 3483 | break; |
| 3484 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3485 | bin = DATA_CONNECTION_GPRS; |
| 3486 | break; |
| 3487 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3488 | bin = DATA_CONNECTION_UMTS; |
| 3489 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3490 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3491 | bin = DATA_CONNECTION_CDMA; |
| 3492 | break; |
| 3493 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3494 | bin = DATA_CONNECTION_EVDO_0; |
| 3495 | break; |
| 3496 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3497 | bin = DATA_CONNECTION_EVDO_A; |
| 3498 | break; |
| 3499 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3500 | bin = DATA_CONNECTION_1xRTT; |
| 3501 | break; |
| 3502 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3503 | bin = DATA_CONNECTION_HSDPA; |
| 3504 | break; |
| 3505 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3506 | bin = DATA_CONNECTION_HSUPA; |
| 3507 | break; |
| 3508 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3509 | bin = DATA_CONNECTION_HSPA; |
| 3510 | break; |
| 3511 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3512 | bin = DATA_CONNECTION_IDEN; |
| 3513 | break; |
| 3514 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3515 | bin = DATA_CONNECTION_EVDO_B; |
| 3516 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3517 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3518 | bin = DATA_CONNECTION_LTE; |
| 3519 | break; |
| 3520 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3521 | bin = DATA_CONNECTION_EHRPD; |
| 3522 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3523 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3524 | bin = DATA_CONNECTION_HSPAP; |
| 3525 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3526 | default: |
| 3527 | bin = DATA_CONNECTION_OTHER; |
| 3528 | break; |
| 3529 | } |
| 3530 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3531 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3532 | if (mPhoneDataConnectionType != bin) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3533 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3534 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3535 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3536 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3537 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3538 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3539 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3540 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3541 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3542 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3543 | } |
| 3544 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3545 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3546 | } |
| 3547 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3548 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3549 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3550 | if (!mWifiOn) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3551 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3552 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3553 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3554 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3555 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3556 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3557 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3558 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 3559 | scheduleSyncExternalWifiStatsLocked("wifi-off"); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3560 | } |
| 3561 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3562 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3563 | public void noteWifiOffLocked() { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3564 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3565 | final long uptime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3566 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3567 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3568 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3569 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3570 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3571 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3572 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 3573 | scheduleSyncExternalWifiStatsLocked("wifi-on"); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3574 | } |
| 3575 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3576 | |
| 3577 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3578 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3579 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3580 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3581 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3582 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3583 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3584 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3585 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3586 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3587 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3588 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3589 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3590 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3591 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3592 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3593 | if (mAudioOnNesting == 0) { |
| 3594 | return; |
| 3595 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3596 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3597 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3598 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3599 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3600 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3601 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3602 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3603 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3604 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3605 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3606 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3610 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3611 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3612 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3613 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3614 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3615 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3616 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3617 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3618 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3619 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3620 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3621 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3622 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3623 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3624 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3625 | if (mVideoOnNesting == 0) { |
| 3626 | return; |
| 3627 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3628 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3629 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3630 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3631 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3632 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3633 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3634 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3635 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3636 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3637 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3638 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3641 | public void noteResetAudioLocked() { |
| 3642 | if (mAudioOnNesting > 0) { |
| 3643 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3644 | final long uptime = SystemClock.uptimeMillis(); |
| 3645 | mAudioOnNesting = 0; |
| 3646 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3647 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3648 | + Integer.toHexString(mHistoryCur.states)); |
| 3649 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3650 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3651 | for (int i=0; i<mUidStats.size(); i++) { |
| 3652 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3653 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3654 | } |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | public void noteResetVideoLocked() { |
| 3659 | if (mVideoOnNesting > 0) { |
| 3660 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3661 | final long uptime = SystemClock.uptimeMillis(); |
| 3662 | mAudioOnNesting = 0; |
| 3663 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3664 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3665 | + Integer.toHexString(mHistoryCur.states)); |
| 3666 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3667 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3668 | for (int i=0; i<mUidStats.size(); i++) { |
| 3669 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3670 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3671 | } |
| 3672 | } |
| 3673 | } |
| 3674 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3675 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3676 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3677 | getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3681 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3682 | getUidStatsLocked(uid).noteActivityPausedLocked(SystemClock.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3685 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3686 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3687 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3688 | } |
| 3689 | |
| 3690 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3691 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3692 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3693 | } |
| 3694 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3695 | public void noteFlashlightOnLocked(int uid) { |
| 3696 | uid = mapUid(uid); |
| 3697 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3698 | final long uptime = SystemClock.uptimeMillis(); |
| 3699 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3700 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3701 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3702 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3703 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3704 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3705 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3706 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 3707 | } |
| 3708 | |
| 3709 | public void noteFlashlightOffLocked(int uid) { |
| 3710 | if (mFlashlightOnNesting == 0) { |
| 3711 | return; |
| 3712 | } |
| 3713 | uid = mapUid(uid); |
| 3714 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3715 | final long uptime = SystemClock.uptimeMillis(); |
| 3716 | if (--mFlashlightOnNesting == 0) { |
| 3717 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3718 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3719 | + Integer.toHexString(mHistoryCur.states2)); |
| 3720 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3721 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3722 | } |
| 3723 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 3724 | } |
| 3725 | |
| 3726 | public void noteCameraOnLocked(int uid) { |
| 3727 | uid = mapUid(uid); |
| 3728 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3729 | final long uptime = SystemClock.uptimeMillis(); |
| 3730 | if (mCameraOnNesting++ == 0) { |
| 3731 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 3732 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 3733 | + Integer.toHexString(mHistoryCur.states2)); |
| 3734 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3735 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 3736 | } |
| 3737 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 3738 | } |
| 3739 | |
| 3740 | public void noteCameraOffLocked(int uid) { |
| 3741 | if (mCameraOnNesting == 0) { |
| 3742 | return; |
| 3743 | } |
| 3744 | uid = mapUid(uid); |
| 3745 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3746 | final long uptime = SystemClock.uptimeMillis(); |
| 3747 | if (--mCameraOnNesting == 0) { |
| 3748 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3749 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3750 | + Integer.toHexString(mHistoryCur.states2)); |
| 3751 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3752 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 3753 | } |
| 3754 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 3755 | } |
| 3756 | |
| 3757 | public void noteResetCameraLocked() { |
| 3758 | if (mCameraOnNesting > 0) { |
| 3759 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3760 | final long uptime = SystemClock.uptimeMillis(); |
| 3761 | mCameraOnNesting = 0; |
| 3762 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3763 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3764 | + Integer.toHexString(mHistoryCur.states2)); |
| 3765 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3766 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3767 | for (int i=0; i<mUidStats.size(); i++) { |
| 3768 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3769 | uid.noteResetCameraLocked(elapsedRealtime); |
| 3770 | } |
| 3771 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3774 | public void noteResetFlashlightLocked() { |
| 3775 | if (mFlashlightOnNesting > 0) { |
| 3776 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3777 | final long uptime = SystemClock.uptimeMillis(); |
| 3778 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3779 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3780 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3781 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3782 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3783 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3784 | for (int i=0; i<mUidStats.size(); i++) { |
| 3785 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3786 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 3787 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3788 | } |
| 3789 | } |
| 3790 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3791 | public void noteWifiRadioPowerState(int powerState, long timestampNs) { |
| 3792 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3793 | final long uptime = SystemClock.uptimeMillis(); |
| 3794 | if (mWifiRadioPowerState != powerState) { |
| 3795 | final boolean active = |
| 3796 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3797 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3798 | if (active) { |
| 3799 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 3800 | } else { |
| 3801 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 3802 | } |
| 3803 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 3804 | + Integer.toHexString(mHistoryCur.states)); |
| 3805 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3806 | mWifiRadioPowerState = powerState; |
| 3807 | } |
| 3808 | } |
| 3809 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3810 | public void noteWifiRunningLocked(WorkSource ws) { |
| 3811 | if (!mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3812 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3813 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3814 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3815 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 3816 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3817 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3818 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3819 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3820 | int N = ws.size(); |
| 3821 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3822 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3823 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3824 | } |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 3825 | scheduleSyncExternalWifiStatsLocked("wifi-running"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3826 | } else { |
| 3827 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3828 | } |
| 3829 | } |
| 3830 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3831 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 3832 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3833 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3834 | int N = oldWs.size(); |
| 3835 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3836 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3837 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3838 | } |
| 3839 | N = newWs.size(); |
| 3840 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3841 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3842 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3843 | } |
| 3844 | } else { |
| 3845 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 3850 | if (mGlobalWifiRunning) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3851 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3852 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3853 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3854 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 3855 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3856 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3857 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3858 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3859 | int N = ws.size(); |
| 3860 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3861 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3862 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3863 | } |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 3864 | scheduleSyncExternalWifiStatsLocked("wifi-stopped"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3865 | } else { |
| 3866 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3870 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 3871 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 3872 | if (mWifiState != wifiState) { |
| 3873 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3874 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3875 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3876 | } |
| 3877 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3878 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 3879 | scheduleSyncExternalWifiStatsLocked("wifi-state"); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3883 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 3884 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 3885 | if (mWifiSupplState != supplState) { |
| 3886 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3887 | final long uptime = SystemClock.uptimeMillis(); |
| 3888 | if (mWifiSupplState >= 0) { |
| 3889 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 3890 | } |
| 3891 | mWifiSupplState = supplState; |
| 3892 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 3893 | mHistoryCur.states2 = |
| 3894 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 3895 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 3896 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 3897 | + Integer.toHexString(mHistoryCur.states2)); |
| 3898 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3899 | } |
| 3900 | } |
| 3901 | |
| 3902 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
| 3903 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3904 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3905 | if (i == except) { |
| 3906 | continue; |
| 3907 | } |
| 3908 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 3909 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 3910 | } |
| 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 3915 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 3916 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 3917 | if (mWifiSignalStrengthBin != strengthBin) { |
| 3918 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 3919 | final long uptime = SystemClock.uptimeMillis(); |
| 3920 | if (mWifiSignalStrengthBin >= 0) { |
| 3921 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 3922 | elapsedRealtime); |
| 3923 | } |
| 3924 | if (strengthBin >= 0) { |
| 3925 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 3926 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 3927 | } |
| 3928 | mHistoryCur.states2 = |
| 3929 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 3930 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 3931 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 3932 | + Integer.toHexString(mHistoryCur.states2)); |
| 3933 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3934 | } else { |
| 3935 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 3936 | } |
| 3937 | mWifiSignalStrengthBin = strengthBin; |
| 3938 | } |
| 3939 | } |
| 3940 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3941 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3942 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3943 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3944 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3945 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3946 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3947 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3948 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3949 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 3950 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3951 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3952 | } |
| 3953 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3954 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3955 | } |
| 3956 | |
| 3957 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3958 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3959 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3960 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3961 | mWifiFullLockNesting--; |
| 3962 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3963 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3964 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 3965 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3966 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3967 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3968 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3971 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3972 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3973 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3974 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3975 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3976 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3977 | if (mWifiScanNesting == 0) { |
| 3978 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3979 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3980 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3981 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3982 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3983 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3984 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3987 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3988 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3989 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3990 | final long uptime = SystemClock.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 3991 | mWifiScanNesting--; |
| 3992 | if (mWifiScanNesting == 0) { |
| 3993 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 3994 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3995 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3996 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3997 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3998 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3999 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4000 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4001 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4002 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4003 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4004 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4008 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4009 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4010 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4013 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4014 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4015 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4016 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4017 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4018 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4019 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4020 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4021 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4022 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4023 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4024 | } |
| 4025 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4026 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4030 | uid = mapUid(uid); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4031 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4032 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4033 | mWifiMulticastNesting--; |
| 4034 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4035 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4036 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4037 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4038 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4039 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4040 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4043 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4044 | int N = ws.size(); |
| 4045 | for (int i=0; i<N; i++) { |
| 4046 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4051 | int N = ws.size(); |
| 4052 | for (int i=0; i<N; i++) { |
| 4053 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4054 | } |
| 4055 | } |
| 4056 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4057 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4058 | int N = ws.size(); |
| 4059 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4060 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4061 | } |
| 4062 | } |
| 4063 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4064 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4065 | int N = ws.size(); |
| 4066 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4067 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4071 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4072 | int N = ws.size(); |
| 4073 | for (int i=0; i<N; i++) { |
| 4074 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4079 | int N = ws.size(); |
| 4080 | for (int i=0; i<N; i++) { |
| 4081 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4082 | } |
| 4083 | } |
| 4084 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4085 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4086 | int N = ws.size(); |
| 4087 | for (int i=0; i<N; i++) { |
| 4088 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4093 | int N = ws.size(); |
| 4094 | for (int i=0; i<N; i++) { |
| 4095 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4096 | } |
| 4097 | } |
| 4098 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4099 | private static String[] includeInStringArray(String[] array, String str) { |
| 4100 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4101 | return array; |
| 4102 | } |
| 4103 | String[] newArray = new String[array.length+1]; |
| 4104 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4105 | newArray[array.length] = str; |
| 4106 | return newArray; |
| 4107 | } |
| 4108 | |
| 4109 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4110 | int index = ArrayUtils.indexOf(array, str); |
| 4111 | if (index >= 0) { |
| 4112 | String[] newArray = new String[array.length-1]; |
| 4113 | if (index > 0) { |
| 4114 | System.arraycopy(array, 0, newArray, 0, index); |
| 4115 | } |
| 4116 | if (index < array.length-1) { |
| 4117 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4118 | } |
| 4119 | return newArray; |
| 4120 | } |
| 4121 | return array; |
| 4122 | } |
| 4123 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4124 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4125 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4126 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4127 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4128 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4129 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4130 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4131 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4132 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4133 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4134 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4135 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4136 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4137 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4138 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | public void noteNetworkStatsEnabledLocked() { |
| 4143 | // During device boot, qtaguid isn't enabled until after the inital |
| 4144 | // loading of battery stats. Now that they're enabled, take our initial |
| 4145 | // snapshot for future delta calculation. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4146 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 4147 | updateMobileRadioStateLocked(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4148 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4151 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4152 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4154 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4155 | @Override public int getScreenOnCount(int which) { |
| 4156 | return mScreenOnTimer.getCountLocked(which); |
| 4157 | } |
| 4158 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4159 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4160 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4161 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4162 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4163 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4164 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4165 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4166 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4167 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4168 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4169 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4170 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4173 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4174 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4175 | } |
| 4176 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 4177 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 4178 | int which) { |
| 4179 | switch (mode) { |
| 4180 | case DEVICE_IDLE_MODE_LIGHT: |
| 4181 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4182 | case DEVICE_IDLE_MODE_FULL: |
| 4183 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4184 | } |
| 4185 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 4188 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 4189 | switch (mode) { |
| 4190 | case DEVICE_IDLE_MODE_LIGHT: |
| 4191 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
| 4192 | case DEVICE_IDLE_MODE_FULL: |
| 4193 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 4194 | } |
| 4195 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 4198 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 4199 | switch (mode) { |
| 4200 | case DEVICE_IDLE_MODE_LIGHT: |
| 4201 | return mLongestLightIdleTime; |
| 4202 | case DEVICE_IDLE_MODE_FULL: |
| 4203 | return mLongestFullIdleTime; |
| 4204 | } |
| 4205 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 4208 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 4209 | switch (mode) { |
| 4210 | case DEVICE_IDLE_MODE_LIGHT: |
| 4211 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4212 | case DEVICE_IDLE_MODE_FULL: |
| 4213 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4214 | } |
| 4215 | return 0; |
| 4216 | } |
| 4217 | |
| 4218 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 4219 | switch (mode) { |
| 4220 | case DEVICE_IDLE_MODE_LIGHT: |
| 4221 | return mDeviceLightIdlingTimer.getCountLocked(which); |
| 4222 | case DEVICE_IDLE_MODE_FULL: |
| 4223 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4224 | } |
| 4225 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4226 | } |
| 4227 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4228 | @Override public int getNumConnectivityChange(int which) { |
| 4229 | int val = mNumConnectivityChange; |
| 4230 | if (which == STATS_CURRENT) { |
| 4231 | val -= mLoadedNumConnectivityChange; |
| 4232 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4233 | val -= mUnpluggedNumConnectivityChange; |
| 4234 | } |
| 4235 | return val; |
| 4236 | } |
| 4237 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4238 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4239 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4241 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4242 | @Override public int getPhoneOnCount(int which) { |
| 4243 | return mPhoneOnTimer.getCountLocked(which); |
| 4244 | } |
| 4245 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4246 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4247 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4248 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4249 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4250 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4251 | |
| 4252 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4253 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4254 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4255 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4258 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4259 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4260 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4261 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4262 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4263 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4264 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4265 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4266 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4267 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4268 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4269 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4270 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4271 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4272 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4273 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4274 | } |
| 4275 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4276 | @Override public int getMobileRadioActiveCount(int which) { |
| 4277 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4278 | } |
| 4279 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4280 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4281 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4282 | } |
| 4283 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4284 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4285 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4286 | } |
| 4287 | |
| 4288 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4289 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4290 | } |
| 4291 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4292 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4293 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4294 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4295 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4296 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4297 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4298 | } |
| 4299 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4300 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4301 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4302 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4303 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4307 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4308 | } |
| 4309 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4310 | @Override public long getWifiSupplStateTime(int state, |
| 4311 | long elapsedRealtimeUs, int which) { |
| 4312 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4313 | elapsedRealtimeUs, which); |
| 4314 | } |
| 4315 | |
| 4316 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4317 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4318 | } |
| 4319 | |
| 4320 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4321 | long elapsedRealtimeUs, int which) { |
| 4322 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4323 | elapsedRealtimeUs, which); |
| 4324 | } |
| 4325 | |
| 4326 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4327 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4328 | } |
| 4329 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4330 | @Override public boolean hasBluetoothActivityReporting() { |
| 4331 | return mHasBluetoothEnergyReporting; |
| 4332 | } |
| 4333 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4334 | @Override public long getBluetoothControllerActivity(int type, int which) { |
| 4335 | if (type >= 0 && type < mBluetoothActivityCounters.length) { |
| 4336 | return mBluetoothActivityCounters[type].getCountLocked(which); |
| 4337 | } |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4341 | @Override public boolean hasWifiActivityReporting() { |
| 4342 | return mHasWifiEnergyReporting; |
| 4343 | } |
| 4344 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4345 | @Override public long getWifiControllerActivity(int type, int which) { |
| 4346 | if (type >= 0 && type < mWifiActivityCounters.length) { |
| 4347 | return mWifiActivityCounters[type].getCountLocked(which); |
| 4348 | } |
| 4349 | return 0; |
| 4350 | } |
| 4351 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4352 | @Override |
| 4353 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4354 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4355 | } |
| 4356 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4357 | @Override |
| 4358 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4359 | return mFlashlightOnTimer.getCountLocked(which); |
| 4360 | } |
| 4361 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4362 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4363 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4364 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4365 | } |
| 4366 | |
| 4367 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4368 | public long getNetworkActivityBytes(int type, int which) { |
| 4369 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4370 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4371 | } else { |
| 4372 | return 0; |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | @Override |
| 4377 | public long getNetworkActivityPackets(int type, int which) { |
| 4378 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4379 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4380 | } else { |
| 4381 | return 0; |
| 4382 | } |
| 4383 | } |
| 4384 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4385 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4386 | final long currentTime = System.currentTimeMillis(); |
| 4387 | if (ensureStartClockTime(currentTime)) { |
| 4388 | recordCurrentTimeChangeLocked(currentTime, SystemClock.elapsedRealtime(), |
| 4389 | SystemClock.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4390 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4391 | return mStartClockTime; |
| 4392 | } |
| 4393 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4394 | @Override public String getStartPlatformVersion() { |
| 4395 | return mStartPlatformVersion; |
| 4396 | } |
| 4397 | |
| 4398 | @Override public String getEndPlatformVersion() { |
| 4399 | return mEndPlatformVersion; |
| 4400 | } |
| 4401 | |
| 4402 | @Override public int getParcelVersion() { |
| 4403 | return VERSION; |
| 4404 | } |
| 4405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | @Override public boolean getIsOnBattery() { |
| 4407 | return mOnBattery; |
| 4408 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4411 | return mUidStats; |
| 4412 | } |
| 4413 | |
| 4414 | /** |
| 4415 | * The statistics associated with a particular uid. |
| 4416 | */ |
| 4417 | public final class Uid extends BatteryStats.Uid { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4420 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4421 | boolean mWifiRunning; |
| 4422 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4423 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4424 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4425 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4426 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4427 | boolean mWifiScanStarted; |
| 4428 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4429 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4430 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4431 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4432 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4433 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4434 | boolean mWifiMulticastEnabled; |
| 4435 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4436 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4437 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4438 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4439 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 4440 | StopwatchTimer mCameraTurnedOnTimer; |
| 4441 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4442 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4443 | StopwatchTimer mForegroundActivityTimer; |
| 4444 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4445 | static final int PROCESS_STATE_NONE = NUM_PROCESS_STATE; |
| 4446 | int mProcessState = PROCESS_STATE_NONE; |
| 4447 | StopwatchTimer[] mProcessStateTimer; |
| 4448 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4449 | BatchTimer mVibratorOnTimer; |
| 4450 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4451 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4452 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4453 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4454 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4455 | LongSamplingCounter mMobileRadioActiveTime; |
| 4456 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4459 | * The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode. |
| 4460 | */ |
| 4461 | LongSamplingCounter[] mWifiControllerTime = |
| 4462 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4463 | |
| 4464 | /** |
| 4465 | * The amount of time this uid has kept the Bluetooth controller in idle, tx, and rx mode. |
| 4466 | */ |
| 4467 | LongSamplingCounter[] mBluetoothControllerTime = |
| 4468 | new LongSamplingCounter[NUM_CONTROLLER_ACTIVITY_TYPES]; |
| 4469 | |
| 4470 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4471 | * The CPU times we had at the last history details update. |
| 4472 | */ |
| 4473 | long mLastStepUserTime; |
| 4474 | long mLastStepSystemTime; |
| 4475 | long mCurStepUserTime; |
| 4476 | long mCurStepSystemTime; |
| 4477 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4478 | LongSamplingCounter mUserCpuTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4479 | LongSamplingCounter mSystemCpuTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4480 | LongSamplingCounter mCpuPower = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 4481 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4482 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4483 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | * The statistics we have collected for this uid's wake locks. |
| 4485 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4486 | final OverflowArrayMap<Wakelock> mWakelockStats = new OverflowArrayMap<Wakelock>() { |
| 4487 | @Override public Wakelock instantiateObject() { return new Wakelock(); } |
| 4488 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | |
| 4490 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4491 | * The statistics we have collected for this uid's syncs. |
| 4492 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4493 | final OverflowArrayMap<StopwatchTimer> mSyncStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4494 | @Override public StopwatchTimer instantiateObject() { |
| 4495 | return new StopwatchTimer(Uid.this, SYNC, null, mOnBatteryTimeBase); |
| 4496 | } |
| 4497 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4498 | |
| 4499 | /** |
| 4500 | * The statistics we have collected for this uid's jobs. |
| 4501 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4502 | final OverflowArrayMap<StopwatchTimer> mJobStats = new OverflowArrayMap<StopwatchTimer>() { |
| 4503 | @Override public StopwatchTimer instantiateObject() { |
| 4504 | return new StopwatchTimer(Uid.this, JOB, null, mOnBatteryTimeBase); |
| 4505 | } |
| 4506 | }; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4507 | |
| 4508 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | * The statistics we have collected for this uid's sensor activations. |
| 4510 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4511 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | |
| 4513 | /** |
| 4514 | * The statistics we have collected for this uid's processes. |
| 4515 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4516 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | |
| 4518 | /** |
| 4519 | * The statistics we have collected for this uid's processes. |
| 4520 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4521 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4522 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4523 | /** |
| 4524 | * The transient wake stats we have collected for this uid's pids. |
| 4525 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4526 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4528 | public Uid(int uid) { |
| 4529 | mUid = uid; |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4530 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4531 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4532 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4533 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4534 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4535 | mWifiScanTimers, mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4536 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4537 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4538 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4539 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4543 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4544 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4548 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4549 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4553 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4554 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4558 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4559 | return mSensorStats; |
| 4560 | } |
| 4561 | |
| 4562 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4563 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | return mProcessStats; |
| 4565 | } |
| 4566 | |
| 4567 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4568 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4569 | return mPackageStats; |
| 4570 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4571 | |
| 4572 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4573 | public int getUid() { |
| 4574 | return mUid; |
| 4575 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4576 | |
| 4577 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4578 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4579 | if (!mWifiRunning) { |
| 4580 | mWifiRunning = true; |
| 4581 | if (mWifiRunningTimer == null) { |
| 4582 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4583 | mWifiRunningTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4584 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4585 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4586 | } |
| 4587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4588 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4589 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4590 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4591 | if (mWifiRunning) { |
| 4592 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4593 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4594 | } |
| 4595 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4596 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4597 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4598 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4599 | if (!mFullWifiLockOut) { |
| 4600 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4601 | if (mFullWifiLockTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4602 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4603 | mFullWifiLockTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4604 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4605 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4606 | } |
| 4607 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4608 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4609 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4610 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4611 | if (mFullWifiLockOut) { |
| 4612 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4613 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4614 | } |
| 4615 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4616 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4617 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4618 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4619 | if (!mWifiScanStarted) { |
| 4620 | mWifiScanStarted = true; |
| 4621 | if (mWifiScanTimer == null) { |
| 4622 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4623 | mWifiScanTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4624 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4625 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4626 | } |
| 4627 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4628 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4629 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4630 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4631 | if (mWifiScanStarted) { |
| 4632 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4633 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4634 | } |
| 4635 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4636 | |
| 4637 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4638 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4639 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 4640 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4641 | csph = csph >> 3; |
| 4642 | bin++; |
| 4643 | } |
| 4644 | |
| 4645 | if (mWifiBatchedScanBinStarted == bin) return; |
| 4646 | |
| 4647 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4648 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4649 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4650 | } |
| 4651 | mWifiBatchedScanBinStarted = bin; |
| 4652 | if (mWifiBatchedScanTimer[bin] == null) { |
| 4653 | makeWifiBatchedScanBin(bin, null); |
| 4654 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4655 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4659 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4660 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4661 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4662 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4663 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4668 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4669 | if (!mWifiMulticastEnabled) { |
| 4670 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4671 | if (mWifiMulticastTimer == null) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4672 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4673 | mWifiMulticastTimers, mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4674 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4675 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4676 | } |
| 4677 | } |
| 4678 | |
| 4679 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4680 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4681 | if (mWifiMulticastEnabled) { |
| 4682 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4683 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4687 | public void noteWifiControllerActivityLocked(int type, long timeMs) { |
| 4688 | if (mWifiControllerTime[type] == null) { |
| 4689 | mWifiControllerTime[type] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 4690 | } |
| 4691 | mWifiControllerTime[type].addCountLocked(timeMs); |
| 4692 | } |
| 4693 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4694 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 4695 | if (mAudioTurnedOnTimer == null) { |
| 4696 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4697 | mAudioTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4698 | } |
| 4699 | return mAudioTurnedOnTimer; |
| 4700 | } |
| 4701 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4702 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4703 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4704 | } |
| 4705 | |
| 4706 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 4707 | if (mAudioTurnedOnTimer != null) { |
| 4708 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4709 | } |
| 4710 | } |
| 4711 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4712 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 4713 | if (mAudioTurnedOnTimer != null) { |
| 4714 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4718 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 4719 | if (mVideoTurnedOnTimer == null) { |
| 4720 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4721 | mVideoTurnedOnTimers, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4722 | } |
| 4723 | return mVideoTurnedOnTimer; |
| 4724 | } |
| 4725 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4726 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4727 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4728 | } |
| 4729 | |
| 4730 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 4731 | if (mVideoTurnedOnTimer != null) { |
| 4732 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4736 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 4737 | if (mVideoTurnedOnTimer != null) { |
| 4738 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4739 | } |
| 4740 | } |
| 4741 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4742 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 4743 | if (mFlashlightTurnedOnTimer == null) { |
| 4744 | mFlashlightTurnedOnTimer = new StopwatchTimer(Uid.this, FLASHLIGHT_TURNED_ON, |
| 4745 | mFlashlightTurnedOnTimers, mOnBatteryTimeBase); |
| 4746 | } |
| 4747 | return mFlashlightTurnedOnTimer; |
| 4748 | } |
| 4749 | |
| 4750 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 4751 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4752 | } |
| 4753 | |
| 4754 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 4755 | if (mFlashlightTurnedOnTimer != null) { |
| 4756 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 4761 | if (mFlashlightTurnedOnTimer != null) { |
| 4762 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 4767 | if (mCameraTurnedOnTimer == null) { |
| 4768 | mCameraTurnedOnTimer = new StopwatchTimer(Uid.this, CAMERA_TURNED_ON, |
| 4769 | mCameraTurnedOnTimers, mOnBatteryTimeBase); |
| 4770 | } |
| 4771 | return mCameraTurnedOnTimer; |
| 4772 | } |
| 4773 | |
| 4774 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 4775 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 4776 | } |
| 4777 | |
| 4778 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 4779 | if (mCameraTurnedOnTimer != null) { |
| 4780 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 4785 | if (mCameraTurnedOnTimer != null) { |
| 4786 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 4787 | } |
| 4788 | } |
| 4789 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4790 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 4791 | if (mForegroundActivityTimer == null) { |
| 4792 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4793 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4794 | } |
| 4795 | return mForegroundActivityTimer; |
| 4796 | } |
| 4797 | |
| 4798 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4799 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4800 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4801 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4805 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4806 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4807 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4808 | } |
| 4809 | } |
| 4810 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4811 | void updateUidProcessStateLocked(int state, long elapsedRealtimeMs) { |
| 4812 | if (mProcessState == state) return; |
| 4813 | |
| 4814 | if (mProcessState != PROCESS_STATE_NONE) { |
| 4815 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
| 4816 | } |
| 4817 | mProcessState = state; |
| 4818 | if (state != PROCESS_STATE_NONE) { |
| 4819 | if (mProcessStateTimer[state] == null) { |
| 4820 | makeProcessState(state, null); |
| 4821 | } |
| 4822 | mProcessStateTimer[state].startRunningLocked(elapsedRealtimeMs); |
| 4823 | } |
| 4824 | } |
| 4825 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4826 | public BatchTimer createVibratorOnTimerLocked() { |
| 4827 | if (mVibratorOnTimer == null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4828 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4829 | } |
| 4830 | return mVibratorOnTimer; |
| 4831 | } |
| 4832 | |
| 4833 | public void noteVibratorOnLocked(long durationMillis) { |
| 4834 | createVibratorOnTimerLocked().addDuration(BatteryStatsImpl.this, durationMillis); |
| 4835 | } |
| 4836 | |
| 4837 | public void noteVibratorOffLocked() { |
| 4838 | if (mVibratorOnTimer != null) { |
| 4839 | mVibratorOnTimer.abortLastDuration(BatteryStatsImpl.this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4840 | } |
| 4841 | } |
| 4842 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4843 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4844 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4845 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4846 | return 0; |
| 4847 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4848 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4849 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4850 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4851 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4852 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4853 | if (mFullWifiLockTimer == null) { |
| 4854 | return 0; |
| 4855 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4856 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4857 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4858 | |
| 4859 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4860 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4861 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4862 | return 0; |
| 4863 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4864 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4865 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4866 | |
| 4867 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4868 | public int getWifiScanCount(int which) { |
| 4869 | if (mWifiScanTimer == null) { |
| 4870 | return 0; |
| 4871 | } |
| 4872 | return mWifiScanTimer.getCountLocked(which); |
| 4873 | } |
| 4874 | |
| 4875 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4876 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4877 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4878 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4879 | return 0; |
| 4880 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4881 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4885 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 4886 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 4887 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 4888 | return 0; |
| 4889 | } |
| 4890 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 4891 | } |
| 4892 | |
| 4893 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4894 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4895 | if (mWifiMulticastTimer == null) { |
| 4896 | return 0; |
| 4897 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4898 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4901 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4902 | public Timer getAudioTurnedOnTimer() { |
| 4903 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4904 | } |
| 4905 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4906 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4907 | public Timer getVideoTurnedOnTimer() { |
| 4908 | return mVideoTurnedOnTimer; |
| 4909 | } |
| 4910 | |
| 4911 | @Override |
| 4912 | public Timer getFlashlightTurnedOnTimer() { |
| 4913 | return mFlashlightTurnedOnTimer; |
| 4914 | } |
| 4915 | |
| 4916 | @Override |
| 4917 | public Timer getCameraTurnedOnTimer() { |
| 4918 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4919 | } |
| 4920 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4921 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4922 | public Timer getForegroundActivityTimer() { |
| 4923 | return mForegroundActivityTimer; |
| 4924 | } |
| 4925 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4926 | void makeProcessState(int i, Parcel in) { |
| 4927 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 4928 | |
| 4929 | if (in == null) { |
| 4930 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4931 | mOnBatteryTimeBase); |
| 4932 | } else { |
| 4933 | mProcessStateTimer[i] = new StopwatchTimer(this, PROCESS_STATE, null, |
| 4934 | mOnBatteryTimeBase, in); |
| 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | @Override |
| 4939 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 4940 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 4941 | if (mProcessStateTimer[state] == null) { |
| 4942 | return 0; |
| 4943 | } |
| 4944 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4945 | } |
| 4946 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4947 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4948 | public Timer getVibratorOnTimer() { |
| 4949 | return mVibratorOnTimer; |
| 4950 | } |
| 4951 | |
| 4952 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4953 | public void noteUserActivityLocked(int type) { |
| 4954 | if (mUserActivityCounters == null) { |
| 4955 | initUserActivityLocked(); |
| 4956 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 4957 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 4958 | mUserActivityCounters[type].stepAtomic(); |
| 4959 | } else { |
| 4960 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 4961 | new Throwable()); |
| 4962 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4963 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4964 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4965 | @Override |
| 4966 | public boolean hasUserActivity() { |
| 4967 | return mUserActivityCounters != null; |
| 4968 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4969 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4970 | @Override |
| 4971 | public int getUserActivityCount(int type, int which) { |
| 4972 | if (mUserActivityCounters == null) { |
| 4973 | return 0; |
| 4974 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4975 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4976 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4977 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4978 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 4979 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 4980 | |
| 4981 | ArrayList<StopwatchTimer> collected = mWifiBatchedScanTimers.get(i); |
| 4982 | if (collected == null) { |
| 4983 | collected = new ArrayList<StopwatchTimer>(); |
| 4984 | mWifiBatchedScanTimers.put(i, collected); |
| 4985 | } |
| 4986 | if (in == null) { |
| 4987 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4988 | mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4989 | } else { |
| 4990 | mWifiBatchedScanTimer[i] = new StopwatchTimer(this, WIFI_BATCHED_SCAN, collected, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4991 | mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4992 | } |
| 4993 | } |
| 4994 | |
| 4995 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4996 | void initUserActivityLocked() { |
| 4997 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 4998 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4999 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5000 | } |
| 5001 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5002 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5003 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5004 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5005 | initNetworkActivityLocked(); |
| 5006 | } |
| 5007 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5008 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5009 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5010 | } else { |
| 5011 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5012 | new Throwable()); |
| 5013 | } |
| 5014 | } |
| 5015 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5016 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5017 | if (mNetworkByteActivityCounters == null) { |
| 5018 | initNetworkActivityLocked(); |
| 5019 | } |
| 5020 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5021 | mMobileRadioActiveCount.addCountLocked(1); |
| 5022 | } |
| 5023 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5024 | @Override |
| 5025 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5026 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5030 | public long getNetworkActivityBytes(int type, int which) { |
| 5031 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5032 | && type < mNetworkByteActivityCounters.length) { |
| 5033 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5034 | } else { |
| 5035 | return 0; |
| 5036 | } |
| 5037 | } |
| 5038 | |
| 5039 | @Override |
| 5040 | public long getNetworkActivityPackets(int type, int which) { |
| 5041 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5042 | && type < mNetworkPacketActivityCounters.length) { |
| 5043 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5044 | } else { |
| 5045 | return 0; |
| 5046 | } |
| 5047 | } |
| 5048 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5049 | @Override |
| 5050 | public long getMobileRadioActiveTime(int which) { |
| 5051 | return mMobileRadioActiveTime != null |
| 5052 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5053 | } |
| 5054 | |
| 5055 | @Override |
| 5056 | public int getMobileRadioActiveCount(int which) { |
| 5057 | return mMobileRadioActiveCount != null |
| 5058 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5059 | } |
| 5060 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5061 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5062 | public long getUserCpuTimeUs(int which) { |
| 5063 | return mUserCpuTime.getCountLocked(which); |
| 5064 | } |
| 5065 | |
| 5066 | @Override |
| 5067 | public long getSystemCpuTimeUs(int which) { |
| 5068 | return mSystemCpuTime.getCountLocked(which); |
| 5069 | } |
| 5070 | |
| 5071 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5072 | public long getCpuPowerMaUs(int which) { |
| 5073 | return mCpuPower.getCountLocked(which); |
| 5074 | } |
| 5075 | |
| 5076 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5077 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 5078 | if (mCpuClusterSpeed != null) { |
| 5079 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 5080 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 5081 | if (cpuSpeeds != null) { |
| 5082 | if (step >= 0 && step < cpuSpeeds.length) { |
| 5083 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 5084 | if (c != null) { |
| 5085 | return c.getCountLocked(which); |
| 5086 | } |
| 5087 | } |
| 5088 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5089 | } |
| 5090 | } |
| 5091 | return 0; |
| 5092 | } |
| 5093 | |
| 5094 | @Override |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5095 | public long getWifiControllerActivity(int type, int which) { |
| 5096 | if (type >= 0 && type < NUM_CONTROLLER_ACTIVITY_TYPES && |
| 5097 | mWifiControllerTime[type] != null) { |
| 5098 | return mWifiControllerTime[type].getCountLocked(which); |
| 5099 | } |
| 5100 | return 0; |
| 5101 | } |
| 5102 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5103 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5104 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5105 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5106 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5107 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5108 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5109 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5110 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 5111 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5113 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5114 | /** |
| 5115 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5116 | * inactive so can be dropped. |
| 5117 | */ |
| 5118 | boolean reset() { |
| 5119 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5120 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5121 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5122 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5123 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5124 | } |
| 5125 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5126 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5127 | active |= mFullWifiLockOut; |
| 5128 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5129 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5130 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5131 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5132 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5133 | if (mWifiBatchedScanTimer != null) { |
| 5134 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5135 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5136 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5137 | } |
| 5138 | } |
| 5139 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5140 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5141 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5142 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5143 | active |= mWifiMulticastEnabled; |
| 5144 | } |
| 5145 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5146 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5147 | } |
| 5148 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5149 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5150 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5151 | if (mFlashlightTurnedOnTimer != null) { |
| 5152 | active |= !mFlashlightTurnedOnTimer.reset(false); |
| 5153 | } |
| 5154 | if (mCameraTurnedOnTimer != null) { |
| 5155 | active |= !mCameraTurnedOnTimer.reset(false); |
| 5156 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5157 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5158 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5159 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5160 | if (mProcessStateTimer != null) { |
| 5161 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5162 | if (mProcessStateTimer[i] != null) { |
| 5163 | active |= !mProcessStateTimer[i].reset(false); |
| 5164 | } |
| 5165 | } |
| 5166 | active |= (mProcessState != PROCESS_STATE_NONE); |
| 5167 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5168 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5169 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5170 | mVibratorOnTimer.detach(); |
| 5171 | mVibratorOnTimer = null; |
| 5172 | } else { |
| 5173 | active = true; |
| 5174 | } |
| 5175 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5176 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5177 | if (mUserActivityCounters != null) { |
| 5178 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5179 | mUserActivityCounters[i].reset(false); |
| 5180 | } |
| 5181 | } |
| 5182 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5183 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5184 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5185 | mNetworkByteActivityCounters[i].reset(false); |
| 5186 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5187 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5188 | mMobileRadioActiveTime.reset(false); |
| 5189 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5192 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5193 | if (mWifiControllerTime[i] != null) { |
| 5194 | mWifiControllerTime[i].reset(false); |
| 5195 | } |
| 5196 | |
| 5197 | if (mBluetoothControllerTime[i] != null) { |
| 5198 | mBluetoothControllerTime[i].reset(false); |
| 5199 | } |
| 5200 | } |
| 5201 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5202 | mUserCpuTime.reset(false); |
| 5203 | mSystemCpuTime.reset(false); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5204 | mCpuPower.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5205 | |
| 5206 | if (mCpuClusterSpeed != null) { |
| 5207 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 5208 | if (speeds != null) { |
| 5209 | for (LongSamplingCounter speed : speeds) { |
| 5210 | if (speed != null) { |
| 5211 | speed.reset(false); |
| 5212 | } |
| 5213 | } |
| 5214 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5215 | } |
| 5216 | } |
| 5217 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5218 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5219 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5220 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5221 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5222 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5223 | } else { |
| 5224 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5225 | } |
| 5226 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5227 | mWakelockStats.cleanup(); |
| 5228 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5229 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5230 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5231 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5232 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5233 | timer.detach(); |
| 5234 | } else { |
| 5235 | active = true; |
| 5236 | } |
| 5237 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5238 | mSyncStats.cleanup(); |
| 5239 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5240 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5241 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5242 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5243 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5244 | timer.detach(); |
| 5245 | } else { |
| 5246 | active = true; |
| 5247 | } |
| 5248 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5249 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5250 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5251 | Sensor s = mSensorStats.valueAt(ise); |
| 5252 | if (s.reset()) { |
| 5253 | mSensorStats.removeAt(ise); |
| 5254 | } else { |
| 5255 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5256 | } |
| 5257 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5258 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5259 | Proc proc = mProcessStats.valueAt(ip); |
| 5260 | if (proc.mProcessState == PROCESS_STATE_NONE) { |
| 5261 | proc.detach(); |
| 5262 | mProcessStats.removeAt(ip); |
| 5263 | } else { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5264 | proc.reset(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5265 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5266 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5267 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5268 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5269 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5270 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5271 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5272 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5273 | } else { |
| 5274 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5275 | } |
| 5276 | } |
| 5277 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5278 | if (mPackageStats.size() > 0) { |
| 5279 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5280 | while (it.hasNext()) { |
| 5281 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5282 | Pkg p = pkgEntry.getValue(); |
| 5283 | p.detach(); |
| 5284 | if (p.mServiceStats.size() > 0) { |
| 5285 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5286 | = p.mServiceStats.entrySet().iterator(); |
| 5287 | while (it2.hasNext()) { |
| 5288 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5289 | servEntry.getValue().detach(); |
| 5290 | } |
| 5291 | } |
| 5292 | } |
| 5293 | mPackageStats.clear(); |
| 5294 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5295 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5296 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5297 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5298 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5299 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5300 | if (mWifiRunningTimer != null) { |
| 5301 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5302 | } |
| 5303 | if (mFullWifiLockTimer != null) { |
| 5304 | mFullWifiLockTimer.detach(); |
| 5305 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5306 | if (mWifiScanTimer != null) { |
| 5307 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5308 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5309 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5310 | if (mWifiBatchedScanTimer[i] != null) { |
| 5311 | mWifiBatchedScanTimer[i].detach(); |
| 5312 | } |
| 5313 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5314 | if (mWifiMulticastTimer != null) { |
| 5315 | mWifiMulticastTimer.detach(); |
| 5316 | } |
| 5317 | if (mAudioTurnedOnTimer != null) { |
| 5318 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5319 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5320 | } |
| 5321 | if (mVideoTurnedOnTimer != null) { |
| 5322 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5323 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5324 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5325 | if (mFlashlightTurnedOnTimer != null) { |
| 5326 | mFlashlightTurnedOnTimer.detach(); |
| 5327 | mFlashlightTurnedOnTimer = null; |
| 5328 | } |
| 5329 | if (mCameraTurnedOnTimer != null) { |
| 5330 | mCameraTurnedOnTimer.detach(); |
| 5331 | mCameraTurnedOnTimer = null; |
| 5332 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5333 | if (mForegroundActivityTimer != null) { |
| 5334 | mForegroundActivityTimer.detach(); |
| 5335 | mForegroundActivityTimer = null; |
| 5336 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5337 | if (mUserActivityCounters != null) { |
| 5338 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5339 | mUserActivityCounters[i].detach(); |
| 5340 | } |
| 5341 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5342 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5343 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5344 | mNetworkByteActivityCounters[i].detach(); |
| 5345 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5346 | } |
| 5347 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5348 | |
| 5349 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5350 | if (mWifiControllerTime[i] != null) { |
| 5351 | mWifiControllerTime[i].detach(); |
| 5352 | } |
| 5353 | |
| 5354 | if (mBluetoothControllerTime[i] != null) { |
| 5355 | mBluetoothControllerTime[i].detach(); |
| 5356 | } |
| 5357 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5358 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5359 | |
| 5360 | mUserCpuTime.detach(); |
| 5361 | mSystemCpuTime.detach(); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5362 | mCpuPower.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5363 | |
| 5364 | if (mCpuClusterSpeed != null) { |
| 5365 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5366 | if (cpuSpeeds != null) { |
| 5367 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5368 | if (c != null) { |
| 5369 | c.detach(); |
| 5370 | } |
| 5371 | } |
| 5372 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5373 | } |
| 5374 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5375 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5376 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5377 | return !active; |
| 5378 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5379 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5380 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5381 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5382 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5383 | out.writeInt(NW); |
| 5384 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5385 | out.writeString(wakeStats.keyAt(iw)); |
| 5386 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5387 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | } |
| 5389 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5390 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5391 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5392 | out.writeInt(NS); |
| 5393 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5394 | out.writeString(syncStats.keyAt(is)); |
| 5395 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5396 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5397 | } |
| 5398 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5399 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5400 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5401 | out.writeInt(NJ); |
| 5402 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5403 | out.writeString(jobStats.keyAt(ij)); |
| 5404 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5405 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5406 | } |
| 5407 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5408 | int NSE = mSensorStats.size(); |
| 5409 | out.writeInt(NSE); |
| 5410 | for (int ise=0; ise<NSE; ise++) { |
| 5411 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5412 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5413 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | } |
| 5415 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5416 | int NP = mProcessStats.size(); |
| 5417 | out.writeInt(NP); |
| 5418 | for (int ip=0; ip<NP; ip++) { |
| 5419 | out.writeString(mProcessStats.keyAt(ip)); |
| 5420 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5421 | proc.writeToParcelLocked(out); |
| 5422 | } |
| 5423 | |
| 5424 | out.writeInt(mPackageStats.size()); |
| 5425 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5426 | out.writeString(pkgEntry.getKey()); |
| 5427 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5428 | pkg.writeToParcelLocked(out); |
| 5429 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5430 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5431 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5432 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5433 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5434 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5435 | out.writeInt(0); |
| 5436 | } |
| 5437 | if (mFullWifiLockTimer != null) { |
| 5438 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5439 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5440 | } else { |
| 5441 | out.writeInt(0); |
| 5442 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5443 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5444 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5445 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5446 | } else { |
| 5447 | out.writeInt(0); |
| 5448 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5449 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5450 | if (mWifiBatchedScanTimer[i] != null) { |
| 5451 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5452 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5453 | } else { |
| 5454 | out.writeInt(0); |
| 5455 | } |
| 5456 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5457 | if (mWifiMulticastTimer != null) { |
| 5458 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5459 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5460 | } else { |
| 5461 | out.writeInt(0); |
| 5462 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5463 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5464 | if (mAudioTurnedOnTimer != null) { |
| 5465 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5466 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5467 | } else { |
| 5468 | out.writeInt(0); |
| 5469 | } |
| 5470 | if (mVideoTurnedOnTimer != null) { |
| 5471 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5472 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5473 | } else { |
| 5474 | out.writeInt(0); |
| 5475 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5476 | if (mFlashlightTurnedOnTimer != null) { |
| 5477 | out.writeInt(1); |
| 5478 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5479 | } else { |
| 5480 | out.writeInt(0); |
| 5481 | } |
| 5482 | if (mCameraTurnedOnTimer != null) { |
| 5483 | out.writeInt(1); |
| 5484 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5485 | } else { |
| 5486 | out.writeInt(0); |
| 5487 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5488 | if (mForegroundActivityTimer != null) { |
| 5489 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5490 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5491 | } else { |
| 5492 | out.writeInt(0); |
| 5493 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5494 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5495 | if (mProcessStateTimer[i] != null) { |
| 5496 | out.writeInt(1); |
| 5497 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 5498 | } else { |
| 5499 | out.writeInt(0); |
| 5500 | } |
| 5501 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5502 | if (mVibratorOnTimer != null) { |
| 5503 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5504 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5505 | } else { |
| 5506 | out.writeInt(0); |
| 5507 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5508 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5509 | out.writeInt(1); |
| 5510 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5511 | mUserActivityCounters[i].writeToParcel(out); |
| 5512 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5513 | } else { |
| 5514 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5515 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5516 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5517 | out.writeInt(1); |
| 5518 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5519 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 5520 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5521 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5522 | mMobileRadioActiveTime.writeToParcel(out); |
| 5523 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5524 | } else { |
| 5525 | out.writeInt(0); |
| 5526 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5527 | |
| 5528 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5529 | if (mWifiControllerTime[i] != null) { |
| 5530 | out.writeInt(1); |
| 5531 | mWifiControllerTime[i].writeToParcel(out); |
| 5532 | } else { |
| 5533 | out.writeInt(0); |
| 5534 | } |
| 5535 | } |
| 5536 | |
| 5537 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5538 | if (mBluetoothControllerTime[i] != null) { |
| 5539 | out.writeInt(1); |
| 5540 | mBluetoothControllerTime[i].writeToParcel(out); |
| 5541 | } else { |
| 5542 | out.writeInt(0); |
| 5543 | } |
| 5544 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5545 | |
| 5546 | mUserCpuTime.writeToParcel(out); |
| 5547 | mSystemCpuTime.writeToParcel(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5548 | mCpuPower.writeToParcel(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5549 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5550 | if (mCpuClusterSpeed != null) { |
| 5551 | out.writeInt(1); |
| 5552 | out.writeInt(mCpuClusterSpeed.length); |
| 5553 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5554 | if (cpuSpeeds != null) { |
| 5555 | out.writeInt(1); |
| 5556 | out.writeInt(cpuSpeeds.length); |
| 5557 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5558 | if (c != null) { |
| 5559 | out.writeInt(1); |
| 5560 | c.writeToParcel(out); |
| 5561 | } else { |
| 5562 | out.writeInt(0); |
| 5563 | } |
| 5564 | } |
| 5565 | } else { |
| 5566 | out.writeInt(0); |
| 5567 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5568 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5569 | } else { |
| 5570 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5571 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | } |
| 5573 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5574 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | int numWakelocks = in.readInt(); |
| 5576 | mWakelockStats.clear(); |
| 5577 | for (int j = 0; j < numWakelocks; j++) { |
| 5578 | String wakelockName = in.readString(); |
| 5579 | Uid.Wakelock wakelock = new Wakelock(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5580 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5581 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | } |
| 5583 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5584 | int numSyncs = in.readInt(); |
| 5585 | mSyncStats.clear(); |
| 5586 | for (int j = 0; j < numSyncs; j++) { |
| 5587 | String syncName = in.readString(); |
| 5588 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5589 | mSyncStats.add(syncName, |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5590 | new StopwatchTimer(Uid.this, SYNC, null, timeBase, in)); |
| 5591 | } |
| 5592 | } |
| 5593 | |
| 5594 | int numJobs = in.readInt(); |
| 5595 | mJobStats.clear(); |
| 5596 | for (int j = 0; j < numJobs; j++) { |
| 5597 | String jobName = in.readString(); |
| 5598 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5599 | mJobStats.add(jobName, new StopwatchTimer(Uid.this, JOB, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5600 | } |
| 5601 | } |
| 5602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | int numSensors = in.readInt(); |
| 5604 | mSensorStats.clear(); |
| 5605 | for (int k = 0; k < numSensors; k++) { |
| 5606 | int sensorNumber = in.readInt(); |
| 5607 | Uid.Sensor sensor = new Sensor(sensorNumber); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5608 | sensor.readFromParcelLocked(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | mSensorStats.put(sensorNumber, sensor); |
| 5610 | } |
| 5611 | |
| 5612 | int numProcs = in.readInt(); |
| 5613 | mProcessStats.clear(); |
| 5614 | for (int k = 0; k < numProcs; k++) { |
| 5615 | String processName = in.readString(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5616 | Uid.Proc proc = new Proc(processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5617 | proc.readFromParcelLocked(in); |
| 5618 | mProcessStats.put(processName, proc); |
| 5619 | } |
| 5620 | |
| 5621 | int numPkgs = in.readInt(); |
| 5622 | mPackageStats.clear(); |
| 5623 | for (int l = 0; l < numPkgs; l++) { |
| 5624 | String packageName = in.readString(); |
| 5625 | Uid.Pkg pkg = new Pkg(); |
| 5626 | pkg.readFromParcelLocked(in); |
| 5627 | mPackageStats.put(packageName, pkg); |
| 5628 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5629 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5630 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5631 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5632 | mWifiRunningTimer = new StopwatchTimer(Uid.this, WIFI_RUNNING, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5633 | mWifiRunningTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5634 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5635 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5636 | } |
| 5637 | mFullWifiLockOut = false; |
| 5638 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5639 | mFullWifiLockTimer = new StopwatchTimer(Uid.this, FULL_WIFI_LOCK, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5640 | mFullWifiLockTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5641 | } else { |
| 5642 | mFullWifiLockTimer = null; |
| 5643 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5644 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5645 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5646 | mWifiScanTimer = new StopwatchTimer(Uid.this, WIFI_SCAN, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5647 | mWifiScanTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5648 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5649 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5650 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5651 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5652 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5653 | if (in.readInt() != 0) { |
| 5654 | makeWifiBatchedScanBin(i, in); |
| 5655 | } else { |
| 5656 | mWifiBatchedScanTimer[i] = null; |
| 5657 | } |
| 5658 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5659 | mWifiMulticastEnabled = false; |
| 5660 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5661 | mWifiMulticastTimer = new StopwatchTimer(Uid.this, WIFI_MULTICAST_ENABLED, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5662 | mWifiMulticastTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5663 | } else { |
| 5664 | mWifiMulticastTimer = null; |
| 5665 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5666 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5667 | mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5668 | mAudioTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5669 | } else { |
| 5670 | mAudioTurnedOnTimer = null; |
| 5671 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5672 | if (in.readInt() != 0) { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5673 | mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5674 | mVideoTurnedOnTimers, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5675 | } else { |
| 5676 | mVideoTurnedOnTimer = null; |
| 5677 | } |
| 5678 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5679 | mFlashlightTurnedOnTimer = new StopwatchTimer(Uid.this, FLASHLIGHT_TURNED_ON, |
| 5680 | mFlashlightTurnedOnTimers, mOnBatteryTimeBase, in); |
| 5681 | } else { |
| 5682 | mFlashlightTurnedOnTimer = null; |
| 5683 | } |
| 5684 | if (in.readInt() != 0) { |
| 5685 | mCameraTurnedOnTimer = new StopwatchTimer(Uid.this, CAMERA_TURNED_ON, |
| 5686 | mCameraTurnedOnTimers, mOnBatteryTimeBase, in); |
| 5687 | } else { |
| 5688 | mCameraTurnedOnTimer = null; |
| 5689 | } |
| 5690 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5691 | mForegroundActivityTimer = new StopwatchTimer( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5692 | Uid.this, FOREGROUND_ACTIVITY, null, mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5693 | } else { |
| 5694 | mForegroundActivityTimer = null; |
| 5695 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5696 | mProcessState = PROCESS_STATE_NONE; |
| 5697 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5698 | if (in.readInt() != 0) { |
| 5699 | makeProcessState(i, in); |
| 5700 | } else { |
| 5701 | mProcessStateTimer[i] = null; |
| 5702 | } |
| 5703 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5704 | if (in.readInt() != 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5705 | mVibratorOnTimer = new BatchTimer(Uid.this, VIBRATOR_ON, mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5706 | } else { |
| 5707 | mVibratorOnTimer = null; |
| 5708 | } |
| 5709 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5710 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5711 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5712 | mUserActivityCounters[i] = new Counter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5713 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5714 | } else { |
| 5715 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5716 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5717 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5718 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5719 | mNetworkPacketActivityCounters |
| 5720 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5721 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5722 | mNetworkByteActivityCounters[i] |
| 5723 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5724 | mNetworkPacketActivityCounters[i] |
| 5725 | = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5726 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5727 | mMobileRadioActiveTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5728 | mMobileRadioActiveCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5729 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5730 | mNetworkByteActivityCounters = null; |
| 5731 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5732 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5733 | |
| 5734 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5735 | if (in.readInt() != 0) { |
| 5736 | mWifiControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5737 | } else { |
| 5738 | mWifiControllerTime[i] = null; |
| 5739 | } |
| 5740 | } |
| 5741 | |
| 5742 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 5743 | if (in.readInt() != 0) { |
| 5744 | mBluetoothControllerTime[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5745 | } else { |
| 5746 | mBluetoothControllerTime[i] = null; |
| 5747 | } |
| 5748 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5749 | |
| 5750 | mUserCpuTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5751 | mSystemCpuTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5752 | mCpuPower = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5753 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5754 | if (in.readInt() != 0) { |
| 5755 | int numCpuClusters = in.readInt(); |
| 5756 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
| 5757 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5758 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5759 | |
| 5760 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 5761 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 5762 | if (in.readInt() != 0) { |
| 5763 | int numSpeeds = in.readInt(); |
| 5764 | if (mPowerProfile != null && |
| 5765 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
| 5766 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 5767 | } |
| 5768 | |
| 5769 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 5770 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 5771 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 5772 | if (in.readInt() != 0) { |
| 5773 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 5774 | } |
| 5775 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 5776 | } else { |
| 5777 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5778 | } |
| 5779 | } |
| 5780 | } else { |
| 5781 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5782 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | /** |
| 5786 | * The statistics associated with a particular wake lock. |
| 5787 | */ |
| 5788 | public final class Wakelock extends BatteryStats.Uid.Wakelock { |
| 5789 | /** |
| 5790 | * How long (in ms) this uid has been keeping the device partially awake. |
| 5791 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5792 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | |
| 5794 | /** |
| 5795 | * How long (in ms) this uid has been keeping the device fully awake. |
| 5796 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5797 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | |
| 5799 | /** |
| 5800 | * How long (in ms) this uid has had a window keeping the device awake. |
| 5801 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5802 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | |
| 5804 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5805 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5806 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5807 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5808 | |
| 5809 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 5811 | * proper timer pool from the given BatteryStatsImpl object. |
| 5812 | * |
| 5813 | * @param in the Parcel to be read from. |
| 5814 | * return a new Timer, or null. |
| 5815 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5816 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5817 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | if (in.readInt() == 0) { |
| 5819 | return null; |
| 5820 | } |
| 5821 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5822 | return new StopwatchTimer(Uid.this, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | } |
| 5824 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5825 | boolean reset() { |
| 5826 | boolean wlactive = false; |
| 5827 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5828 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5829 | } |
| 5830 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5831 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5832 | } |
| 5833 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5834 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5835 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5836 | if (mTimerDraw != null) { |
| 5837 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5838 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5839 | if (!wlactive) { |
| 5840 | if (mTimerFull != null) { |
| 5841 | mTimerFull.detach(); |
| 5842 | mTimerFull = null; |
| 5843 | } |
| 5844 | if (mTimerPartial != null) { |
| 5845 | mTimerPartial.detach(); |
| 5846 | mTimerPartial = null; |
| 5847 | } |
| 5848 | if (mTimerWindow != null) { |
| 5849 | mTimerWindow.detach(); |
| 5850 | mTimerWindow = null; |
| 5851 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5852 | if (mTimerDraw != null) { |
| 5853 | mTimerDraw.detach(); |
| 5854 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5855 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5856 | } |
| 5857 | return !wlactive; |
| 5858 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5859 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5860 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5862 | mPartialTimers, screenOffTimeBase, in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5863 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, mFullTimers, timeBase, in); |
| 5864 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, mWindowTimers, timeBase, in); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5865 | mTimerDraw = readTimerFromParcel(WAKE_TYPE_DRAW, mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5866 | } |
| 5867 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5868 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5869 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 5870 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 5871 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5872 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | @Override |
| 5876 | public Timer getWakeTime(int type) { |
| 5877 | switch (type) { |
| 5878 | case WAKE_TYPE_FULL: return mTimerFull; |
| 5879 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 5880 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5881 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | default: throw new IllegalArgumentException("type = " + type); |
| 5883 | } |
| 5884 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5885 | |
| 5886 | public StopwatchTimer getStopwatchTimer(int type) { |
| 5887 | StopwatchTimer t; |
| 5888 | switch (type) { |
| 5889 | case WAKE_TYPE_PARTIAL: |
| 5890 | t = mTimerPartial; |
| 5891 | if (t == null) { |
| 5892 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_PARTIAL, |
| 5893 | mPartialTimers, mOnBatteryScreenOffTimeBase); |
| 5894 | mTimerPartial = t; |
| 5895 | } |
| 5896 | return t; |
| 5897 | case WAKE_TYPE_FULL: |
| 5898 | t = mTimerFull; |
| 5899 | if (t == null) { |
| 5900 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_FULL, |
| 5901 | mFullTimers, mOnBatteryTimeBase); |
| 5902 | mTimerFull = t; |
| 5903 | } |
| 5904 | return t; |
| 5905 | case WAKE_TYPE_WINDOW: |
| 5906 | t = mTimerWindow; |
| 5907 | if (t == null) { |
| 5908 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_WINDOW, |
| 5909 | mWindowTimers, mOnBatteryTimeBase); |
| 5910 | mTimerWindow = t; |
| 5911 | } |
| 5912 | return t; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5913 | case WAKE_TYPE_DRAW: |
| 5914 | t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5915 | if (t == null) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5916 | t = new StopwatchTimer(Uid.this, WAKE_TYPE_DRAW, |
| 5917 | mDrawTimers, mOnBatteryTimeBase); |
| 5918 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5919 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5920 | return t; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5921 | default: |
| 5922 | throw new IllegalArgumentException("type=" + type); |
| 5923 | } |
| 5924 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | public final class Sensor extends BatteryStats.Uid.Sensor { |
| 5928 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5929 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | public Sensor(int handle) { |
| 5932 | mHandle = handle; |
| 5933 | } |
| 5934 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5935 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5936 | if (in.readInt() == 0) { |
| 5937 | return null; |
| 5938 | } |
| 5939 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5940 | ArrayList<StopwatchTimer> pool = mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5942 | pool = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5943 | mSensorTimers.put(mHandle, pool); |
| 5944 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5945 | return new StopwatchTimer(Uid.this, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5946 | } |
| 5947 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5948 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5949 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5950 | mTimer = null; |
| 5951 | return true; |
| 5952 | } |
| 5953 | return false; |
| 5954 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5955 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5956 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 5957 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5960 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 5961 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | @Override |
| 5965 | public Timer getSensorTime() { |
| 5966 | return mTimer; |
| 5967 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5968 | |
| 5969 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | public int getHandle() { |
| 5971 | return mHandle; |
| 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | /** |
| 5976 | * The statistics associated with a particular process. |
| 5977 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5978 | 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] | 5979 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5980 | * The name of this process. |
| 5981 | */ |
| 5982 | final String mName; |
| 5983 | |
| 5984 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5985 | * Remains true until removed from the stats. |
| 5986 | */ |
| 5987 | boolean mActive = true; |
| 5988 | |
| 5989 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5990 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | */ |
| 5992 | long mUserTime; |
| 5993 | |
| 5994 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5995 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5996 | */ |
| 5997 | long mSystemTime; |
| 5998 | |
| 5999 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6000 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6001 | */ |
| 6002 | long mForegroundTime; |
| 6003 | |
| 6004 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6005 | * Number of times the process has been started. |
| 6006 | */ |
| 6007 | int mStarts; |
| 6008 | |
| 6009 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6010 | * Number of times the process has crashed. |
| 6011 | */ |
| 6012 | int mNumCrashes; |
| 6013 | |
| 6014 | /** |
| 6015 | * Number of times the process has had an ANR. |
| 6016 | */ |
| 6017 | int mNumAnrs; |
| 6018 | |
| 6019 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6020 | * The amount of user time loaded from a previous save. |
| 6021 | */ |
| 6022 | long mLoadedUserTime; |
| 6023 | |
| 6024 | /** |
| 6025 | * The amount of system time loaded from a previous save. |
| 6026 | */ |
| 6027 | long mLoadedSystemTime; |
| 6028 | |
| 6029 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6030 | * The amount of foreground time loaded from a previous save. |
| 6031 | */ |
| 6032 | long mLoadedForegroundTime; |
| 6033 | |
| 6034 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6035 | * The number of times the process has started from a previous save. |
| 6036 | */ |
| 6037 | int mLoadedStarts; |
| 6038 | |
| 6039 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6040 | * 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] | 6041 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6042 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6043 | |
| 6044 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6045 | * 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] | 6046 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6047 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6048 | |
| 6049 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | * The amount of user time when last unplugged. |
| 6051 | */ |
| 6052 | long mUnpluggedUserTime; |
| 6053 | |
| 6054 | /** |
| 6055 | * The amount of system time when last unplugged. |
| 6056 | */ |
| 6057 | long mUnpluggedSystemTime; |
| 6058 | |
| 6059 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6060 | * The amount of foreground time since unplugged. |
| 6061 | */ |
| 6062 | long mUnpluggedForegroundTime; |
| 6063 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6064 | /** |
| 6065 | * The number of times the process has started before unplugged. |
| 6066 | */ |
| 6067 | int mUnpluggedStarts; |
| 6068 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6069 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6070 | * Number of times the process has crashed before unplugged. |
| 6071 | */ |
| 6072 | int mUnpluggedNumCrashes; |
| 6073 | |
| 6074 | /** |
| 6075 | * Number of times the process has had an ANR before unplugged. |
| 6076 | */ |
| 6077 | int mUnpluggedNumAnrs; |
| 6078 | |
| 6079 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6080 | * Current process state. |
| 6081 | */ |
| 6082 | int mProcessState = PROCESS_STATE_NONE; |
| 6083 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6084 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6085 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6086 | Proc(String name) { |
| 6087 | mName = name; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6088 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6090 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6091 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | mUnpluggedUserTime = mUserTime; |
| 6093 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6094 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6095 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6096 | mUnpluggedNumCrashes = mNumCrashes; |
| 6097 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | } |
| 6099 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6100 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6102 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6103 | void reset() { |
| 6104 | mUserTime = mSystemTime = mForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6105 | mStarts = mNumCrashes = mNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6106 | mLoadedUserTime = mLoadedSystemTime = mLoadedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6107 | mLoadedStarts = mLoadedNumCrashes = mLoadedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6108 | mUnpluggedUserTime = mUnpluggedSystemTime = mUnpluggedForegroundTime = 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6109 | mUnpluggedStarts = mUnpluggedNumCrashes = mUnpluggedNumAnrs = 0; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6110 | mExcessivePower = null; |
| 6111 | } |
| 6112 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6113 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6114 | mActive = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6115 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6116 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6117 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6118 | public int countExcessivePowers() { |
| 6119 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6120 | } |
| 6121 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6122 | public ExcessivePower getExcessivePower(int i) { |
| 6123 | if (mExcessivePower != null) { |
| 6124 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6125 | } |
| 6126 | return null; |
| 6127 | } |
| 6128 | |
| 6129 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6130 | if (mExcessivePower == null) { |
| 6131 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6132 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6133 | ExcessivePower ew = new ExcessivePower(); |
| 6134 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6135 | ew.overTime = overTime; |
| 6136 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6137 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6138 | } |
| 6139 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6140 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 6141 | if (mExcessivePower == null) { |
| 6142 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 6143 | } |
| 6144 | ExcessivePower ew = new ExcessivePower(); |
| 6145 | ew.type = ExcessivePower.TYPE_CPU; |
| 6146 | ew.overTime = overTime; |
| 6147 | ew.usedTime = usedTime; |
| 6148 | mExcessivePower.add(ew); |
| 6149 | } |
| 6150 | |
| 6151 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 6152 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6153 | out.writeInt(0); |
| 6154 | return; |
| 6155 | } |
| 6156 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6157 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6158 | out.writeInt(N); |
| 6159 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6160 | ExcessivePower ew = mExcessivePower.get(i); |
| 6161 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6162 | out.writeLong(ew.overTime); |
| 6163 | out.writeLong(ew.usedTime); |
| 6164 | } |
| 6165 | } |
| 6166 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6167 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6168 | final int N = in.readInt(); |
| 6169 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6170 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6171 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6172 | } |
| 6173 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6174 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6175 | throw new ParcelFormatException( |
| 6176 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6177 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6178 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6179 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6180 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6181 | ExcessivePower ew = new ExcessivePower(); |
| 6182 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6183 | ew.overTime = in.readLong(); |
| 6184 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6185 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6186 | } |
| 6187 | } |
| 6188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6189 | void writeToParcelLocked(Parcel out) { |
| 6190 | out.writeLong(mUserTime); |
| 6191 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6192 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6193 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6194 | out.writeInt(mNumCrashes); |
| 6195 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | out.writeLong(mLoadedUserTime); |
| 6197 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6198 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6200 | out.writeInt(mLoadedNumCrashes); |
| 6201 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | out.writeLong(mUnpluggedUserTime); |
| 6203 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6204 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6206 | out.writeInt(mUnpluggedNumCrashes); |
| 6207 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6208 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | void readFromParcelLocked(Parcel in) { |
| 6212 | mUserTime = in.readLong(); |
| 6213 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6214 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6216 | mNumCrashes = in.readInt(); |
| 6217 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6218 | mLoadedUserTime = in.readLong(); |
| 6219 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6220 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6221 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6222 | mLoadedNumCrashes = in.readInt(); |
| 6223 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | mUnpluggedUserTime = in.readLong(); |
| 6225 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6226 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6227 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6228 | mUnpluggedNumCrashes = in.readInt(); |
| 6229 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6230 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6231 | } |
| 6232 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6233 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6234 | mUserTime += utime; |
| 6235 | mSystemTime += stime; |
| 6236 | } |
| 6237 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6238 | public void addForegroundTimeLocked(long ttime) { |
| 6239 | mForegroundTime += ttime; |
| 6240 | } |
| 6241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | public void incStartsLocked() { |
| 6243 | mStarts++; |
| 6244 | } |
| 6245 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6246 | public void incNumCrashesLocked() { |
| 6247 | mNumCrashes++; |
| 6248 | } |
| 6249 | |
| 6250 | public void incNumAnrsLocked() { |
| 6251 | mNumAnrs++; |
| 6252 | } |
| 6253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6255 | public boolean isActive() { |
| 6256 | return mActive; |
| 6257 | } |
| 6258 | |
| 6259 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6260 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6261 | long val = mUserTime; |
| 6262 | if (which == STATS_CURRENT) { |
| 6263 | val -= mLoadedUserTime; |
| 6264 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6265 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | } |
| 6267 | return val; |
| 6268 | } |
| 6269 | |
| 6270 | @Override |
| 6271 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6272 | long val = mSystemTime; |
| 6273 | if (which == STATS_CURRENT) { |
| 6274 | val -= mLoadedSystemTime; |
| 6275 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6276 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |
| 6278 | return val; |
| 6279 | } |
| 6280 | |
| 6281 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6282 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6283 | long val = mForegroundTime; |
| 6284 | if (which == STATS_CURRENT) { |
| 6285 | val -= mLoadedForegroundTime; |
| 6286 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6287 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6288 | } |
| 6289 | return val; |
| 6290 | } |
| 6291 | |
| 6292 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6293 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6294 | int val = mStarts; |
| 6295 | if (which == STATS_CURRENT) { |
| 6296 | val -= mLoadedStarts; |
| 6297 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6298 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6299 | } |
| 6300 | return val; |
| 6301 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6302 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6303 | @Override |
| 6304 | public int getNumCrashes(int which) { |
| 6305 | int val = mNumCrashes; |
| 6306 | if (which == STATS_CURRENT) { |
| 6307 | val -= mLoadedNumCrashes; |
| 6308 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6309 | val -= mUnpluggedNumCrashes; |
| 6310 | } |
| 6311 | return val; |
| 6312 | } |
| 6313 | |
| 6314 | @Override |
| 6315 | public int getNumAnrs(int which) { |
| 6316 | int val = mNumAnrs; |
| 6317 | if (which == STATS_CURRENT) { |
| 6318 | val -= mLoadedNumAnrs; |
| 6319 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6320 | val -= mUnpluggedNumAnrs; |
| 6321 | } |
| 6322 | return val; |
| 6323 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * The statistics associated with a particular package. |
| 6328 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6329 | 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] | 6330 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6331 | * 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] | 6332 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6333 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6334 | |
| 6335 | /** |
| 6336 | * The statics we have collected for this package's services. |
| 6337 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6338 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | |
| 6340 | Pkg() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6341 | mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6342 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6343 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6344 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6345 | } |
| 6346 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6347 | public void onTimeStopped(long elapsedRealtime, long baseUptime, 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 | mOnBatteryScreenOffTimeBase.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) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6355 | int numWA = in.readInt(); |
| 6356 | mWakeupAlarms.clear(); |
| 6357 | for (int i=0; i<numWA; i++) { |
| 6358 | String tag = in.readString(); |
| 6359 | mWakeupAlarms.put(tag, new Counter(mOnBatteryTimeBase, in)); |
| 6360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | |
| 6362 | int numServs = in.readInt(); |
| 6363 | mServiceStats.clear(); |
| 6364 | for (int m = 0; m < numServs; m++) { |
| 6365 | String serviceName = in.readString(); |
| 6366 | Uid.Pkg.Serv serv = new Serv(); |
| 6367 | mServiceStats.put(serviceName, serv); |
| 6368 | |
| 6369 | serv.readFromParcelLocked(in); |
| 6370 | } |
| 6371 | } |
| 6372 | |
| 6373 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6374 | int numWA = mWakeupAlarms.size(); |
| 6375 | out.writeInt(numWA); |
| 6376 | for (int i=0; i<numWA; i++) { |
| 6377 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6378 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6379 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6381 | final int NS = mServiceStats.size(); |
| 6382 | out.writeInt(NS); |
| 6383 | for (int i=0; i<NS; i++) { |
| 6384 | out.writeString(mServiceStats.keyAt(i)); |
| 6385 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | serv.writeToParcelLocked(out); |
| 6387 | } |
| 6388 | } |
| 6389 | |
| 6390 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6391 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6392 | return mWakeupAlarms; |
| 6393 | } |
| 6394 | |
| 6395 | public void noteWakeupAlarmLocked(String tag) { |
| 6396 | Counter c = mWakeupAlarms.get(tag); |
| 6397 | if (c == null) { |
| 6398 | c = new Counter(mOnBatteryTimeBase); |
| 6399 | mWakeupAlarms.put(tag, c); |
| 6400 | } |
| 6401 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6405 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6406 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6407 | } |
| 6408 | |
| 6409 | /** |
| 6410 | * The statistics associated with a particular service. |
| 6411 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6412 | 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] | 6413 | /** |
| 6414 | * Total time (ms in battery uptime) the service has been left started. |
| 6415 | */ |
| 6416 | long mStartTime; |
| 6417 | |
| 6418 | /** |
| 6419 | * If service has been started and not yet stopped, this is |
| 6420 | * when it was started. |
| 6421 | */ |
| 6422 | long mRunningSince; |
| 6423 | |
| 6424 | /** |
| 6425 | * True if we are currently running. |
| 6426 | */ |
| 6427 | boolean mRunning; |
| 6428 | |
| 6429 | /** |
| 6430 | * Total number of times startService() has been called. |
| 6431 | */ |
| 6432 | int mStarts; |
| 6433 | |
| 6434 | /** |
| 6435 | * Total time (ms in battery uptime) the service has been left launched. |
| 6436 | */ |
| 6437 | long mLaunchedTime; |
| 6438 | |
| 6439 | /** |
| 6440 | * If service has been launched and not yet exited, this is |
| 6441 | * when it was launched (ms in battery uptime). |
| 6442 | */ |
| 6443 | long mLaunchedSince; |
| 6444 | |
| 6445 | /** |
| 6446 | * True if we are currently launched. |
| 6447 | */ |
| 6448 | boolean mLaunched; |
| 6449 | |
| 6450 | /** |
| 6451 | * Total number times the service has been launched. |
| 6452 | */ |
| 6453 | int mLaunches; |
| 6454 | |
| 6455 | /** |
| 6456 | * The amount of time spent started loaded from a previous save |
| 6457 | * (ms in battery uptime). |
| 6458 | */ |
| 6459 | long mLoadedStartTime; |
| 6460 | |
| 6461 | /** |
| 6462 | * The number of starts loaded from a previous save. |
| 6463 | */ |
| 6464 | int mLoadedStarts; |
| 6465 | |
| 6466 | /** |
| 6467 | * The number of launches loaded from a previous save. |
| 6468 | */ |
| 6469 | int mLoadedLaunches; |
| 6470 | |
| 6471 | /** |
| 6472 | * The amount of time spent started as of the last run (ms |
| 6473 | * in battery uptime). |
| 6474 | */ |
| 6475 | long mLastStartTime; |
| 6476 | |
| 6477 | /** |
| 6478 | * The number of starts as of the last run. |
| 6479 | */ |
| 6480 | int mLastStarts; |
| 6481 | |
| 6482 | /** |
| 6483 | * The number of launches as of the last run. |
| 6484 | */ |
| 6485 | int mLastLaunches; |
| 6486 | |
| 6487 | /** |
| 6488 | * The amount of time spent started when last unplugged (ms |
| 6489 | * in battery uptime). |
| 6490 | */ |
| 6491 | long mUnpluggedStartTime; |
| 6492 | |
| 6493 | /** |
| 6494 | * The number of starts when last unplugged. |
| 6495 | */ |
| 6496 | int mUnpluggedStarts; |
| 6497 | |
| 6498 | /** |
| 6499 | * The number of launches when last unplugged. |
| 6500 | */ |
| 6501 | int mUnpluggedLaunches; |
| 6502 | |
| 6503 | Serv() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6504 | mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6506 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6507 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 6508 | long baseRealtime) { |
| 6509 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | mUnpluggedStarts = mStarts; |
| 6511 | mUnpluggedLaunches = mLaunches; |
| 6512 | } |
| 6513 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6514 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 6515 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6516 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6517 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6518 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6519 | mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6520 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6522 | void readFromParcelLocked(Parcel in) { |
| 6523 | mStartTime = in.readLong(); |
| 6524 | mRunningSince = in.readLong(); |
| 6525 | mRunning = in.readInt() != 0; |
| 6526 | mStarts = in.readInt(); |
| 6527 | mLaunchedTime = in.readLong(); |
| 6528 | mLaunchedSince = in.readLong(); |
| 6529 | mLaunched = in.readInt() != 0; |
| 6530 | mLaunches = in.readInt(); |
| 6531 | mLoadedStartTime = in.readLong(); |
| 6532 | mLoadedStarts = in.readInt(); |
| 6533 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6534 | mLastStartTime = 0; |
| 6535 | mLastStarts = 0; |
| 6536 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6537 | mUnpluggedStartTime = in.readLong(); |
| 6538 | mUnpluggedStarts = in.readInt(); |
| 6539 | mUnpluggedLaunches = in.readInt(); |
| 6540 | } |
| 6541 | |
| 6542 | void writeToParcelLocked(Parcel out) { |
| 6543 | out.writeLong(mStartTime); |
| 6544 | out.writeLong(mRunningSince); |
| 6545 | out.writeInt(mRunning ? 1 : 0); |
| 6546 | out.writeInt(mStarts); |
| 6547 | out.writeLong(mLaunchedTime); |
| 6548 | out.writeLong(mLaunchedSince); |
| 6549 | out.writeInt(mLaunched ? 1 : 0); |
| 6550 | out.writeInt(mLaunches); |
| 6551 | out.writeLong(mLoadedStartTime); |
| 6552 | out.writeInt(mLoadedStarts); |
| 6553 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6554 | out.writeLong(mUnpluggedStartTime); |
| 6555 | out.writeInt(mUnpluggedStarts); |
| 6556 | out.writeInt(mUnpluggedLaunches); |
| 6557 | } |
| 6558 | |
| 6559 | long getLaunchTimeToNowLocked(long batteryUptime) { |
| 6560 | if (!mLaunched) return mLaunchedTime; |
| 6561 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 6562 | } |
| 6563 | |
| 6564 | long getStartTimeToNowLocked(long batteryUptime) { |
| 6565 | if (!mRunning) return mStartTime; |
| 6566 | return mStartTime + batteryUptime - mRunningSince; |
| 6567 | } |
| 6568 | |
| 6569 | public void startLaunchedLocked() { |
| 6570 | if (!mLaunched) { |
| 6571 | mLaunches++; |
| 6572 | mLaunchedSince = getBatteryUptimeLocked(); |
| 6573 | mLaunched = true; |
| 6574 | } |
| 6575 | } |
| 6576 | |
| 6577 | public void stopLaunchedLocked() { |
| 6578 | if (mLaunched) { |
| 6579 | long time = getBatteryUptimeLocked() - mLaunchedSince; |
| 6580 | if (time > 0) { |
| 6581 | mLaunchedTime += time; |
| 6582 | } else { |
| 6583 | mLaunches--; |
| 6584 | } |
| 6585 | mLaunched = false; |
| 6586 | } |
| 6587 | } |
| 6588 | |
| 6589 | public void startRunningLocked() { |
| 6590 | if (!mRunning) { |
| 6591 | mStarts++; |
| 6592 | mRunningSince = getBatteryUptimeLocked(); |
| 6593 | mRunning = true; |
| 6594 | } |
| 6595 | } |
| 6596 | |
| 6597 | public void stopRunningLocked() { |
| 6598 | if (mRunning) { |
| 6599 | long time = getBatteryUptimeLocked() - mRunningSince; |
| 6600 | if (time > 0) { |
| 6601 | mStartTime += time; |
| 6602 | } else { |
| 6603 | mStarts--; |
| 6604 | } |
| 6605 | mRunning = false; |
| 6606 | } |
| 6607 | } |
| 6608 | |
| 6609 | public BatteryStatsImpl getBatteryStats() { |
| 6610 | return BatteryStatsImpl.this; |
| 6611 | } |
| 6612 | |
| 6613 | @Override |
| 6614 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6615 | int val = mLaunches; |
| 6616 | if (which == STATS_CURRENT) { |
| 6617 | val -= mLoadedLaunches; |
| 6618 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6619 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | return val; |
| 6622 | } |
| 6623 | |
| 6624 | @Override |
| 6625 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6626 | long val = getStartTimeToNowLocked(now); |
| 6627 | if (which == STATS_CURRENT) { |
| 6628 | val -= mLoadedStartTime; |
| 6629 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6630 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6632 | return val; |
| 6633 | } |
| 6634 | |
| 6635 | @Override |
| 6636 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6637 | int val = mStarts; |
| 6638 | if (which == STATS_CURRENT) { |
| 6639 | val -= mLoadedStarts; |
| 6640 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6641 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | } |
| 6643 | |
| 6644 | return val; |
| 6645 | } |
| 6646 | } |
| 6647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6648 | final Serv newServiceStatsLocked() { |
| 6649 | return new Serv(); |
| 6650 | } |
| 6651 | } |
| 6652 | |
| 6653 | /** |
| 6654 | * Retrieve the statistics object for a particular process, creating |
| 6655 | * if needed. |
| 6656 | */ |
| 6657 | public Proc getProcessStatsLocked(String name) { |
| 6658 | Proc ps = mProcessStats.get(name); |
| 6659 | if (ps == null) { |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6660 | ps = new Proc(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6661 | mProcessStats.put(name, ps); |
| 6662 | } |
| 6663 | |
| 6664 | return ps; |
| 6665 | } |
| 6666 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6667 | public void updateProcessStateLocked(String procName, int state, long elapsedRealtimeMs) { |
| 6668 | int procState; |
| 6669 | if (state <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 6670 | procState = PROCESS_STATE_FOREGROUND; |
| 6671 | } else if (state <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 6672 | procState = PROCESS_STATE_ACTIVE; |
| 6673 | } else { |
| 6674 | procState = PROCESS_STATE_RUNNING; |
| 6675 | } |
| 6676 | updateRealProcessStateLocked(procName, procState, elapsedRealtimeMs); |
| 6677 | } |
| 6678 | |
| 6679 | public void updateRealProcessStateLocked(String procName, int procState, |
| 6680 | long elapsedRealtimeMs) { |
| 6681 | Proc proc = getProcessStatsLocked(procName); |
| 6682 | if (proc.mProcessState != procState) { |
| 6683 | boolean changed; |
| 6684 | if (procState < proc.mProcessState) { |
| 6685 | // Has this process become more important? If so, |
| 6686 | // we may need to change the uid if the currrent uid proc state |
| 6687 | // is not as important as what we are now setting. |
| 6688 | changed = mProcessState > procState; |
| 6689 | } else { |
| 6690 | // Has this process become less important? If so, |
| 6691 | // we may need to change the uid if the current uid proc state |
| 6692 | // is the same importance as the old setting. |
| 6693 | changed = mProcessState == proc.mProcessState; |
| 6694 | } |
| 6695 | proc.mProcessState = procState; |
| 6696 | if (changed) { |
| 6697 | // uid's state may have changed; compute what the new state should be. |
| 6698 | int uidProcState = PROCESS_STATE_NONE; |
| 6699 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6700 | proc = mProcessStats.valueAt(ip); |
| 6701 | if (proc.mProcessState < uidProcState) { |
| 6702 | uidProcState = proc.mProcessState; |
| 6703 | } |
| 6704 | } |
| 6705 | updateUidProcessStateLocked(uidProcState, elapsedRealtimeMs); |
| 6706 | } |
| 6707 | } |
| 6708 | } |
| 6709 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6710 | public SparseArray<? extends Pid> getPidStats() { |
| 6711 | return mPids; |
| 6712 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6713 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6714 | public Pid getPidStatsLocked(int pid) { |
| 6715 | Pid p = mPids.get(pid); |
| 6716 | if (p == null) { |
| 6717 | p = new Pid(); |
| 6718 | mPids.put(pid, p); |
| 6719 | } |
| 6720 | return p; |
| 6721 | } |
| 6722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6723 | /** |
| 6724 | * Retrieve the statistics object for a particular service, creating |
| 6725 | * if needed. |
| 6726 | */ |
| 6727 | public Pkg getPackageStatsLocked(String name) { |
| 6728 | Pkg ps = mPackageStats.get(name); |
| 6729 | if (ps == null) { |
| 6730 | ps = new Pkg(); |
| 6731 | mPackageStats.put(name, ps); |
| 6732 | } |
| 6733 | |
| 6734 | return ps; |
| 6735 | } |
| 6736 | |
| 6737 | /** |
| 6738 | * Retrieve the statistics object for a particular service, creating |
| 6739 | * if needed. |
| 6740 | */ |
| 6741 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 6742 | Pkg ps = getPackageStatsLocked(pkg); |
| 6743 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 6744 | if (ss == null) { |
| 6745 | ss = ps.newServiceStatsLocked(); |
| 6746 | ps.mServiceStats.put(serv, ss); |
| 6747 | } |
| 6748 | |
| 6749 | return ss; |
| 6750 | } |
| 6751 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6752 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 6753 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 6754 | timer.readSummaryFromParcelLocked(in); |
| 6755 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6758 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 6759 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 6760 | timer.readSummaryFromParcelLocked(in); |
| 6761 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6762 | } |
| 6763 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6764 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
| 6765 | Wakelock wl = new Wakelock(); |
| 6766 | mWakelockStats.add(wlName, wl); |
| 6767 | if (in.readInt() != 0) { |
| 6768 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6770 | if (in.readInt() != 0) { |
| 6771 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 6772 | } |
| 6773 | if (in.readInt() != 0) { |
| 6774 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6776 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6777 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6778 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6781 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6782 | Sensor se = mSensorStats.get(sensor); |
| 6783 | if (se == null) { |
| 6784 | if (!create) { |
| 6785 | return null; |
| 6786 | } |
| 6787 | se = new Sensor(sensor); |
| 6788 | mSensorStats.put(sensor, se); |
| 6789 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6790 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | if (t != null) { |
| 6792 | return t; |
| 6793 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6794 | ArrayList<StopwatchTimer> timers = mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6796 | timers = new ArrayList<StopwatchTimer>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | mSensorTimers.put(sensor, timers); |
| 6798 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6799 | t = new StopwatchTimer(Uid.this, BatteryStats.SENSOR, timers, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | se.mTimer = t; |
| 6801 | return t; |
| 6802 | } |
| 6803 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6804 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6805 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6806 | if (t != null) { |
| 6807 | t.startRunningLocked(elapsedRealtimeMs); |
| 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6812 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6813 | if (t != null) { |
| 6814 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6815 | } |
| 6816 | } |
| 6817 | |
| 6818 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 6819 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6820 | if (t != null) { |
| 6821 | t.startRunningLocked(elapsedRealtimeMs); |
| 6822 | } |
| 6823 | } |
| 6824 | |
| 6825 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6826 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6827 | if (t != null) { |
| 6828 | t.stopRunningLocked(elapsedRealtimeMs); |
| 6829 | } |
| 6830 | } |
| 6831 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6832 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6833 | Wakelock wl = mWakelockStats.startObject(name); |
| 6834 | if (wl != null) { |
| 6835 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6837 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6838 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6839 | if (p.mWakeNesting++ == 0) { |
| 6840 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 6841 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6842 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6843 | } |
| 6844 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6845 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6846 | Wakelock wl = mWakelockStats.stopObject(name); |
| 6847 | if (wl != null) { |
| 6848 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6849 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 6850 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6851 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6852 | if (p != null && p.mWakeNesting > 0) { |
| 6853 | if (p.mWakeNesting-- == 1) { |
| 6854 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 6855 | p.mWakeStartMs = 0; |
| 6856 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 6862 | Proc p = getProcessStatsLocked(proc); |
| 6863 | if (p != null) { |
| 6864 | p.addExcessiveWake(overTime, usedTime); |
| 6865 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6867 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6868 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 6869 | Proc p = getProcessStatsLocked(proc); |
| 6870 | if (p != null) { |
| 6871 | p.addExcessiveCpu(overTime, usedTime); |
| 6872 | } |
| 6873 | } |
| 6874 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6875 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6876 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6878 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6879 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | } |
| 6881 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6882 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6884 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6885 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6886 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6888 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6889 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6890 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6891 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6893 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6894 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6896 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6897 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6898 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6900 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | public BatteryStatsImpl getBatteryStats() { |
| 6905 | return BatteryStatsImpl.this; |
| 6906 | } |
| 6907 | } |
| 6908 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6909 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6910 | if (systemDir != null) { |
| 6911 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 6912 | new File(systemDir, "batterystats.bin.tmp")); |
| 6913 | } else { |
| 6914 | mFile = null; |
| 6915 | } |
| 6916 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6917 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6918 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 6919 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6920 | mStartCount++; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6921 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6922 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6923 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6924 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6925 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase); |
| 6926 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 6927 | mDeviceIdleModeLightTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase); |
| 6928 | mDeviceIdleModeFullTimer = new StopwatchTimer(null, -14, null, mOnBatteryTimeBase); |
| 6929 | mDeviceLightIdlingTimer = new StopwatchTimer(null, -15, null, mOnBatteryTimeBase); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6930 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6931 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 6932 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6933 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, |
| 6934 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6935 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6936 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6937 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6938 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, null, |
| 6939 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6940 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6941 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6942 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6943 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6944 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6945 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 6946 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6947 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6948 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6949 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); |
| 6950 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6951 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6952 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 6953 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6954 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase); |
| 6955 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6956 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6957 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6958 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6959 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 6960 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, null, mOnBatteryTimeBase); |
| 6961 | } |
| 6962 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 6963 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, null, |
| 6964 | mOnBatteryTimeBase); |
| 6965 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6966 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
| 6967 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6968 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6969 | mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6971 | long uptime = SystemClock.uptimeMillis() * 1000; |
| 6972 | long realtime = SystemClock.elapsedRealtime() * 1000; |
| 6973 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6974 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6975 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6976 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6977 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 6978 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 6979 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 6980 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6981 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6982 | updateDailyDeadlineLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | public BatteryStatsImpl(Parcel p) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 6986 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 6987 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6988 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 6989 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6990 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6991 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6992 | readFromParcel(p); |
| 6993 | } |
| 6994 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6995 | public void setPowerProfile(PowerProfile profile) { |
| 6996 | synchronized (this) { |
| 6997 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6998 | |
| 6999 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 7000 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 7001 | // information. |
| 7002 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 7003 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 7004 | int firstCpuOfCluster = 0; |
| 7005 | for (int i = 0; i < numClusters; i++) { |
| 7006 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 7007 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 7008 | numSpeedSteps); |
| 7009 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 7010 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7011 | } |
| 7012 | } |
| 7013 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7014 | public void setCallback(BatteryCallback cb) { |
| 7015 | mCallback = cb; |
| 7016 | } |
| 7017 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7018 | public void setRadioScanningTimeout(long timeout) { |
| 7019 | if (mPhoneSignalScanningTimer != null) { |
| 7020 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 7021 | } |
| 7022 | } |
| 7023 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7024 | public void updateDailyDeadlineLocked() { |
| 7025 | // Get the current time. |
| 7026 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 7027 | Calendar calDeadline = Calendar.getInstance(); |
| 7028 | calDeadline.setTimeInMillis(currentTime); |
| 7029 | |
| 7030 | // Move time up to the next day, ranging from 1am to 3pm. |
| 7031 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 7032 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 7033 | calDeadline.set(Calendar.SECOND, 0); |
| 7034 | calDeadline.set(Calendar.MINUTE, 0); |
| 7035 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 7036 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 7037 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 7038 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 7039 | } |
| 7040 | |
| 7041 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 7042 | long currentTime = System.currentTimeMillis(); |
| 7043 | if (currentTime >= mNextMaxDailyDeadline) { |
| 7044 | recordDailyStatsLocked(); |
| 7045 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 7046 | recordDailyStatsLocked(); |
| 7047 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 7048 | recordDailyStatsLocked(); |
| 7049 | } |
| 7050 | } |
| 7051 | |
| 7052 | public void recordDailyStatsLocked() { |
| 7053 | DailyItem item = new DailyItem(); |
| 7054 | item.mStartTime = mDailyStartTime; |
| 7055 | item.mEndTime = System.currentTimeMillis(); |
| 7056 | boolean hasData = false; |
| 7057 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 7058 | hasData = true; |
| 7059 | item.mDischargeSteps = new LevelStepTracker( |
| 7060 | mDailyDischargeStepTracker.mNumStepDurations, |
| 7061 | mDailyDischargeStepTracker.mStepDurations); |
| 7062 | } |
| 7063 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 7064 | hasData = true; |
| 7065 | item.mChargeSteps = new LevelStepTracker( |
| 7066 | mDailyChargeStepTracker.mNumStepDurations, |
| 7067 | mDailyChargeStepTracker.mStepDurations); |
| 7068 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7069 | if (mDailyPackageChanges != null) { |
| 7070 | hasData = true; |
| 7071 | item.mPackageChanges = mDailyPackageChanges; |
| 7072 | mDailyPackageChanges = null; |
| 7073 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7074 | mDailyDischargeStepTracker.init(); |
| 7075 | mDailyChargeStepTracker.init(); |
| 7076 | updateDailyDeadlineLocked(); |
| 7077 | |
| 7078 | if (hasData) { |
| 7079 | mDailyItems.add(item); |
| 7080 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 7081 | mDailyItems.remove(0); |
| 7082 | } |
| 7083 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 7084 | try { |
| 7085 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7086 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7087 | writeDailyItemsLocked(out); |
| 7088 | BackgroundThread.getHandler().post(new Runnable() { |
| 7089 | @Override |
| 7090 | public void run() { |
| 7091 | synchronized (mCheckinFile) { |
| 7092 | FileOutputStream stream = null; |
| 7093 | try { |
| 7094 | stream = mDailyFile.startWrite(); |
| 7095 | memStream.writeTo(stream); |
| 7096 | stream.flush(); |
| 7097 | FileUtils.sync(stream); |
| 7098 | stream.close(); |
| 7099 | mDailyFile.finishWrite(stream); |
| 7100 | } catch (IOException e) { |
| 7101 | Slog.w("BatteryStats", |
| 7102 | "Error writing battery daily items", e); |
| 7103 | mDailyFile.failWrite(stream); |
| 7104 | } |
| 7105 | } |
| 7106 | } |
| 7107 | }); |
| 7108 | } catch (IOException e) { |
| 7109 | } |
| 7110 | } |
| 7111 | } |
| 7112 | |
| 7113 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 7114 | StringBuilder sb = new StringBuilder(64); |
| 7115 | out.startDocument(null, true); |
| 7116 | out.startTag(null, "daily-items"); |
| 7117 | for (int i=0; i<mDailyItems.size(); i++) { |
| 7118 | final DailyItem dit = mDailyItems.get(i); |
| 7119 | out.startTag(null, "item"); |
| 7120 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 7121 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 7122 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 7123 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7124 | if (dit.mPackageChanges != null) { |
| 7125 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 7126 | PackageChange pc = dit.mPackageChanges.get(j); |
| 7127 | if (pc.mUpdate) { |
| 7128 | out.startTag(null, "upd"); |
| 7129 | out.attribute(null, "pkg", pc.mPackageName); |
| 7130 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 7131 | out.endTag(null, "upd"); |
| 7132 | } else { |
| 7133 | out.startTag(null, "rem"); |
| 7134 | out.attribute(null, "pkg", pc.mPackageName); |
| 7135 | out.endTag(null, "rem"); |
| 7136 | } |
| 7137 | } |
| 7138 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7139 | out.endTag(null, "item"); |
| 7140 | } |
| 7141 | out.endTag(null, "daily-items"); |
| 7142 | out.endDocument(); |
| 7143 | } |
| 7144 | |
| 7145 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 7146 | StringBuilder tmpBuilder) throws IOException { |
| 7147 | if (steps != null) { |
| 7148 | out.startTag(null, tag); |
| 7149 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 7150 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 7151 | out.startTag(null, "s"); |
| 7152 | tmpBuilder.setLength(0); |
| 7153 | steps.encodeEntryAt(i, tmpBuilder); |
| 7154 | out.attribute(null, "v", tmpBuilder.toString()); |
| 7155 | out.endTag(null, "s"); |
| 7156 | } |
| 7157 | out.endTag(null, tag); |
| 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | public void readDailyStatsLocked() { |
| 7162 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 7163 | mDailyItems.clear(); |
| 7164 | FileInputStream stream; |
| 7165 | try { |
| 7166 | stream = mDailyFile.openRead(); |
| 7167 | } catch (FileNotFoundException e) { |
| 7168 | return; |
| 7169 | } |
| 7170 | try { |
| 7171 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7172 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7173 | readDailyItemsLocked(parser); |
| 7174 | } catch (XmlPullParserException e) { |
| 7175 | } finally { |
| 7176 | try { |
| 7177 | stream.close(); |
| 7178 | } catch (IOException e) { |
| 7179 | } |
| 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7184 | try { |
| 7185 | int type; |
| 7186 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7187 | && type != XmlPullParser.END_DOCUMENT) { |
| 7188 | ; |
| 7189 | } |
| 7190 | |
| 7191 | if (type != XmlPullParser.START_TAG) { |
| 7192 | throw new IllegalStateException("no start tag found"); |
| 7193 | } |
| 7194 | |
| 7195 | int outerDepth = parser.getDepth(); |
| 7196 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7197 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7198 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7199 | continue; |
| 7200 | } |
| 7201 | |
| 7202 | String tagName = parser.getName(); |
| 7203 | if (tagName.equals("item")) { |
| 7204 | readDailyItemTagLocked(parser); |
| 7205 | } else { |
| 7206 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7207 | + parser.getName()); |
| 7208 | XmlUtils.skipCurrentTag(parser); |
| 7209 | } |
| 7210 | } |
| 7211 | |
| 7212 | } catch (IllegalStateException e) { |
| 7213 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7214 | } catch (NullPointerException e) { |
| 7215 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7216 | } catch (NumberFormatException e) { |
| 7217 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7218 | } catch (XmlPullParserException e) { |
| 7219 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7220 | } catch (IOException e) { |
| 7221 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7222 | } catch (IndexOutOfBoundsException e) { |
| 7223 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7224 | } |
| 7225 | } |
| 7226 | |
| 7227 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7228 | XmlPullParserException, IOException { |
| 7229 | DailyItem dit = new DailyItem(); |
| 7230 | String attr = parser.getAttributeValue(null, "start"); |
| 7231 | if (attr != null) { |
| 7232 | dit.mStartTime = Long.parseLong(attr); |
| 7233 | } |
| 7234 | attr = parser.getAttributeValue(null, "end"); |
| 7235 | if (attr != null) { |
| 7236 | dit.mEndTime = Long.parseLong(attr); |
| 7237 | } |
| 7238 | int outerDepth = parser.getDepth(); |
| 7239 | int type; |
| 7240 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7241 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7242 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7243 | continue; |
| 7244 | } |
| 7245 | |
| 7246 | String tagName = parser.getName(); |
| 7247 | if (tagName.equals("dis")) { |
| 7248 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7249 | } else if (tagName.equals("chg")) { |
| 7250 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7251 | } else if (tagName.equals("upd")) { |
| 7252 | if (dit.mPackageChanges == null) { |
| 7253 | dit.mPackageChanges = new ArrayList<>(); |
| 7254 | } |
| 7255 | PackageChange pc = new PackageChange(); |
| 7256 | pc.mUpdate = true; |
| 7257 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7258 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7259 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7260 | dit.mPackageChanges.add(pc); |
| 7261 | XmlUtils.skipCurrentTag(parser); |
| 7262 | } else if (tagName.equals("rem")) { |
| 7263 | if (dit.mPackageChanges == null) { |
| 7264 | dit.mPackageChanges = new ArrayList<>(); |
| 7265 | } |
| 7266 | PackageChange pc = new PackageChange(); |
| 7267 | pc.mUpdate = false; |
| 7268 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7269 | dit.mPackageChanges.add(pc); |
| 7270 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7271 | } else { |
| 7272 | Slog.w(TAG, "Unknown element under <item>: " |
| 7273 | + parser.getName()); |
| 7274 | XmlUtils.skipCurrentTag(parser); |
| 7275 | } |
| 7276 | } |
| 7277 | mDailyItems.add(dit); |
| 7278 | } |
| 7279 | |
| 7280 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7281 | String tag) |
| 7282 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7283 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7284 | if (numAttr == null) { |
| 7285 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7286 | XmlUtils.skipCurrentTag(parser); |
| 7287 | return; |
| 7288 | } |
| 7289 | final int num = Integer.parseInt(numAttr); |
| 7290 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7291 | if (isCharge) { |
| 7292 | dit.mChargeSteps = steps; |
| 7293 | } else { |
| 7294 | dit.mDischargeSteps = steps; |
| 7295 | } |
| 7296 | int i = 0; |
| 7297 | int outerDepth = parser.getDepth(); |
| 7298 | int type; |
| 7299 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7300 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7301 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7302 | continue; |
| 7303 | } |
| 7304 | |
| 7305 | String tagName = parser.getName(); |
| 7306 | if ("s".equals(tagName)) { |
| 7307 | if (i < num) { |
| 7308 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7309 | if (valueAttr != null) { |
| 7310 | steps.decodeEntryAt(i, valueAttr); |
| 7311 | i++; |
| 7312 | } |
| 7313 | } |
| 7314 | } else { |
| 7315 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7316 | + parser.getName()); |
| 7317 | XmlUtils.skipCurrentTag(parser); |
| 7318 | } |
| 7319 | } |
| 7320 | steps.mNumStepDurations = i; |
| 7321 | } |
| 7322 | |
| 7323 | @Override |
| 7324 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7325 | int index = mDailyItems.size()-1-daysAgo; |
| 7326 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7327 | } |
| 7328 | |
| 7329 | @Override |
| 7330 | public long getCurrentDailyStartTime() { |
| 7331 | return mDailyStartTime; |
| 7332 | } |
| 7333 | |
| 7334 | @Override |
| 7335 | public long getNextMinDailyDeadline() { |
| 7336 | return mNextMinDailyDeadline; |
| 7337 | } |
| 7338 | |
| 7339 | @Override |
| 7340 | public long getNextMaxDailyDeadline() { |
| 7341 | return mNextMaxDailyDeadline; |
| 7342 | } |
| 7343 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7344 | @Override |
| 7345 | public boolean startIteratingOldHistoryLocked() { |
| 7346 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7347 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7348 | if ((mHistoryIterator = mHistory) == null) { |
| 7349 | return false; |
| 7350 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7351 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7352 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7353 | mReadOverflow = false; |
| 7354 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7355 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7356 | } |
| 7357 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7358 | @Override |
| 7359 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7360 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7361 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7362 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7363 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7364 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7365 | HistoryItem cur = mHistoryIterator; |
| 7366 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7367 | if (!mReadOverflow && !end) { |
| 7368 | Slog.w(TAG, "Old history ends before new history!"); |
| 7369 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7370 | return false; |
| 7371 | } |
| 7372 | out.setTo(cur); |
| 7373 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7374 | if (!mReadOverflow) { |
| 7375 | if (end) { |
| 7376 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7377 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7378 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7379 | pw.println("Histories differ!"); |
| 7380 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7381 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7382 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7383 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7384 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7385 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7386 | } |
| 7387 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7388 | return true; |
| 7389 | } |
| 7390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7392 | public void finishIteratingOldHistoryLocked() { |
| 7393 | mIteratingHistory = false; |
| 7394 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7395 | mHistoryIterator = null; |
| 7396 | } |
| 7397 | |
| 7398 | public int getHistoryTotalSize() { |
| 7399 | return MAX_HISTORY_BUFFER; |
| 7400 | } |
| 7401 | |
| 7402 | public int getHistoryUsedSize() { |
| 7403 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7404 | } |
| 7405 | |
| 7406 | @Override |
| 7407 | public boolean startIteratingHistoryLocked() { |
| 7408 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7409 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7410 | if (mHistoryBuffer.dataSize() <= 0) { |
| 7411 | return false; |
| 7412 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7413 | mHistoryBuffer.setDataPosition(0); |
| 7414 | mReadOverflow = false; |
| 7415 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7416 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 7417 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 7418 | mReadHistoryChars = 0; |
| 7419 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7420 | final HistoryTag tag = ent.getKey(); |
| 7421 | final int idx = ent.getValue(); |
| 7422 | mReadHistoryStrings[idx] = tag.string; |
| 7423 | mReadHistoryUids[idx] = tag.uid; |
| 7424 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7425 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7426 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7430 | public int getHistoryStringPoolSize() { |
| 7431 | return mReadHistoryStrings.length; |
| 7432 | } |
| 7433 | |
| 7434 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7435 | public int getHistoryStringPoolBytes() { |
| 7436 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 7437 | // Each string character is 2 bytes. |
| 7438 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 7439 | } |
| 7440 | |
| 7441 | @Override |
| 7442 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7443 | return mReadHistoryStrings[index]; |
| 7444 | } |
| 7445 | |
| 7446 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7447 | public int getHistoryTagPoolUid(int index) { |
| 7448 | return mReadHistoryUids[index]; |
| 7449 | } |
| 7450 | |
| 7451 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7452 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7453 | final int pos = mHistoryBuffer.dataPosition(); |
| 7454 | if (pos == 0) { |
| 7455 | out.clear(); |
| 7456 | } |
| 7457 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7458 | if (end) { |
| 7459 | return false; |
| 7460 | } |
| 7461 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7462 | final long lastRealtime = out.time; |
| 7463 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7464 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7465 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 7466 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7467 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 7468 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7469 | return true; |
| 7470 | } |
| 7471 | |
| 7472 | @Override |
| 7473 | public void finishIteratingHistoryLocked() { |
| 7474 | mIteratingHistory = false; |
| 7475 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7476 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7477 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7478 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7479 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7480 | public long getHistoryBaseTime() { |
| 7481 | return mHistoryBaseTime; |
| 7482 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7483 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7484 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | public int getStartCount() { |
| 7486 | return mStartCount; |
| 7487 | } |
| 7488 | |
| 7489 | public boolean isOnBattery() { |
| 7490 | return mOnBattery; |
| 7491 | } |
| 7492 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7493 | public boolean isCharging() { |
| 7494 | return mCharging; |
| 7495 | } |
| 7496 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7497 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7498 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7499 | } |
| 7500 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7501 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7502 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7503 | mOnBatteryTimeBase.init(uptime, realtime); |
| 7504 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7505 | mRealtime = 0; |
| 7506 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7507 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7508 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7509 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7510 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7511 | void initDischarge() { |
| 7512 | mLowDischargeAmountSinceCharge = 0; |
| 7513 | mHighDischargeAmountSinceCharge = 0; |
| 7514 | mDischargeAmountScreenOn = 0; |
| 7515 | mDischargeAmountScreenOnSinceCharge = 0; |
| 7516 | mDischargeAmountScreenOff = 0; |
| 7517 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7518 | mDischargeStepTracker.init(); |
| 7519 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7520 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7521 | |
| 7522 | public void resetAllStatsCmdLocked() { |
| 7523 | resetAllStatsLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7524 | final long mSecUptime = SystemClock.uptimeMillis(); |
| 7525 | long uptime = mSecUptime * 1000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7526 | long mSecRealtime = SystemClock.elapsedRealtime(); |
| 7527 | long realtime = mSecRealtime * 1000; |
| 7528 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 7529 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7530 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7531 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 7532 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7533 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 7534 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 7535 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7536 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7537 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 7538 | mDischargeScreenOffUnplugLevel = 0; |
| 7539 | } else { |
| 7540 | mDischargeScreenOnUnplugLevel = 0; |
| 7541 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 7542 | } |
| 7543 | mDischargeAmountScreenOn = 0; |
| 7544 | mDischargeAmountScreenOff = 0; |
| 7545 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7546 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7550 | mStartCount = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7551 | initTimes(SystemClock.uptimeMillis() * 1000, SystemClock.elapsedRealtime() * 1000); |
| 7552 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7553 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7554 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7555 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7556 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 7557 | mPowerSaveModeEnabledTimer.reset(false); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 7558 | mLongestLightIdleTime = 0; |
| 7559 | mLongestFullIdleTime = 0; |
| 7560 | mDeviceIdleModeLightTimer.reset(false); |
| 7561 | mDeviceIdleModeFullTimer.reset(false); |
| 7562 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7563 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7564 | mPhoneOnTimer.reset(false); |
| 7565 | mAudioOnTimer.reset(false); |
| 7566 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 7567 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7568 | mCameraOnTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 7569 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7570 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7571 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7572 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7573 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7574 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7575 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7576 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7577 | mNetworkByteActivityCounters[i].reset(false); |
| 7578 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7579 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7580 | mMobileRadioActiveTimer.reset(false); |
| 7581 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7582 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7583 | mMobileRadioActiveUnknownTime.reset(false); |
| 7584 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7585 | mWifiOnTimer.reset(false); |
| 7586 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7587 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7588 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7589 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7590 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7591 | mWifiSupplStateTimer[i].reset(false); |
| 7592 | } |
| 7593 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7594 | mWifiSignalStrengthsTimer[i].reset(false); |
| 7595 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 7596 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 7597 | mBluetoothActivityCounters[i].reset(false); |
| 7598 | mWifiActivityCounters[i].reset(false); |
| 7599 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7600 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7601 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7602 | for (int i=0; i<mUidStats.size(); i++) { |
| 7603 | if (mUidStats.valueAt(i).reset()) { |
| 7604 | mUidStats.remove(mUidStats.keyAt(i)); |
| 7605 | i--; |
| 7606 | } |
| 7607 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7608 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7609 | if (mKernelWakelockStats.size() > 0) { |
| 7610 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7611 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7612 | } |
| 7613 | mKernelWakelockStats.clear(); |
| 7614 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7615 | |
| 7616 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7617 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 7618 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7619 | } |
| 7620 | mWakeupReasonStats.clear(); |
| 7621 | } |
| 7622 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 7623 | mLastHistoryStepDetails = null; |
| 7624 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 7625 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 7626 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 7627 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 7628 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 7629 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 7630 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 7631 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 7632 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 7633 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 7634 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7635 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7636 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7637 | clearHistoryLocked(); |
| 7638 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7639 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7640 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7641 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7642 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 7643 | // Not recording process starts/stops. |
| 7644 | continue; |
| 7645 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7646 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7647 | if (active == null) { |
| 7648 | continue; |
| 7649 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7650 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 7651 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7652 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7653 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 7654 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 7655 | } |
| 7656 | } |
| 7657 | } |
| 7658 | } |
| 7659 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 7660 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7661 | if (oldScreenOn) { |
| 7662 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 7663 | if (diff > 0) { |
| 7664 | mDischargeAmountScreenOn += diff; |
| 7665 | mDischargeAmountScreenOnSinceCharge += diff; |
| 7666 | } |
| 7667 | } else { |
| 7668 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 7669 | if (diff > 0) { |
| 7670 | mDischargeAmountScreenOff += diff; |
| 7671 | mDischargeAmountScreenOffSinceCharge += diff; |
| 7672 | } |
| 7673 | } |
| 7674 | if (newScreenOn) { |
| 7675 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 7676 | mDischargeScreenOffUnplugLevel = 0; |
| 7677 | } else { |
| 7678 | mDischargeScreenOnUnplugLevel = 0; |
| 7679 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 7680 | } |
| 7681 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7682 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7683 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7684 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7685 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 7686 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 7687 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 7688 | } |
| 7689 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7690 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 7691 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 7692 | |
| 7693 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 7694 | |
| 7695 | private static final int NETWORK_STATS_LAST = 0; |
| 7696 | private static final int NETWORK_STATS_NEXT = 1; |
| 7697 | private static final int NETWORK_STATS_DELTA = 2; |
| 7698 | |
| 7699 | private final NetworkStats[] mMobileNetworkStats = new NetworkStats[] { |
| 7700 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7701 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7702 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7703 | }; |
| 7704 | |
| 7705 | private final NetworkStats[] mWifiNetworkStats = new NetworkStats[] { |
| 7706 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7707 | new NetworkStats(SystemClock.elapsedRealtime(), 50), |
| 7708 | new NetworkStats(SystemClock.elapsedRealtime(), 50) |
| 7709 | }; |
| 7710 | |
| 7711 | /** |
| 7712 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 7713 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 7714 | */ |
| 7715 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 7716 | NetworkStats[] networkStatsBuffer) |
| 7717 | throws IOException { |
| 7718 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 7719 | false)) { |
| 7720 | return null; |
| 7721 | } |
| 7722 | |
| 7723 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 7724 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 7725 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 7726 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 7727 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 7728 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 7729 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 7730 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 7731 | } |
| 7732 | |
| 7733 | /** |
| 7734 | * Distribute WiFi energy info and network traffic to apps. |
| 7735 | * @param info The energy information from the WiFi controller. |
| 7736 | */ |
| 7737 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 7738 | if (DEBUG_ENERGY) { |
| 7739 | Slog.d(TAG, "Updating wifi stats"); |
| 7740 | } |
| 7741 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7742 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 7743 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7744 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7745 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 7746 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 7747 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7748 | } catch (IOException e) { |
| 7749 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 7750 | return; |
| 7751 | } |
| 7752 | |
| 7753 | if (!mOnBatteryInternal) { |
| 7754 | return; |
| 7755 | } |
| 7756 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7757 | SparseLongArray rxPackets = new SparseLongArray(); |
| 7758 | SparseLongArray txPackets = new SparseLongArray(); |
| 7759 | long totalTxPackets = 0; |
| 7760 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7761 | if (delta != null) { |
| 7762 | final int size = delta.size(); |
| 7763 | for (int i = 0; i < size; i++) { |
| 7764 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7765 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7766 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7767 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7768 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7769 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7770 | } |
| 7771 | |
| 7772 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7773 | continue; |
| 7774 | } |
| 7775 | |
| 7776 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7777 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 7778 | entry.rxPackets); |
| 7779 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 7780 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7781 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 7782 | txPackets.put(u.getUid(), entry.txPackets); |
| 7783 | |
| 7784 | // Sum the total number of packets so that the Rx Power and Tx Power can |
| 7785 | // be evenly distributed amongst the apps. |
| 7786 | totalRxPackets += entry.rxPackets; |
| 7787 | totalTxPackets += entry.txPackets; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7788 | |
| 7789 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7790 | entry.rxBytes); |
| 7791 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7792 | entry.txBytes); |
| 7793 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 7794 | entry.rxPackets); |
| 7795 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 7796 | entry.txPackets); |
| 7797 | } |
| 7798 | } |
| 7799 | |
| 7800 | if (info != null) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 7801 | mHasWifiEnergyReporting = true; |
| 7802 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7803 | // Measured in mAms |
| 7804 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 7805 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 7806 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 7807 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 7808 | |
| 7809 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7810 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7811 | |
| 7812 | if (DEBUG_ENERGY) { |
| 7813 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 7814 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 7815 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 7816 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 7817 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 7818 | } |
| 7819 | |
| 7820 | long totalWifiLockTimeMs = 0; |
| 7821 | long totalScanTimeMs = 0; |
| 7822 | |
| 7823 | // On the first pass, collect some totals so that we can normalize power |
| 7824 | // calculations if we need to. |
| 7825 | final int uidStatsSize = mUidStats.size(); |
| 7826 | for (int i = 0; i < uidStatsSize; i++) { |
| 7827 | final Uid uid = mUidStats.valueAt(i); |
| 7828 | |
| 7829 | // Sum the total scan power for all apps. |
| 7830 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7831 | elapsedRealtimeMs * 1000) / 1000; |
| 7832 | |
| 7833 | // Sum the total time holding wifi lock for all apps. |
| 7834 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7835 | elapsedRealtimeMs * 1000) / 1000; |
| 7836 | } |
| 7837 | |
| 7838 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 7839 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 7840 | + rxTimeMs + " ms). Normalizing scan time."); |
| 7841 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7842 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 7843 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 7844 | + txTimeMs + " ms). Normalizing scan time."); |
| 7845 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7846 | |
| 7847 | // Actually assign and distribute power usage to apps. |
| 7848 | for (int i = 0; i < uidStatsSize; i++) { |
| 7849 | final Uid uid = mUidStats.valueAt(i); |
| 7850 | |
| 7851 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 7852 | elapsedRealtimeMs * 1000) / 1000; |
| 7853 | if (scanTimeSinceMarkMs > 0) { |
| 7854 | // Set the new mark so that next time we get new data since this point. |
| 7855 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 7856 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7857 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 7858 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 7859 | |
| 7860 | // Our total scan time is more than the reported Tx/Rx time. |
| 7861 | // This is possible because the cost of a scan is approximate. |
| 7862 | // Let's normalize the result so that we evenly blame each app |
| 7863 | // scanning. |
| 7864 | // |
| 7865 | // This means that we may have apps that transmitted/received packets not be |
| 7866 | // blamed for this, but this is fine as scans are relatively more expensive. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7867 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7868 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 7869 | totalScanTimeMs; |
| 7870 | } |
| 7871 | if (totalScanTimeMs > txTimeMs) { |
| 7872 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 7873 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7874 | } |
| 7875 | |
| 7876 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7877 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 7878 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 7879 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7880 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7881 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, scanRxTimeSinceMarkMs); |
| 7882 | uid.noteWifiControllerActivityLocked(CONTROLLER_TX_TIME, scanTxTimeSinceMarkMs); |
| 7883 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 7884 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7885 | } |
| 7886 | |
| 7887 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 7888 | // lock. |
| 7889 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 7890 | elapsedRealtimeMs * 1000) / 1000; |
| 7891 | if (wifiLockTimeSinceMarkMs > 0) { |
| 7892 | // Set the new mark so that next time we get new data since this point. |
| 7893 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 7894 | |
| 7895 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 7896 | / totalWifiLockTimeMs; |
| 7897 | if (DEBUG_ENERGY) { |
| 7898 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 7899 | + myIdleTimeMs + " ms"); |
| 7900 | } |
| 7901 | uid.noteWifiControllerActivityLocked(CONTROLLER_IDLE_TIME, myIdleTimeMs); |
| 7902 | } |
| 7903 | } |
| 7904 | |
| 7905 | if (DEBUG_ENERGY) { |
| 7906 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7907 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7908 | } |
| 7909 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7910 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 7911 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7912 | for (int i = 0; i < txPackets.size(); i++) { |
| 7913 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 7914 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7915 | if (DEBUG_ENERGY) { |
| 7916 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 7917 | } |
| 7918 | uid.noteWifiControllerActivityLocked(CONTROLLER_TX_TIME, myTxTimeMs); |
| 7919 | } |
| 7920 | |
| 7921 | // Distribute the remaining Rx power appropriately between all apps that received |
| 7922 | // packets. |
| 7923 | for (int i = 0; i < rxPackets.size(); i++) { |
| 7924 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 7925 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 7926 | if (DEBUG_ENERGY) { |
| 7927 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 7928 | } |
| 7929 | uid.noteWifiControllerActivityLocked(CONTROLLER_RX_TIME, myRxTimeMs); |
| 7930 | } |
| 7931 | |
| 7932 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 7933 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7934 | // Update WiFi controller stats. |
| 7935 | mWifiActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 7936 | info.getControllerRxTimeMillis()); |
| 7937 | mWifiActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 7938 | info.getControllerTxTimeMillis()); |
| 7939 | mWifiActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 7940 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7941 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7942 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 7943 | final double opVolt = mPowerProfile.getAveragePower( |
| 7944 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 7945 | if (opVolt != 0) { |
| 7946 | // We store the power drain as mAms. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 7947 | mWifiActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 7948 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7949 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7950 | } |
| 7951 | } |
| 7952 | |
| 7953 | /** |
| 7954 | * Distribute Cell radio energy info and network traffic to apps. |
| 7955 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7956 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 7957 | if (DEBUG_ENERGY) { |
| 7958 | Slog.d(TAG, "Updating mobile radio stats"); |
| 7959 | } |
| 7960 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7961 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7962 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7963 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 7964 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 7965 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7966 | } catch (IOException e) { |
| 7967 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 7968 | return; |
| 7969 | } |
| 7970 | |
| 7971 | if (delta == null || !mOnBatteryInternal) { |
| 7972 | return; |
| 7973 | } |
| 7974 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7975 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 7976 | elapsedRealtimeMs * 1000); |
| 7977 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7978 | long totalPackets = delta.getTotalPackets(); |
| 7979 | |
| 7980 | final int size = delta.size(); |
| 7981 | for (int i = 0; i < size; i++) { |
| 7982 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 7983 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7984 | if (entry.rxBytes == 0 || entry.txBytes == 0) { |
| 7985 | continue; |
| 7986 | } |
| 7987 | |
| 7988 | if (DEBUG_ENERGY) { |
| 7989 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 7990 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 7991 | + " txPackets=" + entry.txPackets); |
| 7992 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7993 | |
| 7994 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 7995 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 7996 | entry.rxPackets); |
| 7997 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 7998 | entry.txPackets); |
| 7999 | |
| 8000 | if (radioTime > 0) { |
| 8001 | // Distribute total radio active time in to this app. |
| 8002 | long appPackets = entry.rxPackets + entry.txPackets; |
| 8003 | long appRadioTime = (radioTime*appPackets)/totalPackets; |
| 8004 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 8005 | // Remove this app from the totals, so that we don't lose any time |
| 8006 | // due to rounding. |
| 8007 | radioTime -= appRadioTime; |
| 8008 | totalPackets -= appPackets; |
| 8009 | } |
| 8010 | |
| 8011 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8012 | entry.rxBytes); |
| 8013 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8014 | entry.txBytes); |
| 8015 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8016 | entry.rxPackets); |
| 8017 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8018 | entry.txPackets); |
| 8019 | } |
| 8020 | |
| 8021 | if (radioTime > 0) { |
| 8022 | // Whoops, there is some radio time we can't blame on an app! |
| 8023 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 8024 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 8025 | } |
| 8026 | } |
| 8027 | |
| 8028 | /** |
| 8029 | * Distribute Bluetooth energy info and network traffic to apps. |
| 8030 | * @param info The energy information from the bluetooth controller. |
| 8031 | */ |
| 8032 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8033 | if (DEBUG_ENERGY) { |
| 8034 | Slog.d(TAG, "Updating bluetooth stats"); |
| 8035 | } |
| 8036 | |
Adam Lesinski | 719e61f | 2015-05-15 15:49:24 -0700 | [diff] [blame] | 8037 | if (info != null && mOnBatteryInternal) { |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 8038 | mHasBluetoothEnergyReporting = true; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8039 | mBluetoothActivityCounters[CONTROLLER_RX_TIME].addCountLocked( |
| 8040 | info.getControllerRxTimeMillis()); |
| 8041 | mBluetoothActivityCounters[CONTROLLER_TX_TIME].addCountLocked( |
| 8042 | info.getControllerTxTimeMillis()); |
| 8043 | mBluetoothActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked( |
| 8044 | info.getControllerIdleTimeMillis()); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8045 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8046 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8047 | final double opVolt = mPowerProfile.getAveragePower( |
| 8048 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8049 | if (opVolt != 0) { |
| 8050 | // We store the power drain as mAms. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8051 | mBluetoothActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8052 | (long) (info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8053 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8054 | } |
| 8055 | } |
| 8056 | |
| 8057 | /** |
| 8058 | * Read and distribute kernel wake lock use across apps. |
| 8059 | */ |
| 8060 | public void updateKernelWakelocksLocked() { |
| 8061 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 8062 | mTmpWakelockStats); |
| 8063 | if (wakelockStats == null) { |
| 8064 | // Not crashing might make board bringup easier. |
| 8065 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 8066 | return; |
| 8067 | } |
| 8068 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8069 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 8070 | boolean seenNonZeroTime = false; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8071 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 8072 | String name = ent.getKey(); |
| 8073 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 8074 | |
| 8075 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 8076 | if (kwlt == null) { |
| 8077 | kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, |
| 8078 | true /* track reported val */); |
| 8079 | mKernelWakelockStats.put(name, kwlt); |
| 8080 | } |
| 8081 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 8082 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 8083 | kwlt.setUpdateVersion(kws.mVersion); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8084 | |
| 8085 | if (kws.mVersion != wakelockStats.kernelWakelockVersion) |
| 8086 | seenNonZeroTime |= kws.mTotalTime > 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8087 | } |
| 8088 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8089 | int numWakelocksSetStale = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8090 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 8091 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 8092 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 8093 | SamplingTimer st = ent.getValue(); |
| 8094 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 8095 | st.setStale(); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8096 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8097 | } |
| 8098 | } |
| 8099 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8100 | |
| 8101 | if (!seenNonZeroTime) { |
| 8102 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 8103 | } |
| 8104 | |
| 8105 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 8106 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 8107 | wakelockStats.kernelWakelockVersion); |
| 8108 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8109 | } |
| 8110 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8111 | // We use an anonymous class to access these variables, |
| 8112 | // so they can't live on the stack or they'd have to be |
| 8113 | // final MutableLong objects (more allocations). |
| 8114 | // Used in updateCpuTimeLocked(). |
| 8115 | long mTempTotalCpuUserTimeUs; |
| 8116 | long mTempTotalCpuSystemTimeUs; |
| 8117 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8118 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8119 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 8120 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 8121 | * 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] | 8122 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8123 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8124 | if (mPowerProfile == null) { |
| 8125 | return; |
| 8126 | } |
| 8127 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8128 | if (DEBUG_ENERGY_CPU) { |
| 8129 | Slog.d(TAG, "!Cpu updating!"); |
| 8130 | } |
| 8131 | |
| 8132 | // Holding a wakelock costs more than just using the cpu. |
| 8133 | // Currently, we assign only half the cpu time to an app that is running but |
| 8134 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 8135 | // If no app is holding a wakelock, then the distribution is normal. |
| 8136 | final int wakelockWeight = 50; |
| 8137 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8138 | // Read the time spent for each cluster at various cpu frequencies. |
| 8139 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 8140 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 8141 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 8142 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8143 | |
| 8144 | int numWakelocks = 0; |
| 8145 | |
| 8146 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 8147 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 8148 | final int numPartialTimers = mPartialTimers.size(); |
| 8149 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 8150 | for (int i = 0; i < numPartialTimers; i++) { |
| 8151 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8152 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8153 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 8154 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 8155 | // the newly added timer for past cpu time, so we only consider timers that |
| 8156 | // were present for one round of collection. Once a timer has gone through |
| 8157 | // a round of collection, its mInList field is set to true. |
| 8158 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8159 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8160 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8161 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8162 | |
| 8163 | final int numWakelocksF = numWakelocks; |
| 8164 | mTempTotalCpuUserTimeUs = 0; |
| 8165 | mTempTotalCpuSystemTimeUs = 0; |
| 8166 | |
| 8167 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 8168 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 8169 | // we just ignore the data. |
| 8170 | final long startTimeMs = SystemClock.elapsedRealtime(); |
| 8171 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 8172 | new KernelUidCpuTimeReader.Callback() { |
| 8173 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8174 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs, |
| 8175 | long powerMaUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8176 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 8177 | |
| 8178 | // Accumulate the total system and user time. |
| 8179 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 8180 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 8181 | |
| 8182 | StringBuilder sb = null; |
| 8183 | if (DEBUG_ENERGY_CPU) { |
| 8184 | sb = new StringBuilder(); |
| 8185 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 8186 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8187 | sb.append(" s="); |
| 8188 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8189 | sb.append(" p=").append(powerMaUs / 1000).append("mAms\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8190 | } |
| 8191 | |
| 8192 | if (numWakelocksF > 0) { |
| 8193 | // We have wakelocks being held, so only give a portion of the |
| 8194 | // time to the process. The rest will be distributed among wakelock |
| 8195 | // holders. |
| 8196 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 8197 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 8198 | } |
| 8199 | |
| 8200 | if (sb != null) { |
| 8201 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 8202 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8203 | sb.append(" s="); |
| 8204 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8205 | sb.append(" p=").append(powerMaUs / 1000).append("mAms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8206 | Slog.d(TAG, sb.toString()); |
| 8207 | } |
| 8208 | |
| 8209 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 8210 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8211 | u.mCpuPower.addCountLocked(powerMaUs); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8212 | |
| 8213 | // Add the cpu speeds to this UID. These are used as a ratio |
| 8214 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8215 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8216 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 8217 | numClusters) { |
| 8218 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8219 | } |
| 8220 | |
| 8221 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8222 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 8223 | cluster); |
| 8224 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 8225 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8226 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8227 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8228 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8229 | |
| 8230 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 8231 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 8232 | if (cpuSpeeds[speed] == null) { |
| 8233 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8234 | } |
| 8235 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 8236 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8237 | } |
| 8238 | } |
| 8239 | }); |
| 8240 | |
| 8241 | if (DEBUG_ENERGY_CPU) { |
| 8242 | Slog.d(TAG, "Reading cpu stats took " + (SystemClock.elapsedRealtime() - startTimeMs) + |
| 8243 | " ms"); |
| 8244 | } |
| 8245 | |
| 8246 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 8247 | // Distribute a portion of the total cpu time to wakelock holders. |
| 8248 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 8249 | mTempTotalCpuSystemTimeUs = |
| 8250 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 8251 | |
| 8252 | for (int i = 0; i < numPartialTimers; i++) { |
| 8253 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8254 | |
| 8255 | // The system does not share any blame, as it is usually holding the wakelock |
| 8256 | // on behalf of an app. |
| 8257 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8258 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 8259 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 8260 | |
| 8261 | if (DEBUG_ENERGY_CPU) { |
| 8262 | StringBuilder sb = new StringBuilder(); |
| 8263 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 8264 | .append(": u="); |
| 8265 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8266 | sb.append(" s="); |
| 8267 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 8268 | Slog.d(TAG, sb.toString()); |
| 8269 | } |
| 8270 | |
| 8271 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 8272 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 8273 | |
| 8274 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 8275 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8276 | |
| 8277 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 8278 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 8279 | numWakelocks--; |
| 8280 | } |
| 8281 | } |
| 8282 | |
| 8283 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 8284 | // Anything left over is given to the system. |
| 8285 | if (DEBUG_ENERGY_CPU) { |
| 8286 | StringBuilder sb = new StringBuilder(); |
| 8287 | sb.append(" Distributing lost time to system: u="); |
| 8288 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 8289 | sb.append(" s="); |
| 8290 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 8291 | Slog.d(TAG, sb.toString()); |
| 8292 | } |
| 8293 | |
| 8294 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 8295 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 8296 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 8297 | |
| 8298 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 8299 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 8300 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8301 | } |
| 8302 | } |
| 8303 | |
| 8304 | // See if there is a difference in wakelocks between this collection and the last |
| 8305 | // collection. |
| 8306 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 8307 | // No difference, so each timer is now considered for the next collection. |
| 8308 | for (int i = 0; i < numPartialTimers; i++) { |
| 8309 | mPartialTimers.get(i).mInList = true; |
| 8310 | } |
| 8311 | } else { |
| 8312 | // The lists are different, meaning we added (or removed a timer) since the last |
| 8313 | // collection. |
| 8314 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 8315 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 8316 | mLastPartialTimers.get(i).mInList = false; |
| 8317 | } |
| 8318 | mLastPartialTimers.clear(); |
| 8319 | |
| 8320 | // Mark the current timers as gone through a collection. |
| 8321 | for (int i = 0; i < numPartialTimers; i++) { |
| 8322 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8323 | timer.mInList = true; |
| 8324 | mLastPartialTimers.add(timer); |
| 8325 | } |
| 8326 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8327 | } |
| 8328 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8329 | boolean setChargingLocked(boolean charging) { |
| 8330 | if (mCharging != charging) { |
| 8331 | mCharging = charging; |
| 8332 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8333 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8334 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8335 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8336 | } |
| 8337 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 8338 | return true; |
| 8339 | } |
| 8340 | return false; |
| 8341 | } |
| 8342 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8343 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 8344 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8345 | boolean doWrite = false; |
| 8346 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 8347 | m.arg1 = onBattery ? 1 : 0; |
| 8348 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8349 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8350 | final long uptime = mSecUptime * 1000; |
| 8351 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8352 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8353 | if (onBattery) { |
| 8354 | // We will reset our status if we are unplugging after the |
| 8355 | // battery was last full, or the level is at 100, or |
| 8356 | // we have gone through a significant charge (from a very low |
| 8357 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8358 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 8359 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8360 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 8361 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 8362 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 8363 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 8364 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 8365 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 8366 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 8367 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8368 | // Before we write, collect a snapshot of the final aggregated |
| 8369 | // stats to be reported in the next checkin. Only do this if we have |
| 8370 | // a sufficient amount of data to make it interesting. |
| 8371 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 8372 | final Parcel parcel = Parcel.obtain(); |
| 8373 | writeSummaryToParcel(parcel, true); |
| 8374 | BackgroundThread.getHandler().post(new Runnable() { |
| 8375 | @Override public void run() { |
| 8376 | synchronized (mCheckinFile) { |
| 8377 | FileOutputStream stream = null; |
| 8378 | try { |
| 8379 | stream = mCheckinFile.startWrite(); |
| 8380 | stream.write(parcel.marshall()); |
| 8381 | stream.flush(); |
| 8382 | FileUtils.sync(stream); |
| 8383 | stream.close(); |
| 8384 | mCheckinFile.finishWrite(stream); |
| 8385 | } catch (IOException e) { |
| 8386 | Slog.w("BatteryStats", |
| 8387 | "Error writing checkin battery statistics", e); |
| 8388 | mCheckinFile.failWrite(stream); |
| 8389 | } finally { |
| 8390 | parcel.recycle(); |
| 8391 | } |
| 8392 | } |
| 8393 | } |
| 8394 | }); |
| 8395 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8396 | doWrite = true; |
| 8397 | resetAllStatsLocked(); |
| 8398 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8399 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8400 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8401 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8402 | if (mCharging) { |
| 8403 | setChargingLocked(false); |
| 8404 | } |
| 8405 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8406 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8407 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8408 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8409 | mDischargeStepTracker.clearTime(); |
| 8410 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8411 | mInitStepMode = mCurStepMode; |
| 8412 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8413 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8414 | mHistoryCur.batteryLevel = (byte)level; |
| 8415 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 8416 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 8417 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8418 | if (reset) { |
| 8419 | mRecordingHistory = true; |
| 8420 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 8421 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8422 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8423 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8424 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8425 | mDischargeScreenOnUnplugLevel = level; |
| 8426 | mDischargeScreenOffUnplugLevel = 0; |
| 8427 | } else { |
| 8428 | mDischargeScreenOnUnplugLevel = 0; |
| 8429 | mDischargeScreenOffUnplugLevel = level; |
| 8430 | } |
| 8431 | mDischargeAmountScreenOn = 0; |
| 8432 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8433 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8434 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8435 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8436 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8437 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8438 | mHistoryCur.batteryLevel = (byte)level; |
| 8439 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 8440 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 8441 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8442 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8443 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8444 | if (level < mDischargeUnplugLevel) { |
| 8445 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 8446 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 8447 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8448 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 8449 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8450 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8451 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 8452 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8453 | mInitStepMode = mCurStepMode; |
| 8454 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8455 | } |
| 8456 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 8457 | if (mFile != null) { |
| 8458 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8459 | } |
| 8460 | } |
| 8461 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8462 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8463 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 8464 | boolean reset) { |
| 8465 | mRecordingHistory = true; |
| 8466 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8467 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 8468 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8469 | mHistoryCur); |
| 8470 | mHistoryCur.currentTime = 0; |
| 8471 | if (reset) { |
| 8472 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 8473 | } |
| 8474 | } |
| 8475 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 8476 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 8477 | final long uptimeMs) { |
| 8478 | if (mRecordingHistory) { |
| 8479 | mHistoryCur.currentTime = currentTime; |
| 8480 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 8481 | mHistoryCur); |
| 8482 | mHistoryCur.currentTime = 0; |
| 8483 | } |
| 8484 | } |
| 8485 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8486 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 8487 | if (mRecordingHistory) { |
| 8488 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8489 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 8490 | mHistoryCur); |
| 8491 | mHistoryCur.currentTime = 0; |
| 8492 | } |
| 8493 | } |
| 8494 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8495 | private void scheduleSyncExternalStatsLocked(String reason) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8496 | if (mExternalSync != null) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8497 | mExternalSync.scheduleSync(reason); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8498 | } |
| 8499 | } |
| 8500 | |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8501 | private void scheduleSyncExternalWifiStatsLocked(String reason) { |
| 8502 | if (mExternalSync != null) { |
| 8503 | mExternalSync.scheduleWifiSync(reason); |
| 8504 | } |
| 8505 | } |
| 8506 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8507 | // 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] | 8508 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8509 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8510 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8511 | int temp, int volt) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8512 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
| 8513 | final long uptime = SystemClock.uptimeMillis(); |
| 8514 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 8515 | if (!mHaveBatteryLevel) { |
| 8516 | mHaveBatteryLevel = true; |
| 8517 | // We start out assuming that the device is plugged in (not |
| 8518 | // on battery). If our first report is now that we are indeed |
| 8519 | // plugged in, then twiddle our state to correctly reflect that |
| 8520 | // since we won't be going through the full setOnBattery(). |
| 8521 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8522 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8523 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8524 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8525 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8526 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8527 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8528 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8529 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8530 | mHistoryCur.batteryStatus = (byte)status; |
| 8531 | mHistoryCur.batteryLevel = (byte)level; |
| 8532 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 8533 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8534 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8535 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 8536 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 8537 | } |
| 8538 | int oldStatus = mHistoryCur.batteryStatus; |
| 8539 | if (onBattery) { |
| 8540 | mDischargeCurrentLevel = level; |
| 8541 | if (!mRecordingHistory) { |
| 8542 | mRecordingHistory = true; |
| 8543 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 8544 | } |
| 8545 | } else if (level < 96) { |
| 8546 | if (!mRecordingHistory) { |
| 8547 | mRecordingHistory = true; |
| 8548 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8549 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8550 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8551 | mCurrentBatteryLevel = level; |
| 8552 | if (mDischargePlugLevel < 0) { |
| 8553 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8554 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8555 | if (onBattery != mOnBattery) { |
| 8556 | mHistoryCur.batteryLevel = (byte)level; |
| 8557 | mHistoryCur.batteryStatus = (byte)status; |
| 8558 | mHistoryCur.batteryHealth = (byte)health; |
| 8559 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8560 | mHistoryCur.batteryTemperature = (short)temp; |
| 8561 | mHistoryCur.batteryVoltage = (char)volt; |
| 8562 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 8563 | } else { |
| 8564 | boolean changed = false; |
| 8565 | if (mHistoryCur.batteryLevel != level) { |
| 8566 | mHistoryCur.batteryLevel = (byte)level; |
| 8567 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 8568 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8569 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 8570 | // which will pull external stats. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8571 | scheduleSyncExternalStatsLocked("battery-level"); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8572 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8573 | if (mHistoryCur.batteryStatus != status) { |
| 8574 | mHistoryCur.batteryStatus = (byte)status; |
| 8575 | changed = true; |
| 8576 | } |
| 8577 | if (mHistoryCur.batteryHealth != health) { |
| 8578 | mHistoryCur.batteryHealth = (byte)health; |
| 8579 | changed = true; |
| 8580 | } |
| 8581 | if (mHistoryCur.batteryPlugType != plugType) { |
| 8582 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 8583 | changed = true; |
| 8584 | } |
| 8585 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 8586 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 8587 | mHistoryCur.batteryTemperature = (short)temp; |
| 8588 | changed = true; |
| 8589 | } |
| 8590 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 8591 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 8592 | mHistoryCur.batteryVoltage = (char)volt; |
| 8593 | changed = true; |
| 8594 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8595 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 8596 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 8597 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 8598 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8599 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8600 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 8601 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8602 | modeBits, elapsedRealtime); |
| 8603 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 8604 | modeBits, elapsedRealtime); |
| 8605 | mLastDischargeStepLevel = level; |
| 8606 | mMinDischargeStepLevel = level; |
| 8607 | mInitStepMode = mCurStepMode; |
| 8608 | mModStepMode = 0; |
| 8609 | } |
| 8610 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8611 | if (level >= 90) { |
| 8612 | // If the battery level is at least 90%, always consider the device to be |
| 8613 | // charging even if it happens to go down a level. |
| 8614 | changed |= setChargingLocked(true); |
| 8615 | mLastChargeStepLevel = level; |
| 8616 | } if (!mCharging) { |
| 8617 | if (mLastChargeStepLevel < level) { |
| 8618 | // We have not reporting that we are charging, but the level has now |
| 8619 | // gone up, so consider the state to be charging. |
| 8620 | changed |= setChargingLocked(true); |
| 8621 | mLastChargeStepLevel = level; |
| 8622 | } |
| 8623 | } else { |
| 8624 | if (mLastChargeStepLevel > level) { |
| 8625 | // We had reported that the device was charging, but here we are with |
| 8626 | // power connected and the level going down. Looks like the current |
| 8627 | // power supplied isn't enough, so consider the device to now be |
| 8628 | // discharging. |
| 8629 | changed |= setChargingLocked(false); |
| 8630 | mLastChargeStepLevel = level; |
| 8631 | } |
| 8632 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8633 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 8634 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8635 | modeBits, elapsedRealtime); |
| 8636 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 8637 | modeBits, elapsedRealtime); |
| 8638 | mLastChargeStepLevel = level; |
| 8639 | mMaxChargeStepLevel = level; |
| 8640 | mInitStepMode = mCurStepMode; |
| 8641 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8642 | } |
| 8643 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8644 | if (changed) { |
| 8645 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 8646 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8647 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8648 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 8649 | // We don't record history while we are plugged in and fully charged. |
| 8650 | // The next time we are unplugged, history will be cleared. |
| 8651 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 8652 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 8653 | } |
| 8654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8655 | public long getAwakeTimeBattery() { |
| 8656 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 8657 | } |
| 8658 | |
| 8659 | public long getAwakeTimePlugged() { |
| 8660 | return (SystemClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
| 8661 | } |
| 8662 | |
| 8663 | @Override |
| 8664 | public long computeUptime(long curTime, int which) { |
| 8665 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8666 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8667 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8668 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8669 | } |
| 8670 | return 0; |
| 8671 | } |
| 8672 | |
| 8673 | @Override |
| 8674 | public long computeRealtime(long curTime, int which) { |
| 8675 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8676 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8677 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8678 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | } |
| 8680 | return 0; |
| 8681 | } |
| 8682 | |
| 8683 | @Override |
| 8684 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8685 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | } |
| 8687 | |
| 8688 | @Override |
| 8689 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8690 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8691 | } |
| 8692 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8693 | @Override |
| 8694 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 8695 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 8696 | } |
| 8697 | |
| 8698 | @Override |
| 8699 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 8700 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8701 | } |
| 8702 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8703 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 8704 | // For now we'll do a simple average across all steps. |
| 8705 | if (numSteps <= 0) { |
| 8706 | return -1; |
| 8707 | } |
| 8708 | long total = 0; |
| 8709 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8710 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8711 | } |
| 8712 | return total / numSteps; |
| 8713 | /* |
| 8714 | long[] buckets = new long[numSteps]; |
| 8715 | int numBuckets = 0; |
| 8716 | int numToAverage = 4; |
| 8717 | int i = 0; |
| 8718 | while (i < numSteps) { |
| 8719 | long totalTime = 0; |
| 8720 | int num = 0; |
| 8721 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8722 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8723 | num++; |
| 8724 | } |
| 8725 | buckets[numBuckets] = totalTime / num; |
| 8726 | numBuckets++; |
| 8727 | numToAverage *= 2; |
| 8728 | i += num; |
| 8729 | } |
| 8730 | if (numBuckets < 1) { |
| 8731 | return -1; |
| 8732 | } |
| 8733 | long averageTime = buckets[numBuckets-1]; |
| 8734 | for (i=numBuckets-2; i>=0; i--) { |
| 8735 | averageTime = (averageTime + buckets[i]) / 2; |
| 8736 | } |
| 8737 | return averageTime; |
| 8738 | */ |
| 8739 | } |
| 8740 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8741 | @Override |
| 8742 | public long computeBatteryTimeRemaining(long curTime) { |
| 8743 | if (!mOnBattery) { |
| 8744 | return -1; |
| 8745 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8746 | /* Simple implementation just looks at the average discharge per level across the |
| 8747 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8748 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 8749 | if (discharge < 2) { |
| 8750 | return -1; |
| 8751 | } |
| 8752 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 8753 | if (duration < 1000*1000) { |
| 8754 | return -1; |
| 8755 | } |
| 8756 | long usPerLevel = duration/discharge; |
| 8757 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8758 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8759 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8760 | return -1; |
| 8761 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8762 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8763 | if (msPerLevel <= 0) { |
| 8764 | return -1; |
| 8765 | } |
| 8766 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8767 | } |
| 8768 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8769 | @Override |
| 8770 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 8771 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8772 | } |
| 8773 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8774 | @Override |
| 8775 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 8776 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8777 | } |
| 8778 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8779 | @Override |
| 8780 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8781 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8782 | // Not yet working. |
| 8783 | return -1; |
| 8784 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8785 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8786 | int curLevel = mCurrentBatteryLevel; |
| 8787 | int plugLevel = mDischargePlugLevel; |
| 8788 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 8789 | return -1; |
| 8790 | } |
| 8791 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 8792 | if (duration < 1000*1000) { |
| 8793 | return -1; |
| 8794 | } |
| 8795 | long usPerLevel = duration/(curLevel-plugLevel); |
| 8796 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8797 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8798 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8799 | return -1; |
| 8800 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8801 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 8802 | if (msPerLevel <= 0) { |
| 8803 | return -1; |
| 8804 | } |
| 8805 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8806 | } |
| 8807 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8808 | @Override |
| 8809 | public LevelStepTracker getChargeLevelStepTracker() { |
| 8810 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8811 | } |
| 8812 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8813 | @Override |
| 8814 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 8815 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 8816 | } |
| 8817 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8818 | @Override |
| 8819 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 8820 | return mDailyPackageChanges; |
| 8821 | } |
| 8822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8823 | long getBatteryUptimeLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8824 | return mOnBatteryTimeBase.getUptime(SystemClock.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8825 | } |
| 8826 | |
| 8827 | @Override |
| 8828 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8829 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8830 | } |
| 8831 | |
| 8832 | @Override |
| 8833 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8834 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8835 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 8836 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8837 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8838 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8839 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8840 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8841 | } |
| 8842 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8843 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8844 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8845 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8846 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8847 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8848 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8849 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8850 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8851 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8852 | } |
| 8853 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8854 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8855 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8856 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8857 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8858 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8859 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8860 | public int getLowDischargeAmountSinceCharge() { |
| 8861 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8862 | int val = mLowDischargeAmountSinceCharge; |
| 8863 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8864 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 8865 | } |
| 8866 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8867 | } |
| 8868 | } |
| 8869 | |
| 8870 | @Override |
| 8871 | public int getHighDischargeAmountSinceCharge() { |
| 8872 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 8873 | int val = mHighDischargeAmountSinceCharge; |
| 8874 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 8875 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 8876 | } |
| 8877 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8878 | } |
| 8879 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8880 | |
| 8881 | @Override |
| 8882 | public int getDischargeAmount(int which) { |
| 8883 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 8884 | ? getHighDischargeAmountSinceCharge() |
| 8885 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 8886 | if (dischargeAmount < 0) { |
| 8887 | dischargeAmount = 0; |
| 8888 | } |
| 8889 | return dischargeAmount; |
| 8890 | } |
| 8891 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8892 | public int getDischargeAmountScreenOn() { |
| 8893 | synchronized(this) { |
| 8894 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8895 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8896 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8897 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8898 | } |
| 8899 | return val; |
| 8900 | } |
| 8901 | } |
| 8902 | |
| 8903 | public int getDischargeAmountScreenOnSinceCharge() { |
| 8904 | synchronized(this) { |
| 8905 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8906 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8907 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 8908 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 8909 | } |
| 8910 | return val; |
| 8911 | } |
| 8912 | } |
| 8913 | |
| 8914 | public int getDischargeAmountScreenOff() { |
| 8915 | synchronized(this) { |
| 8916 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8917 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8918 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8919 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8920 | } |
| 8921 | return val; |
| 8922 | } |
| 8923 | } |
| 8924 | |
| 8925 | public int getDischargeAmountScreenOffSinceCharge() { |
| 8926 | synchronized(this) { |
| 8927 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8928 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8929 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 8930 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 8931 | } |
| 8932 | return val; |
| 8933 | } |
| 8934 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8936 | /** |
| 8937 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 8938 | */ |
| 8939 | public Uid getUidStatsLocked(int uid) { |
| 8940 | Uid u = mUidStats.get(uid); |
| 8941 | if (u == null) { |
| 8942 | u = new Uid(uid); |
| 8943 | mUidStats.put(uid, u); |
| 8944 | } |
| 8945 | return u; |
| 8946 | } |
| 8947 | |
| 8948 | /** |
| 8949 | * Remove the statistics object for a particular uid. |
| 8950 | */ |
| 8951 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 8952 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8953 | mUidStats.remove(uid); |
| 8954 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 8955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8956 | /** |
| 8957 | * Retrieve the statistics object for a particular process, creating |
| 8958 | * if needed. |
| 8959 | */ |
| 8960 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8961 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8962 | Uid u = getUidStatsLocked(uid); |
| 8963 | return u.getProcessStatsLocked(name); |
| 8964 | } |
| 8965 | |
| 8966 | /** |
| 8967 | * Retrieve the statistics object for a particular process, creating |
| 8968 | * if needed. |
| 8969 | */ |
| 8970 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8971 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8972 | Uid u = getUidStatsLocked(uid); |
| 8973 | return u.getPackageStatsLocked(pkg); |
| 8974 | } |
| 8975 | |
| 8976 | /** |
| 8977 | * Retrieve the statistics object for a particular service, creating |
| 8978 | * if needed. |
| 8979 | */ |
| 8980 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 8981 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8982 | Uid u = getUidStatsLocked(uid); |
| 8983 | return u.getServiceStatsLocked(pkg, name); |
| 8984 | } |
| 8985 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8986 | public void shutdownLocked() { |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 8987 | recordShutdownLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8988 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8989 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8990 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8991 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8992 | Parcel mPendingWrite = null; |
| 8993 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 8994 | |
| 8995 | public void writeAsyncLocked() { |
| 8996 | writeLocked(false); |
| 8997 | } |
| 8998 | |
| 8999 | public void writeSyncLocked() { |
| 9000 | writeLocked(true); |
| 9001 | } |
| 9002 | |
| 9003 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9004 | if (mFile == null) { |
| 9005 | 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] | 9006 | return; |
| 9007 | } |
| 9008 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9009 | if (mShuttingDown) { |
| 9010 | return; |
| 9011 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9012 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9013 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9014 | writeSummaryToParcel(out, true); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9015 | mLastWriteTime = SystemClock.elapsedRealtime(); |
| 9016 | |
| 9017 | if (mPendingWrite != null) { |
| 9018 | mPendingWrite.recycle(); |
| 9019 | } |
| 9020 | mPendingWrite = out; |
| 9021 | |
| 9022 | if (sync) { |
| 9023 | commitPendingDataToDisk(); |
| 9024 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9025 | BackgroundThread.getHandler().post(new Runnable() { |
| 9026 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9027 | commitPendingDataToDisk(); |
| 9028 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9029 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9030 | } |
| 9031 | } |
| 9032 | |
| 9033 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9034 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9035 | synchronized (this) { |
| 9036 | next = mPendingWrite; |
| 9037 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9038 | if (next == null) { |
| 9039 | return; |
| 9040 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9041 | |
| 9042 | mWriteLock.lock(); |
| 9043 | } |
| 9044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9045 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9046 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9047 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9048 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 9049 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9050 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9051 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9052 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9053 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9054 | mFile.rollback(); |
| 9055 | } finally { |
| 9056 | next.recycle(); |
| 9057 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 9058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | } |
| 9060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9061 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9062 | if (mDailyFile != null) { |
| 9063 | readDailyStatsLocked(); |
| 9064 | } |
| 9065 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9066 | if (mFile == null) { |
| 9067 | 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] | 9068 | return; |
| 9069 | } |
| 9070 | |
| 9071 | mUidStats.clear(); |
| 9072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9073 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9074 | File file = mFile.chooseForRead(); |
| 9075 | if (!file.exists()) { |
| 9076 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9077 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9078 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9079 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9080 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9081 | Parcel in = Parcel.obtain(); |
| 9082 | in.unmarshall(raw, 0, raw.length); |
| 9083 | in.setDataPosition(0); |
| 9084 | stream.close(); |
| 9085 | |
| 9086 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 9087 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9088 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9089 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9090 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9091 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9092 | mEndPlatformVersion = Build.ID; |
| 9093 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9094 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9095 | mRecordingHistory = true; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9096 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 9097 | final long uptime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9098 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9099 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9100 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9101 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 9102 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9103 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9104 | |
| 9105 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9106 | } |
| 9107 | |
| 9108 | public int describeContents() { |
| 9109 | return 0; |
| 9110 | } |
| 9111 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9112 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9113 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9114 | |
| 9115 | mHistoryBuffer.setDataSize(0); |
| 9116 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9117 | mHistoryTagPool.clear(); |
| 9118 | mNextHistoryTagIdx = 0; |
| 9119 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9120 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9121 | int numTags = in.readInt(); |
| 9122 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9123 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9124 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9125 | if (str == null) { |
| 9126 | throw new ParcelFormatException("null history tag string"); |
| 9127 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9128 | int uid = in.readInt(); |
| 9129 | HistoryTag tag = new HistoryTag(); |
| 9130 | tag.string = str; |
| 9131 | tag.uid = uid; |
| 9132 | tag.poolIdx = idx; |
| 9133 | mHistoryTagPool.put(tag, idx); |
| 9134 | if (idx >= mNextHistoryTagIdx) { |
| 9135 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9136 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9137 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9138 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9139 | |
| 9140 | int bufSize = in.readInt(); |
| 9141 | int curPos = in.dataPosition(); |
| 9142 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9143 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 9144 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9145 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9146 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 9147 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9148 | } else { |
| 9149 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 9150 | + " bytes at " + curPos); |
| 9151 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 9152 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9153 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9154 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9155 | if (andOldHistory) { |
| 9156 | readOldHistory(in); |
| 9157 | } |
| 9158 | |
| 9159 | if (DEBUG_HISTORY) { |
| 9160 | StringBuilder sb = new StringBuilder(128); |
| 9161 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 9162 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9163 | Slog.i(TAG, sb.toString()); |
| 9164 | } |
| 9165 | mHistoryBaseTime = historyBaseTime; |
| 9166 | if (DEBUG_HISTORY) { |
| 9167 | StringBuilder sb = new StringBuilder(128); |
| 9168 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 9169 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9170 | Slog.i(TAG, sb.toString()); |
| 9171 | } |
| 9172 | |
| 9173 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 9174 | // the last run until samples in this run. |
| 9175 | if (mHistoryBaseTime > 0) { |
| 9176 | long oldnow = SystemClock.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9177 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9178 | if (DEBUG_HISTORY) { |
| 9179 | StringBuilder sb = new StringBuilder(128); |
| 9180 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 9181 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9182 | Slog.i(TAG, sb.toString()); |
| 9183 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 9184 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9185 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9186 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9187 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9188 | if (!USE_OLD_HISTORY) { |
| 9189 | return; |
| 9190 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9191 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 9192 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 9193 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9194 | HistoryItem rec = new HistoryItem(time, in); |
| 9195 | addHistoryRecordLocked(rec); |
| 9196 | } |
| 9197 | } |
| 9198 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9199 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9200 | if (DEBUG_HISTORY) { |
| 9201 | StringBuilder sb = new StringBuilder(128); |
| 9202 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 9203 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9204 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 9205 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9206 | Slog.i(TAG, sb.toString()); |
| 9207 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9208 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9209 | if (!inclData) { |
| 9210 | out.writeInt(0); |
| 9211 | out.writeInt(0); |
| 9212 | return; |
| 9213 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9214 | out.writeInt(mHistoryTagPool.size()); |
| 9215 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 9216 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9217 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9218 | out.writeString(tag.string); |
| 9219 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9220 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9221 | out.writeInt(mHistoryBuffer.dataSize()); |
| 9222 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 9223 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 9224 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9225 | |
| 9226 | if (andOldHistory) { |
| 9227 | writeOldHistory(out); |
| 9228 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9229 | } |
| 9230 | |
| 9231 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9232 | if (!USE_OLD_HISTORY) { |
| 9233 | return; |
| 9234 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9235 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9236 | while (rec != null) { |
| 9237 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 9238 | rec = rec.next; |
| 9239 | } |
| 9240 | out.writeLong(-1); |
| 9241 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9242 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9243 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9244 | final int version = in.readInt(); |
| 9245 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9246 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | + ", expected " + VERSION + "; erasing old stats"); |
| 9248 | return; |
| 9249 | } |
| 9250 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9251 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9254 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9255 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9256 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9257 | mStartPlatformVersion = in.readString(); |
| 9258 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9259 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 9260 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9261 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9262 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9263 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9264 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9265 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9266 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9267 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9268 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9269 | mDischargeStepTracker.readFromParcel(in); |
| 9270 | mChargeStepTracker.readFromParcel(in); |
| 9271 | mDailyDischargeStepTracker.readFromParcel(in); |
| 9272 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9273 | int NPKG = in.readInt(); |
| 9274 | if (NPKG > 0) { |
| 9275 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 9276 | while (NPKG > 0) { |
| 9277 | NPKG--; |
| 9278 | PackageChange pc = new PackageChange(); |
| 9279 | pc.mPackageName = in.readString(); |
| 9280 | pc.mUpdate = in.readInt() != 0; |
| 9281 | pc.mVersionCode = in.readInt(); |
| 9282 | mDailyPackageChanges.add(pc); |
| 9283 | } |
| 9284 | } else { |
| 9285 | mDailyPackageChanges = null; |
| 9286 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9287 | mDailyStartTime = in.readLong(); |
| 9288 | mNextMinDailyDeadline = in.readLong(); |
| 9289 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9291 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9292 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9293 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9294 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9295 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9296 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 9297 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9298 | mInteractive = false; |
| 9299 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9300 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9301 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 9302 | mLongestLightIdleTime = in.readLong(); |
| 9303 | mLongestFullIdleTime = in.readLong(); |
| 9304 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 9305 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 9306 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9307 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9308 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9309 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9310 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9311 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 9312 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9313 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9314 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 9315 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9316 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9317 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9318 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9319 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9320 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9321 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9322 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9323 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9324 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 9325 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9326 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9327 | mWifiOn = false; |
| 9328 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9329 | mGlobalWifiRunning = false; |
| 9330 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9331 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9332 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 9333 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9334 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9335 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 9336 | } |
| 9337 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9338 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9339 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9340 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9341 | mBluetoothActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9342 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9343 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9344 | mWifiActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9345 | } |
| 9346 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9347 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9348 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9349 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9350 | mCameraOnNesting = 0; |
| 9351 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9353 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9354 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9355 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9356 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9357 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 9358 | if (in.readInt() != 0) { |
| 9359 | String kwltName = in.readString(); |
| 9360 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 9361 | } |
| 9362 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9363 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9364 | int NWR = in.readInt(); |
| 9365 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9366 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9367 | } |
| 9368 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 9369 | if (in.readInt() != 0) { |
| 9370 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9371 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9372 | } |
| 9373 | } |
| 9374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9375 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9376 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9377 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9379 | for (int iu = 0; iu < NU; iu++) { |
| 9380 | int uid = in.readInt(); |
| 9381 | Uid u = new Uid(uid); |
| 9382 | mUidStats.put(uid, u); |
| 9383 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9384 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9385 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9386 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9387 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9388 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9389 | if (in.readInt() != 0) { |
| 9390 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 9391 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9392 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9393 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9394 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9395 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9396 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 9397 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9398 | if (in.readInt() != 0) { |
| 9399 | u.makeWifiBatchedScanBin(i, null); |
| 9400 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 9401 | } |
| 9402 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9403 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9404 | if (in.readInt() != 0) { |
| 9405 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 9406 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9407 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9408 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9409 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9410 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9411 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9412 | } |
| 9413 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9414 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9415 | } |
| 9416 | if (in.readInt() != 0) { |
| 9417 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 9418 | } |
| 9419 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9420 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 9421 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9422 | u.mProcessState = Uid.PROCESS_STATE_NONE; |
| 9423 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9424 | if (in.readInt() != 0) { |
| 9425 | u.makeProcessState(i, null); |
| 9426 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 9427 | } |
| 9428 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9429 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9430 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9431 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 9432 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9433 | if (in.readInt() != 0) { |
| 9434 | if (u.mUserActivityCounters == null) { |
| 9435 | u.initUserActivityLocked(); |
| 9436 | } |
| 9437 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9438 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9439 | } |
| 9440 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9441 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9442 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9443 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9444 | u.initNetworkActivityLocked(); |
| 9445 | } |
| 9446 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9447 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9448 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9449 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9450 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 9451 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9452 | } |
| 9453 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9454 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 9455 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9456 | u.mCpuPower.readSummaryFromParcelLocked(in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9457 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9458 | if (in.readInt() != 0) { |
| 9459 | final int numClusters = in.readInt(); |
| 9460 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 9461 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9462 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9463 | |
| 9464 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 9465 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9466 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 9467 | final int NSB = in.readInt(); |
| 9468 | if (mPowerProfile != null && |
| 9469 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 9470 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 9471 | NSB); |
| 9472 | } |
| 9473 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9474 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 9475 | for (int speed = 0; speed < NSB; speed++) { |
| 9476 | if (in.readInt() != 0) { |
| 9477 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 9478 | mOnBatteryTimeBase); |
| 9479 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 9480 | } |
| 9481 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 9482 | } else { |
| 9483 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9484 | } |
| 9485 | } |
| 9486 | } else { |
| 9487 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9488 | } |
| 9489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9490 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9491 | if (NW > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9492 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | for (int iw = 0; iw < NW; iw++) { |
| 9495 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9496 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9497 | } |
| 9498 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9499 | int NS = in.readInt(); |
| 9500 | if (NS > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9501 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9502 | } |
| 9503 | for (int is = 0; is < NS; is++) { |
| 9504 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9505 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9506 | } |
| 9507 | |
| 9508 | int NJ = in.readInt(); |
| 9509 | if (NJ > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9510 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9511 | } |
| 9512 | for (int ij = 0; ij < NJ; ij++) { |
| 9513 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9514 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9515 | } |
| 9516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9517 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9518 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9519 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9520 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9521 | for (int is = 0; is < NP; is++) { |
| 9522 | int seNumber = in.readInt(); |
| 9523 | if (in.readInt() != 0) { |
| 9524 | u.getSensorTimerLocked(seNumber, true) |
| 9525 | .readSummaryFromParcelLocked(in); |
| 9526 | } |
| 9527 | } |
| 9528 | |
| 9529 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9530 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9531 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9532 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9533 | for (int ip = 0; ip < NP; ip++) { |
| 9534 | String procName = in.readString(); |
| 9535 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 9536 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9537 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9538 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9539 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9540 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 9541 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9542 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | } |
| 9544 | |
| 9545 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9546 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9547 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9549 | for (int ip = 0; ip < NP; ip++) { |
| 9550 | String pkgName = in.readString(); |
| 9551 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9552 | final int NWA = in.readInt(); |
| 9553 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9554 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9555 | } |
| 9556 | p.mWakeupAlarms.clear(); |
| 9557 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9558 | String tag = in.readString(); |
| 9559 | Counter c = new Counter(mOnBatteryTimeBase); |
| 9560 | c.readSummaryFromParcelLocked(in); |
| 9561 | p.mWakeupAlarms.put(tag, c); |
| 9562 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9563 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9564 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9565 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9566 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9567 | for (int is = 0; is < NS; is++) { |
| 9568 | String servName = in.readString(); |
| 9569 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 9570 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9571 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9572 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9573 | } |
| 9574 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9575 | } |
| 9576 | } |
| 9577 | |
| 9578 | /** |
| 9579 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 9580 | * disk. This format does not allow a lossless round-trip. |
| 9581 | * |
| 9582 | * @param out the Parcel to be written to. |
| 9583 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9584 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9585 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9586 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9587 | // Pull the clock time. This may update the time and make a new history entry |
| 9588 | // if we had originally pulled a time before the RTC was set. |
| 9589 | long startClockTime = getStartClockTime(); |
| 9590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9591 | final long NOW_SYS = SystemClock.uptimeMillis() * 1000; |
| 9592 | final long NOWREAL_SYS = SystemClock.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9593 | |
| 9594 | out.writeInt(VERSION); |
| 9595 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9596 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9598 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9599 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9600 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9601 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9602 | out.writeString(mStartPlatformVersion); |
| 9603 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9604 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 9605 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9606 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9607 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9608 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9609 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9610 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 9611 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9612 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 9613 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9614 | mDischargeStepTracker.writeToParcel(out); |
| 9615 | mChargeStepTracker.writeToParcel(out); |
| 9616 | mDailyDischargeStepTracker.writeToParcel(out); |
| 9617 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9618 | if (mDailyPackageChanges != null) { |
| 9619 | final int NPKG = mDailyPackageChanges.size(); |
| 9620 | out.writeInt(NPKG); |
| 9621 | for (int i=0; i<NPKG; i++) { |
| 9622 | PackageChange pc = mDailyPackageChanges.get(i); |
| 9623 | out.writeString(pc.mPackageName); |
| 9624 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 9625 | out.writeInt(pc.mVersionCode); |
| 9626 | } |
| 9627 | } else { |
| 9628 | out.writeInt(0); |
| 9629 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9630 | out.writeLong(mDailyStartTime); |
| 9631 | out.writeLong(mNextMinDailyDeadline); |
| 9632 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9633 | |
| 9634 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9635 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9636 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9637 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9638 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9639 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 9640 | out.writeLong(mLongestLightIdleTime); |
| 9641 | out.writeLong(mLongestFullIdleTime); |
| 9642 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9643 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9644 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9645 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9646 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9647 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9648 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9649 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9650 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9651 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9652 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9653 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9654 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9655 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9656 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9657 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9658 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9659 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9660 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9661 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 9662 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9663 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9664 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9665 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9666 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9667 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9668 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9669 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9670 | } |
| 9671 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9672 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9673 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9674 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9675 | mBluetoothActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9676 | } |
| 9677 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 9678 | mWifiActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9679 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9680 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9681 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9682 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9683 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9684 | out.writeInt(mKernelWakelockStats.size()); |
| 9685 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9686 | Timer kwlt = ent.getValue(); |
| 9687 | if (kwlt != null) { |
| 9688 | out.writeInt(1); |
| 9689 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9690 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9691 | } else { |
| 9692 | out.writeInt(0); |
| 9693 | } |
| 9694 | } |
| 9695 | |
| 9696 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9697 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 9698 | SamplingTimer timer = ent.getValue(); |
| 9699 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9700 | out.writeInt(1); |
| 9701 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9702 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9703 | } else { |
| 9704 | out.writeInt(0); |
| 9705 | } |
| 9706 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9708 | final int NU = mUidStats.size(); |
| 9709 | out.writeInt(NU); |
| 9710 | for (int iu = 0; iu < NU; iu++) { |
| 9711 | out.writeInt(mUidStats.keyAt(iu)); |
| 9712 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9713 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9714 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9715 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9716 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9717 | } else { |
| 9718 | out.writeInt(0); |
| 9719 | } |
| 9720 | if (u.mFullWifiLockTimer != null) { |
| 9721 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9722 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9723 | } else { |
| 9724 | out.writeInt(0); |
| 9725 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 9726 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9727 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9728 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9729 | } else { |
| 9730 | out.writeInt(0); |
| 9731 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9732 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 9733 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 9734 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9735 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 9736 | } else { |
| 9737 | out.writeInt(0); |
| 9738 | } |
| 9739 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9740 | if (u.mWifiMulticastTimer != null) { |
| 9741 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9742 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9743 | } else { |
| 9744 | out.writeInt(0); |
| 9745 | } |
| 9746 | if (u.mAudioTurnedOnTimer != null) { |
| 9747 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9748 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9749 | } else { |
| 9750 | out.writeInt(0); |
| 9751 | } |
| 9752 | if (u.mVideoTurnedOnTimer != null) { |
| 9753 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9754 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9755 | } else { |
| 9756 | out.writeInt(0); |
| 9757 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9758 | if (u.mFlashlightTurnedOnTimer != null) { |
| 9759 | out.writeInt(1); |
| 9760 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9761 | } else { |
| 9762 | out.writeInt(0); |
| 9763 | } |
| 9764 | if (u.mCameraTurnedOnTimer != null) { |
| 9765 | out.writeInt(1); |
| 9766 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9767 | } else { |
| 9768 | out.writeInt(0); |
| 9769 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9770 | if (u.mForegroundActivityTimer != null) { |
| 9771 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9772 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9773 | } else { |
| 9774 | out.writeInt(0); |
| 9775 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9776 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 9777 | if (u.mProcessStateTimer[i] != null) { |
| 9778 | out.writeInt(1); |
| 9779 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9780 | } else { |
| 9781 | out.writeInt(0); |
| 9782 | } |
| 9783 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9784 | if (u.mVibratorOnTimer != null) { |
| 9785 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9786 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 9787 | } else { |
| 9788 | out.writeInt(0); |
| 9789 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9790 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9791 | if (u.mUserActivityCounters == null) { |
| 9792 | out.writeInt(0); |
| 9793 | } else { |
| 9794 | out.writeInt(1); |
| 9795 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 9796 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9797 | } |
| 9798 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9799 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9800 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9801 | out.writeInt(0); |
| 9802 | } else { |
| 9803 | out.writeInt(1); |
| 9804 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9805 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 9806 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9807 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9808 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 9809 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9810 | } |
| 9811 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9812 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 9813 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9814 | u.mCpuPower.writeSummaryFromParcelLocked(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9815 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9816 | if (u.mCpuClusterSpeed != null) { |
| 9817 | out.writeInt(1); |
| 9818 | out.writeInt(u.mCpuClusterSpeed.length); |
| 9819 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 9820 | if (cpuSpeeds != null) { |
| 9821 | out.writeInt(1); |
| 9822 | out.writeInt(cpuSpeeds.length); |
| 9823 | for (LongSamplingCounter c : cpuSpeeds) { |
| 9824 | if (c != null) { |
| 9825 | out.writeInt(1); |
| 9826 | c.writeSummaryFromParcelLocked(out); |
| 9827 | } else { |
| 9828 | out.writeInt(0); |
| 9829 | } |
| 9830 | } |
| 9831 | } else { |
| 9832 | out.writeInt(0); |
| 9833 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9834 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9835 | } else { |
| 9836 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9837 | } |
| 9838 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9839 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 9840 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9841 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9842 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9843 | out.writeString(wakeStats.keyAt(iw)); |
| 9844 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9845 | if (wl.mTimerFull != null) { |
| 9846 | out.writeInt(1); |
| 9847 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9848 | } else { |
| 9849 | out.writeInt(0); |
| 9850 | } |
| 9851 | if (wl.mTimerPartial != null) { |
| 9852 | out.writeInt(1); |
| 9853 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9854 | } else { |
| 9855 | out.writeInt(0); |
| 9856 | } |
| 9857 | if (wl.mTimerWindow != null) { |
| 9858 | out.writeInt(1); |
| 9859 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9860 | } else { |
| 9861 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9862 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9863 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9864 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9865 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9866 | } else { |
| 9867 | out.writeInt(0); |
| 9868 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9869 | } |
| 9870 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9871 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 9872 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9873 | out.writeInt(NS); |
| 9874 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9875 | out.writeString(syncStats.keyAt(is)); |
| 9876 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9877 | } |
| 9878 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9879 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 9880 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9881 | out.writeInt(NJ); |
| 9882 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9883 | out.writeString(jobStats.keyAt(ij)); |
| 9884 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9885 | } |
| 9886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9887 | int NSE = u.mSensorStats.size(); |
| 9888 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9889 | for (int ise=0; ise<NSE; ise++) { |
| 9890 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 9891 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 9892 | if (se.mTimer != null) { |
| 9893 | out.writeInt(1); |
| 9894 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 9895 | } else { |
| 9896 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9897 | } |
| 9898 | } |
| 9899 | |
| 9900 | int NP = u.mProcessStats.size(); |
| 9901 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9902 | for (int ip=0; ip<NP; ip++) { |
| 9903 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 9904 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 9905 | out.writeLong(ps.mUserTime); |
| 9906 | out.writeLong(ps.mSystemTime); |
| 9907 | out.writeLong(ps.mForegroundTime); |
| 9908 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9909 | out.writeInt(ps.mNumCrashes); |
| 9910 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9911 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9912 | } |
| 9913 | |
| 9914 | NP = u.mPackageStats.size(); |
| 9915 | out.writeInt(NP); |
| 9916 | if (NP > 0) { |
| 9917 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 9918 | : u.mPackageStats.entrySet()) { |
| 9919 | out.writeString(ent.getKey()); |
| 9920 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9921 | final int NWA = ps.mWakeupAlarms.size(); |
| 9922 | out.writeInt(NWA); |
| 9923 | for (int iwa=0; iwa<NWA; iwa++) { |
| 9924 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 9925 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 9926 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9927 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9928 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9929 | for (int is=0; is<NS; is++) { |
| 9930 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 9931 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 9932 | long time = ss.getStartTimeToNowLocked( |
| 9933 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 9934 | out.writeLong(time); |
| 9935 | out.writeInt(ss.mStarts); |
| 9936 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9937 | } |
| 9938 | } |
| 9939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9940 | } |
| 9941 | } |
| 9942 | |
| 9943 | public void readFromParcel(Parcel in) { |
| 9944 | readFromParcelLocked(in); |
| 9945 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9947 | void readFromParcelLocked(Parcel in) { |
| 9948 | int magic = in.readInt(); |
| 9949 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9950 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9951 | } |
| 9952 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9953 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9955 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9956 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9957 | mStartPlatformVersion = in.readString(); |
| 9958 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9959 | mUptime = in.readLong(); |
| 9960 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9961 | mRealtime = in.readLong(); |
| 9962 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9963 | mOnBattery = in.readInt() != 0; |
| 9964 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9965 | mOnBatteryTimeBase.readFromParcel(in); |
| 9966 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 9967 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9968 | mScreenState = Display.STATE_UNKNOWN; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9969 | mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in); |
| 9970 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9971 | mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase, |
| 9972 | in); |
| 9973 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9974 | mInteractive = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9975 | mInteractiveTimer = new StopwatchTimer(null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9976 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9977 | mPowerSaveModeEnabledTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 9978 | mLongestLightIdleTime = in.readLong(); |
| 9979 | mLongestFullIdleTime = in.readLong(); |
| 9980 | mDeviceIdleModeLightTimer = new StopwatchTimer(null, -14, null, mOnBatteryTimeBase, in); |
| 9981 | mDeviceIdleModeFullTimer = new StopwatchTimer(null, -11, null, mOnBatteryTimeBase, in); |
| 9982 | mDeviceLightIdlingTimer = new StopwatchTimer(null, -15, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9983 | mDeviceIdlingTimer = new StopwatchTimer(null, -12, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 9984 | mPhoneOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9985 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 9986 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, |
| 9987 | null, mOnBatteryTimeBase, in); |
| 9988 | } |
| 9989 | mPhoneSignalScanningTimer = new StopwatchTimer(null, -200+1, null, mOnBatteryTimeBase, in); |
| 9990 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9991 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(null, -300-i, |
| 9992 | null, mOnBatteryTimeBase, in); |
| 9993 | } |
| 9994 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 9995 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9996 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 9997 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9998 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9999 | mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); |
| 10000 | mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, |
| 10001 | in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10002 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10003 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10004 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10005 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10006 | mWifiOn = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 10007 | mWifiOnTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10008 | mGlobalWifiRunning = false; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 10009 | mGlobalWifiRunningTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10010 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10011 | mWifiStateTimer[i] = new StopwatchTimer(null, -600-i, |
| 10012 | null, mOnBatteryTimeBase, in); |
| 10013 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10014 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10015 | mWifiSupplStateTimer[i] = new StopwatchTimer(null, -700-i, |
| 10016 | null, mOnBatteryTimeBase, in); |
| 10017 | } |
| 10018 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10019 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(null, -800-i, |
| 10020 | null, mOnBatteryTimeBase, in); |
| 10021 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10022 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 10023 | mBluetoothActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10024 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10025 | for (int i = 0; i < NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 10026 | mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10027 | } |
| 10028 | |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 10029 | mHasWifiEnergyReporting = in.readInt() != 0; |
| 10030 | mHasBluetoothEnergyReporting = in.readInt() != 0; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10031 | mNumConnectivityChange = in.readInt(); |
| 10032 | mLoadedNumConnectivityChange = in.readInt(); |
| 10033 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10034 | mAudioOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 10035 | mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10036 | mVideoOnNesting = 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 10037 | mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10038 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10039 | mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10040 | mCameraOnNesting = 0; |
| 10041 | mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10042 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10043 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10044 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10045 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10046 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10047 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10048 | mDischargeAmountScreenOn = in.readInt(); |
| 10049 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10050 | mDischargeAmountScreenOff = in.readInt(); |
| 10051 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10052 | mDischargeStepTracker.readFromParcel(in); |
| 10053 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | mLastWriteTime = in.readLong(); |
| 10055 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10056 | mKernelWakelockStats.clear(); |
| 10057 | int NKW = in.readInt(); |
| 10058 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10059 | if (in.readInt() != 0) { |
| 10060 | String wakelockName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10061 | SamplingTimer kwlt = new SamplingTimer(mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10062 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 10063 | } |
| 10064 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10065 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10066 | mWakeupReasonStats.clear(); |
| 10067 | int NWR = in.readInt(); |
| 10068 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10069 | if (in.readInt() != 0) { |
| 10070 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10071 | SamplingTimer timer = new SamplingTimer(mOnBatteryTimeBase, in); |
| 10072 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10073 | } |
| 10074 | } |
| 10075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | mPartialTimers.clear(); |
| 10077 | mFullTimers.clear(); |
| 10078 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10079 | mWifiRunningTimers.clear(); |
| 10080 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10081 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10082 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10083 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10084 | mAudioTurnedOnTimers.clear(); |
| 10085 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10086 | mFlashlightTurnedOnTimers.clear(); |
| 10087 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10088 | |
| 10089 | int numUids = in.readInt(); |
| 10090 | mUidStats.clear(); |
| 10091 | for (int i = 0; i < numUids; i++) { |
| 10092 | int uid = in.readInt(); |
| 10093 | Uid u = new Uid(uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10094 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10095 | mUidStats.append(uid, u); |
| 10096 | } |
| 10097 | } |
| 10098 | |
| 10099 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10100 | writeToParcelLocked(out, true, flags); |
| 10101 | } |
| 10102 | |
| 10103 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 10104 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10105 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10106 | |
| 10107 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10108 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10109 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10110 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10111 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10112 | // Pull the clock time. This may update the time and make a new history entry |
| 10113 | // if we had originally pulled a time before the RTC was set. |
| 10114 | long startClockTime = getStartClockTime(); |
| 10115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10116 | final long uSecUptime = SystemClock.uptimeMillis() * 1000; |
| 10117 | final long uSecRealtime = SystemClock.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10118 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 10119 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10121 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10122 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10123 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10125 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10126 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10127 | out.writeString(mStartPlatformVersion); |
| 10128 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10129 | out.writeLong(mUptime); |
| 10130 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | out.writeLong(mRealtime); |
| 10132 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10133 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10134 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10135 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10136 | |
| 10137 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 10138 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10139 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 10140 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10141 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10142 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 10143 | out.writeLong(mLongestLightIdleTime); |
| 10144 | out.writeLong(mLongestFullIdleTime); |
| 10145 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 10146 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 10147 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10148 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10149 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 10150 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10151 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10152 | } |
| 10153 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 10154 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10155 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 10156 | } |
| 10157 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10158 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 10159 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 10160 | } |
| 10161 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 10162 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10163 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10164 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 10165 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 10166 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 10167 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 10168 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10169 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 10170 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10171 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10172 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 10173 | } |
| 10174 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10175 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10176 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10177 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 10178 | mBluetoothActivityCounters[i].writeToParcel(out); |
| 10179 | } |
| 10180 | for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { |
| 10181 | mWifiActivityCounters[i].writeToParcel(out); |
| 10182 | } |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 10183 | out.writeInt(mHasWifiEnergyReporting ? 1 : 0); |
| 10184 | out.writeInt(mHasBluetoothEnergyReporting ? 1 : 0); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10185 | out.writeInt(mNumConnectivityChange); |
| 10186 | out.writeInt(mLoadedNumConnectivityChange); |
| 10187 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10188 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10189 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10190 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10191 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10192 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10193 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10194 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 10195 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10196 | out.writeInt(mDischargeAmountScreenOn); |
| 10197 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 10198 | out.writeInt(mDischargeAmountScreenOff); |
| 10199 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10200 | mDischargeStepTracker.writeToParcel(out); |
| 10201 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10202 | out.writeLong(mLastWriteTime); |
| 10203 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10204 | if (inclUids) { |
| 10205 | out.writeInt(mKernelWakelockStats.size()); |
| 10206 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10207 | SamplingTimer kwlt = ent.getValue(); |
| 10208 | if (kwlt != null) { |
| 10209 | out.writeInt(1); |
| 10210 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10211 | kwlt.writeToParcel(out, uSecRealtime); |
| 10212 | } else { |
| 10213 | out.writeInt(0); |
| 10214 | } |
| 10215 | } |
| 10216 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10217 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10218 | SamplingTimer timer = ent.getValue(); |
| 10219 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10220 | out.writeInt(1); |
| 10221 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10222 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10223 | } else { |
| 10224 | out.writeInt(0); |
| 10225 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10226 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10227 | } else { |
| 10228 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10229 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10230 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10231 | if (inclUids) { |
| 10232 | int size = mUidStats.size(); |
| 10233 | out.writeInt(size); |
| 10234 | for (int i = 0; i < size; i++) { |
| 10235 | out.writeInt(mUidStats.keyAt(i)); |
| 10236 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10237 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10238 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10239 | } |
| 10240 | } else { |
| 10241 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10242 | } |
| 10243 | } |
| 10244 | |
| 10245 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 10246 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 10247 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 10248 | return new BatteryStatsImpl(in); |
| 10249 | } |
| 10250 | |
| 10251 | public BatteryStatsImpl[] newArray(int size) { |
| 10252 | return new BatteryStatsImpl[size]; |
| 10253 | } |
| 10254 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10255 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10256 | public void prepareForDumpLocked() { |
| 10257 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10258 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10259 | |
| 10260 | // Pull the clock time. This may update the time and make a new history entry |
| 10261 | // if we had originally pulled a time before the RTC was set. |
| 10262 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10263 | } |
| 10264 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 10265 | 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] | 10266 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10267 | pw.println("mOnBatteryTimeBase:"); |
| 10268 | mOnBatteryTimeBase.dump(pw, " "); |
| 10269 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 10270 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10271 | Printer pr = new PrintWriterPrinter(pw); |
| 10272 | pr.println("*** Screen timer:"); |
| 10273 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10274 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10275 | pr.println("*** Screen brightness #" + i + ":"); |
| 10276 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10277 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10278 | pr.println("*** Interactive timer:"); |
| 10279 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10280 | pr.println("*** Power save mode timer:"); |
| 10281 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame^] | 10282 | pr.println("*** Device idle mode light timer:"); |
| 10283 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 10284 | pr.println("*** Device idle mode full timer:"); |
| 10285 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 10286 | pr.println("*** Device light idling timer:"); |
| 10287 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10288 | pr.println("*** Device idling timer:"); |
| 10289 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10290 | pr.println("*** Phone timer:"); |
| 10291 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10292 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10293 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10294 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10295 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10296 | pr.println("*** Signal scanning :"); |
| 10297 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10298 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10299 | pr.println("*** Data connection type #" + i + ":"); |
| 10300 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10301 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10302 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10303 | pr.println("*** Mobile network active timer:"); |
| 10304 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10305 | pr.println("*** Mobile network active adjusted timer:"); |
| 10306 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10307 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10308 | pr.println("*** Wifi timer:"); |
| 10309 | mWifiOnTimer.logState(pr, " "); |
| 10310 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10311 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10312 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10313 | pr.println("*** Wifi state #" + i + ":"); |
| 10314 | mWifiStateTimer[i].logState(pr, " "); |
| 10315 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10316 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10317 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 10318 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 10319 | } |
| 10320 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10321 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 10322 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 10323 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10324 | pr.println("*** Flashlight timer:"); |
| 10325 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10326 | pr.println("*** Camera timer:"); |
| 10327 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10328 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 10329 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10331 | } |