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 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 23 | import android.bluetooth.UidTraffic; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 26 | import android.net.ConnectivityManager; |
| 27 | import android.net.NetworkStats; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 29 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 30 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 32 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 33 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 34 | import android.os.Handler; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 35 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 36 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 37 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.Parcel; |
| 39 | import android.os.ParcelFormatException; |
| 40 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 41 | import android.os.Process; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 42 | import android.os.RemoteException; |
| 43 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.os.SystemClock; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 45 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 46 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 47 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 48 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 49 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 50 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 51 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 52 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 53 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 55 | import android.util.LogWriter; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 56 | import android.util.LongSparseArray; |
| 57 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 58 | import android.util.MutableInt; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 59 | import android.util.Pools; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 60 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 62 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 64 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 65 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 66 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 67 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 68 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 70 | import com.android.internal.annotations.GuardedBy; |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 71 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 72 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 73 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 74 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 75 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 76 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 77 | import com.android.internal.util.XmlUtils; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 78 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 79 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 80 | import org.xmlpull.v1.XmlPullParser; |
| 81 | import org.xmlpull.v1.XmlPullParserException; |
| 82 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 83 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 84 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.io.File; |
| 86 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 87 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import java.io.FileOutputStream; |
| 89 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 90 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 91 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import java.util.ArrayList; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 93 | import java.util.Arrays; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 94 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 96 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import java.util.Map; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 98 | import java.util.concurrent.Future; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 99 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 100 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * All information we are collecting about things that can happen that impact |
| 104 | * battery life. All times are represented in microseconds except where indicated |
| 105 | * otherwise. |
| 106 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 107 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 109 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 110 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 111 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 112 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 113 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 114 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 115 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 116 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | // 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] | 119 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
| 121 | // Current on-disk Parcel version |
Bookatz | ba78b2b | 2017-10-10 11:06:33 -0700 | [diff] [blame^] | 122 | private static final int VERSION = 168 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 123 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 124 | // Maximum number of items we will record in the history. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 125 | private static final int MAX_HISTORY_ITEMS; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 126 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 127 | // No, really, THIS is the maximum number of items we will record in the history. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 128 | private static final int MAX_MAX_HISTORY_ITEMS; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 129 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 130 | // The maximum number of names wakelocks we will keep track of |
| 131 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 132 | // in to one common name. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 133 | private static final int MAX_WAKELOCKS_PER_UID; |
| 134 | |
| 135 | static final int MAX_HISTORY_BUFFER; // 256KB |
| 136 | static final int MAX_MAX_HISTORY_BUFFER; // 320KB |
| 137 | |
| 138 | static { |
| 139 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 140 | MAX_HISTORY_ITEMS = 800; |
| 141 | MAX_MAX_HISTORY_ITEMS = 1200; |
| 142 | MAX_WAKELOCKS_PER_UID = 40; |
| 143 | MAX_HISTORY_BUFFER = 96*1024; // 96KB |
| 144 | MAX_MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 145 | } else { |
| 146 | MAX_HISTORY_ITEMS = 2000; |
| 147 | MAX_MAX_HISTORY_ITEMS = 3000; |
| 148 | MAX_WAKELOCKS_PER_UID = 100; |
| 149 | MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 150 | MAX_MAX_HISTORY_BUFFER = 320*1024; // 256KB |
| 151 | } |
| 152 | } |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 153 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 154 | // Number of transmit power states the Wifi controller can be in. |
| 155 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 156 | |
| 157 | // Number of transmit power states the Bluetooth controller can be in. |
| 158 | private static final int NUM_BT_TX_LEVELS = 1; |
| 159 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 160 | /** |
| 161 | * Holding a wakelock costs more than just using the cpu. |
| 162 | * Currently, we assign only half the cpu time to an app that is running but |
| 163 | * not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 164 | * If no app is holding a wakelock, then the distribution is normal. |
| 165 | */ |
| 166 | @VisibleForTesting |
| 167 | public static final int WAKE_LOCK_WEIGHT = 50; |
| 168 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 169 | protected Clocks mClocks; |
| 170 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 171 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 172 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 173 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 175 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 176 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 177 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 178 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 179 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 180 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 181 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 182 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 183 | @VisibleForTesting |
| 184 | protected KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 185 | @VisibleForTesting |
| 186 | protected KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
| 187 | @VisibleForTesting |
| 188 | protected KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 189 | new KernelUidCpuFreqTimeReader(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 190 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 191 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 192 | = new KernelMemoryBandwidthStats(); |
| 193 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 194 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 195 | return mKernelMemoryStats; |
| 196 | } |
| 197 | |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 198 | /** Container for Resource Power Manager stats. Updated by updateRpmStatsLocked. */ |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 199 | private final RpmStats mTmpRpmStats = new RpmStats(); |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 200 | /** The soonest the RPM stats can be updated after it was last updated. */ |
| 201 | private static final long RPM_STATS_UPDATE_FREQ_MS = 1000; |
| 202 | /** Last time that RPM stats were updated by updateRpmStatsLocked. */ |
| 203 | private long mLastRpmStatsUpdateTimeMs = -RPM_STATS_UPDATE_FREQ_MS; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 204 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 205 | public interface BatteryCallback { |
| 206 | public void batteryNeedsCpuUpdate(); |
| 207 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 208 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 211 | public interface PlatformIdleStateCallback { |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 212 | public void fillLowPowerStats(RpmStats rpmStats); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 213 | public String getPlatformLowPowerStats(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 214 | public String getSubsystemLowPowerStats(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 217 | public static abstract class UserInfoProvider { |
| 218 | private int[] userIds; |
| 219 | protected abstract @Nullable int[] getUserIds(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 220 | @VisibleForTesting |
| 221 | public final void refreshUserIds() { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 222 | userIds = getUserIds(); |
| 223 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 224 | @VisibleForTesting |
| 225 | public boolean exists(int userId) { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 226 | return userIds != null ? ArrayUtils.contains(userIds, userId) : true; |
| 227 | } |
| 228 | } |
| 229 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 230 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 231 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 232 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 233 | public MyHandler(Looper looper) { |
| 234 | super(looper, null, true); |
| 235 | } |
| 236 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 237 | @Override |
| 238 | public void handleMessage(Message msg) { |
| 239 | BatteryCallback cb = mCallback; |
| 240 | switch (msg.what) { |
| 241 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 242 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 243 | updateCpuTimeLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 244 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 245 | if (cb != null) { |
| 246 | cb.batteryNeedsCpuUpdate(); |
| 247 | } |
| 248 | break; |
| 249 | case MSG_REPORT_POWER_CHANGE: |
| 250 | if (cb != null) { |
| 251 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 252 | } |
| 253 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 254 | case MSG_REPORT_CHARGING: |
| 255 | if (cb != null) { |
| 256 | final String action; |
| 257 | synchronized (BatteryStatsImpl.this) { |
| 258 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 259 | : BatteryManager.ACTION_DISCHARGING; |
| 260 | } |
| 261 | Intent intent = new Intent(action); |
| 262 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 263 | cb.batterySendBroadcast(intent); |
| 264 | } |
| 265 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 270 | public interface Clocks { |
| 271 | public long elapsedRealtime(); |
| 272 | public long uptimeMillis(); |
| 273 | } |
| 274 | |
| 275 | public static class SystemClocks implements Clocks { |
| 276 | public long elapsedRealtime() { |
| 277 | return SystemClock.elapsedRealtime(); |
| 278 | } |
| 279 | |
| 280 | public long uptimeMillis() { |
| 281 | return SystemClock.uptimeMillis(); |
| 282 | } |
| 283 | } |
| 284 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 285 | public interface ExternalStatsSync { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 286 | int UPDATE_CPU = 0x01; |
| 287 | int UPDATE_WIFI = 0x02; |
| 288 | int UPDATE_RADIO = 0x04; |
| 289 | int UPDATE_BT = 0x08; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 290 | int UPDATE_RPM = 0x10; // 16 |
| 291 | int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT | UPDATE_RPM; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 292 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 293 | Future<?> scheduleSync(String reason, int flags); |
| 294 | Future<?> scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 297 | public final MyHandler mHandler; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 298 | private ExternalStatsSync mExternalSync = null; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 299 | @VisibleForTesting |
| 300 | protected UserInfoProvider mUserInfoProvider = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 301 | |
| 302 | private BatteryCallback mCallback; |
| 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 305 | * Mapping isolated uids to the actual owning app uid. |
| 306 | */ |
| 307 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 308 | |
| 309 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | * The statistics we have collected organized by uids. |
| 311 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 312 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | |
| 314 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 315 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 316 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 317 | // changes. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 318 | @VisibleForTesting |
| 319 | protected ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 320 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 321 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 322 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 323 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 324 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 325 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 326 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 327 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 328 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 329 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 330 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 331 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 332 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 333 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 335 | // Last partial timers we use for distributing CPU usage. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 336 | @VisibleForTesting |
| 337 | protected ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | // These are the objects that will want to do something when the device |
| 340 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 341 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 342 | |
| 343 | // These are the objects that will want to do something when the device |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 344 | // is unplugged from power *and* the screen is off or doze. |
| 345 | protected final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 346 | |
| 347 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 348 | // CPU update, even if we aren't currently running wake locks. |
| 349 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 350 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 351 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 352 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 353 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 354 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 355 | long mHistoryBaseTime; |
| 356 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 357 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 358 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 359 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 360 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 361 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 362 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 363 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 364 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 365 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 366 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 367 | int[] mReadHistoryUids; |
| 368 | int mReadHistoryChars; |
| 369 | int mNextHistoryTagIdx = 0; |
| 370 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 371 | int mHistoryBufferLastPos = -1; |
| 372 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 373 | int mActiveHistoryStates = 0xffffffff; |
| 374 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 375 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 376 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 377 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 378 | |
| 379 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 380 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 381 | HistoryItem mHistory; |
| 382 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 383 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 384 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 385 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 386 | // Used by computeHistoryStepDetails |
| 387 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 388 | byte mLastHistoryStepLevel = 0; |
| 389 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 390 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 391 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 392 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 393 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 394 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 395 | */ |
| 396 | long mLastStepCpuUserTime; |
| 397 | long mCurStepCpuUserTime; |
| 398 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 399 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 400 | */ |
| 401 | long mLastStepCpuSystemTime; |
| 402 | long mCurStepCpuSystemTime; |
| 403 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 404 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 405 | */ |
| 406 | long mLastStepStatUserTime; |
| 407 | long mLastStepStatSystemTime; |
| 408 | long mLastStepStatIOWaitTime; |
| 409 | long mLastStepStatIrqTime; |
| 410 | long mLastStepStatSoftIrqTime; |
| 411 | long mLastStepStatIdleTime; |
| 412 | long mCurStepStatUserTime; |
| 413 | long mCurStepStatSystemTime; |
| 414 | long mCurStepStatIOWaitTime; |
| 415 | long mCurStepStatIrqTime; |
| 416 | long mCurStepStatSoftIrqTime; |
| 417 | long mCurStepStatIdleTime; |
| 418 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 419 | private HistoryItem mHistoryIterator; |
| 420 | private boolean mReadOverflow; |
| 421 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | int mStartCount; |
| 424 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 425 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 426 | String mStartPlatformVersion; |
| 427 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | long mUptime; |
| 430 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | long mRealtime; |
| 432 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 433 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 434 | int mWakeLockNesting; |
| 435 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 436 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 437 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 438 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 439 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 440 | protected int mScreenState = Display.STATE_UNKNOWN; |
| 441 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 442 | protected StopwatchTimer mScreenOnTimer; |
| 443 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 444 | protected StopwatchTimer mScreenDozeTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 445 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 446 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 447 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 448 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 449 | boolean mPretendScreenOff; |
| 450 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 451 | boolean mInteractive; |
| 452 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 453 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 454 | boolean mPowerSaveModeEnabled; |
| 455 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 456 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 457 | boolean mDeviceIdling; |
| 458 | StopwatchTimer mDeviceIdlingTimer; |
| 459 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 460 | boolean mDeviceLightIdling; |
| 461 | StopwatchTimer mDeviceLightIdlingTimer; |
| 462 | |
| 463 | int mDeviceIdleMode; |
| 464 | long mLastIdleTimeStart; |
| 465 | long mLongestLightIdleTime; |
| 466 | long mLongestFullIdleTime; |
| 467 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 468 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 471 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 472 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 473 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 474 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 475 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 476 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 477 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 478 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 479 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 480 | StopwatchTimer mFlashlightOnTimer; |
| 481 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 482 | int mCameraOnNesting; |
| 483 | StopwatchTimer mCameraOnTimer; |
| 484 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 485 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 486 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 487 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 488 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 489 | |
| 490 | StopwatchTimer mPhoneSignalScanningTimer; |
| 491 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 492 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 493 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 494 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 495 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 496 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 497 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 498 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 499 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 500 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 501 | /** |
| 502 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 503 | */ |
| 504 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 505 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 506 | /** |
| 507 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 508 | */ |
| 509 | ControllerActivityCounterImpl mBluetoothActivity; |
| 510 | |
| 511 | /** |
| 512 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 513 | */ |
| 514 | ControllerActivityCounterImpl mModemActivity; |
| 515 | |
| 516 | /** |
| 517 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 518 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 519 | */ |
| 520 | boolean mHasWifiReporting = false; |
| 521 | |
| 522 | /** |
| 523 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 524 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 525 | */ |
| 526 | boolean mHasBluetoothReporting = false; |
| 527 | |
| 528 | /** |
| 529 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 530 | * the first Modem energy report. See {@link #mModemActivity}. |
| 531 | */ |
| 532 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 533 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 534 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 535 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 536 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 537 | boolean mGlobalWifiRunning; |
| 538 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 539 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 540 | int mWifiState = -1; |
| 541 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 542 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 543 | int mWifiSupplState = -1; |
| 544 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 545 | |
| 546 | int mWifiSignalStrengthBin = -1; |
| 547 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 548 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 549 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 550 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 551 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 552 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 553 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 554 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 555 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 556 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 557 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 558 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 559 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 560 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 561 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 562 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | /** |
| 565 | * These provide time bases that discount the time the device is plugged |
| 566 | * in to power. |
| 567 | */ |
| 568 | boolean mOnBattery; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 569 | @VisibleForTesting |
| 570 | protected boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 571 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 572 | /** |
| 573 | * External reporting of whether the device is actually charging. |
| 574 | */ |
| 575 | boolean mCharging = true; |
| 576 | int mLastChargingStateLevel; |
| 577 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 578 | /* |
| 579 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 580 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 581 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 582 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 583 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 584 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 585 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 586 | int mLowDischargeAmountSinceCharge; |
| 587 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 588 | int mDischargeScreenOnUnplugLevel; |
| 589 | int mDischargeScreenOffUnplugLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 590 | int mDischargeScreenDozeUnplugLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 591 | int mDischargeAmountScreenOn; |
| 592 | int mDischargeAmountScreenOnSinceCharge; |
| 593 | int mDischargeAmountScreenOff; |
| 594 | int mDischargeAmountScreenOffSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 595 | int mDischargeAmountScreenDoze; |
| 596 | int mDischargeAmountScreenDozeSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 597 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 598 | private LongSamplingCounter mDischargeScreenOffCounter; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 599 | private LongSamplingCounter mDischargeScreenDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 600 | private LongSamplingCounter mDischargeCounter; |
| 601 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 602 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 603 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 604 | int mInitStepMode = 0; |
| 605 | int mCurStepMode = 0; |
| 606 | int mModStepMode = 0; |
| 607 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 608 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 609 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 610 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 611 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 612 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 613 | |
| 614 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 615 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 616 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 617 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 618 | |
| 619 | static final int MAX_DAILY_ITEMS = 10; |
| 620 | |
| 621 | long mDailyStartTime = 0; |
| 622 | long mNextMinDailyDeadline = 0; |
| 623 | long mNextMaxDailyDeadline = 0; |
| 624 | |
| 625 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 628 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 629 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 630 | private int mPhoneServiceStateRaw = -1; |
| 631 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 632 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 633 | private int mNumConnectivityChange; |
| 634 | private int mLoadedNumConnectivityChange; |
| 635 | private int mUnpluggedNumConnectivityChange; |
| 636 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 637 | private int mEstimatedBatteryCapacity = -1; |
| 638 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 639 | private int mMinLearnedBatteryCapacity = -1; |
| 640 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 641 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 642 | private long[] mCpuFreqs; |
| 643 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 644 | @VisibleForTesting |
| 645 | protected PowerProfile mPowerProfile; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 646 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 647 | /* |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 648 | * Holds a SamplingTimer associated with each Resource Power Manager state and voter, |
| 649 | * recording their times when on-battery (regardless of screen state). |
| 650 | */ |
| 651 | private final HashMap<String, SamplingTimer> mRpmStats = new HashMap<>(); |
| 652 | /** Times for each Resource Power Manager state and voter when screen-off and on-battery. */ |
| 653 | private final HashMap<String, SamplingTimer> mScreenOffRpmStats = new HashMap<>(); |
| 654 | |
| 655 | @Override |
| 656 | public Map<String, ? extends Timer> getRpmStats() { |
| 657 | return mRpmStats; |
| 658 | } |
| 659 | |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 660 | // TODO: Note: screenOffRpmStats has been disabled via SCREEN_OFF_RPM_STATS_ENABLED. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 661 | @Override |
| 662 | public Map<String, ? extends Timer> getScreenOffRpmStats() { |
| 663 | return mScreenOffRpmStats; |
| 664 | } |
| 665 | |
| 666 | /* |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 667 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 668 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 669 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 670 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 671 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 672 | return mKernelWakelockStats; |
| 673 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 674 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 675 | String mLastWakeupReason = null; |
| 676 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 677 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 678 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 679 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 680 | return mWakeupReasonStats; |
| 681 | } |
| 682 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 683 | @Override |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 684 | public long getMahDischarge(int which) { |
| 685 | return mDischargeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | @Override |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 689 | public long getMahDischargeScreenOff(int which) { |
| 690 | return mDischargeScreenOffCounter.getCountLocked(which); |
| 691 | } |
| 692 | |
| 693 | @Override |
| 694 | public long getMahDischargeScreenDoze(int which) { |
| 695 | return mDischargeScreenDozeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 698 | @Override |
| 699 | public int getEstimatedBatteryCapacity() { |
| 700 | return mEstimatedBatteryCapacity; |
| 701 | } |
| 702 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 703 | @Override |
| 704 | public int getMinLearnedBatteryCapacity() { |
| 705 | return mMinLearnedBatteryCapacity; |
| 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public int getMaxLearnedBatteryCapacity() { |
| 710 | return mMaxLearnedBatteryCapacity; |
| 711 | } |
| 712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 714 | this(new SystemClocks()); |
| 715 | } |
| 716 | |
| 717 | public BatteryStatsImpl(Clocks clocks) { |
| 718 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 719 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 720 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 721 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 722 | mHandler = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 723 | mPlatformIdleStateCallback = null; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 724 | mUserInfoProvider = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 725 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 728 | private void init(Clocks clocks) { |
| 729 | mClocks = clocks; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 732 | public interface TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 733 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 734 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 735 | } |
| 736 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 737 | // methods are protected not private to be VisibleForTesting |
| 738 | public static class TimeBase { |
| 739 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 740 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 741 | protected long mUptime; |
| 742 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 743 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 744 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 745 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 746 | protected long mPastUptime; |
| 747 | protected long mUptimeStart; |
| 748 | protected long mPastRealtime; |
| 749 | protected long mRealtimeStart; |
| 750 | protected long mUnpluggedUptime; |
| 751 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 752 | |
| 753 | public void dump(PrintWriter pw, String prefix) { |
| 754 | StringBuilder sb = new StringBuilder(128); |
| 755 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 756 | sb.setLength(0); |
| 757 | sb.append(prefix); |
| 758 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 759 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 760 | pw.println(sb.toString()); |
| 761 | sb.setLength(0); |
| 762 | sb.append(prefix); |
| 763 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 764 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 765 | pw.println(sb.toString()); |
| 766 | sb.setLength(0); |
| 767 | sb.append(prefix); |
| 768 | sb.append("mPastUptime="); |
| 769 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 770 | formatTimeMs(sb, mUptimeStart / 1000); |
| 771 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 772 | pw.println(sb.toString()); |
| 773 | sb.setLength(0); |
| 774 | sb.append(prefix); |
| 775 | sb.append("mPastRealtime="); |
| 776 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 777 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 778 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 779 | pw.println(sb.toString()); |
| 780 | } |
| 781 | |
| 782 | public void add(TimeBaseObs observer) { |
| 783 | mObservers.add(observer); |
| 784 | } |
| 785 | |
| 786 | public void remove(TimeBaseObs observer) { |
| 787 | if (!mObservers.remove(observer)) { |
| 788 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 789 | } |
| 790 | } |
| 791 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 792 | public boolean hasObserver(TimeBaseObs observer) { |
| 793 | return mObservers.contains(observer); |
| 794 | } |
| 795 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 796 | public void init(long uptime, long realtime) { |
| 797 | mRealtime = 0; |
| 798 | mUptime = 0; |
| 799 | mPastUptime = 0; |
| 800 | mPastRealtime = 0; |
| 801 | mUptimeStart = uptime; |
| 802 | mRealtimeStart = realtime; |
| 803 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 804 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 805 | } |
| 806 | |
| 807 | public void reset(long uptime, long realtime) { |
| 808 | if (!mRunning) { |
| 809 | mPastUptime = 0; |
| 810 | mPastRealtime = 0; |
| 811 | } else { |
| 812 | mUptimeStart = uptime; |
| 813 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 814 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 815 | // just return mPastUptime. Also, are we sure we don't want to reset that? |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 816 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 817 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 818 | mUnpluggedRealtime = getRealtime(realtime); |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | public long computeUptime(long curTime, int which) { |
| 823 | switch (which) { |
| 824 | case STATS_SINCE_CHARGED: |
| 825 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 826 | case STATS_CURRENT: |
| 827 | return getUptime(curTime); |
| 828 | case STATS_SINCE_UNPLUGGED: |
| 829 | return getUptime(curTime) - mUnpluggedUptime; |
| 830 | } |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | public long computeRealtime(long curTime, int which) { |
| 835 | switch (which) { |
| 836 | case STATS_SINCE_CHARGED: |
| 837 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 838 | case STATS_CURRENT: |
| 839 | return getRealtime(curTime); |
| 840 | case STATS_SINCE_UNPLUGGED: |
| 841 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 842 | } |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | public long getUptime(long curTime) { |
| 847 | long time = mPastUptime; |
| 848 | if (mRunning) { |
| 849 | time += curTime - mUptimeStart; |
| 850 | } |
| 851 | return time; |
| 852 | } |
| 853 | |
| 854 | public long getRealtime(long curTime) { |
| 855 | long time = mPastRealtime; |
| 856 | if (mRunning) { |
| 857 | time += curTime - mRealtimeStart; |
| 858 | } |
| 859 | return time; |
| 860 | } |
| 861 | |
| 862 | public long getUptimeStart() { |
| 863 | return mUptimeStart; |
| 864 | } |
| 865 | |
| 866 | public long getRealtimeStart() { |
| 867 | return mRealtimeStart; |
| 868 | } |
| 869 | |
| 870 | public boolean isRunning() { |
| 871 | return mRunning; |
| 872 | } |
| 873 | |
| 874 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 875 | if (mRunning != running) { |
| 876 | mRunning = running; |
| 877 | if (running) { |
| 878 | mUptimeStart = uptime; |
| 879 | mRealtimeStart = realtime; |
| 880 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 881 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 882 | |
| 883 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 884 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 885 | } |
| 886 | } else { |
| 887 | mPastUptime += uptime - mUptimeStart; |
| 888 | mPastRealtime += realtime - mRealtimeStart; |
| 889 | |
| 890 | long batteryUptime = getUptime(uptime); |
| 891 | long batteryRealtime = getRealtime(realtime); |
| 892 | |
| 893 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 894 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 895 | } |
| 896 | } |
| 897 | return true; |
| 898 | } |
| 899 | return false; |
| 900 | } |
| 901 | |
| 902 | public void readSummaryFromParcel(Parcel in) { |
| 903 | mUptime = in.readLong(); |
| 904 | mRealtime = in.readLong(); |
| 905 | } |
| 906 | |
| 907 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 908 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 909 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 910 | } |
| 911 | |
| 912 | public void readFromParcel(Parcel in) { |
| 913 | mRunning = false; |
| 914 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 915 | mPastUptime = in.readLong(); |
| 916 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 917 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 918 | mPastRealtime = in.readLong(); |
| 919 | mRealtimeStart = in.readLong(); |
| 920 | mUnpluggedUptime = in.readLong(); |
| 921 | mUnpluggedRealtime = in.readLong(); |
| 922 | } |
| 923 | |
| 924 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 925 | final long runningUptime = getUptime(uptime); |
| 926 | final long runningRealtime = getRealtime(realtime); |
| 927 | out.writeLong(mUptime); |
| 928 | out.writeLong(runningUptime); |
| 929 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 930 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 931 | out.writeLong(runningRealtime); |
| 932 | out.writeLong(mRealtimeStart); |
| 933 | out.writeLong(mUnpluggedUptime); |
| 934 | out.writeLong(mUnpluggedRealtime); |
| 935 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 939 | * State for keeping track of counting information. |
| 940 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 941 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 942 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 943 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 944 | int mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 945 | int mUnpluggedCount; |
| 946 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 947 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 948 | public Counter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 949 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 950 | mPluggedCount = in.readInt(); |
| 951 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 952 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 953 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 954 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 957 | public Counter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 958 | mTimeBase = timeBase; |
| 959 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 960 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 961 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 962 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 963 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 964 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 965 | out.writeInt(mUnpluggedCount); |
| 966 | } |
| 967 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 968 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 969 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 970 | mUnpluggedCount = mPluggedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 973 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 974 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 975 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 976 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 977 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 978 | /** |
| 979 | * Writes a possibly null Counter to a Parcel. |
| 980 | * |
| 981 | * @param out the Parcel to be written to. |
| 982 | * @param counter a Counter, or null. |
| 983 | */ |
| 984 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 985 | if (counter == null) { |
| 986 | out.writeInt(0); // indicates null |
| 987 | return; |
| 988 | } |
| 989 | out.writeInt(1); // indicates non-null |
| 990 | |
| 991 | counter.writeToParcel(out); |
| 992 | } |
| 993 | |
| 994 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 995 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 996 | int val = mCount.get(); |
| 997 | if (which == STATS_SINCE_UNPLUGGED) { |
| 998 | val -= mUnpluggedCount; |
| 999 | } else if (which != STATS_SINCE_CHARGED) { |
| 1000 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | return val; |
| 1004 | } |
| 1005 | |
| 1006 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1007 | pw.println(prefix + "mCount=" + mCount.get() |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1008 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1009 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1010 | + " mPluggedCount=" + mPluggedCount); |
| 1011 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1012 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1013 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1014 | public void stepAtomic() { |
| 1015 | if (mTimeBase.isRunning()) { |
| 1016 | mCount.incrementAndGet(); |
| 1017 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1020 | void addAtomic(int delta) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1021 | if (mTimeBase.isRunning()) { |
| 1022 | mCount.addAndGet(delta); |
| 1023 | } |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1026 | /** |
| 1027 | * Clear state of this counter. |
| 1028 | */ |
| 1029 | void reset(boolean detachIfReset) { |
| 1030 | mCount.set(0); |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1031 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1032 | if (detachIfReset) { |
| 1033 | detach(); |
| 1034 | } |
| 1035 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1036 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1037 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1038 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1039 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1040 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1041 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1042 | public void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1043 | int count = mCount.get(); |
| 1044 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1047 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1048 | public void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1049 | mLoadedCount = in.readInt(); |
| 1050 | mCount.set(mLoadedCount); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1051 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1052 | } |
| 1053 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1054 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1055 | @VisibleForTesting |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1056 | public static class LongSamplingCounterArray extends LongCounterArray implements TimeBaseObs { |
| 1057 | final TimeBase mTimeBase; |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1058 | public long[] mCounts; |
| 1059 | public long[] mLoadedCounts; |
| 1060 | public long[] mUnpluggedCounts; |
| 1061 | public long[] mPluggedCounts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1062 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1063 | private LongSamplingCounterArray(TimeBase timeBase, Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1064 | mTimeBase = timeBase; |
| 1065 | mPluggedCounts = in.createLongArray(); |
| 1066 | mCounts = copyArray(mPluggedCounts, mCounts); |
| 1067 | mLoadedCounts = in.createLongArray(); |
| 1068 | mUnpluggedCounts = in.createLongArray(); |
| 1069 | timeBase.add(this); |
| 1070 | } |
| 1071 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1072 | public LongSamplingCounterArray(TimeBase timeBase) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1073 | mTimeBase = timeBase; |
| 1074 | timeBase.add(this); |
| 1075 | } |
| 1076 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1077 | private void writeToParcel(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1078 | out.writeLongArray(mCounts); |
| 1079 | out.writeLongArray(mLoadedCounts); |
| 1080 | out.writeLongArray(mUnpluggedCounts); |
| 1081 | } |
| 1082 | |
| 1083 | @Override |
| 1084 | public void onTimeStarted(long elapsedRealTime, long baseUptime, long baseRealtime) { |
| 1085 | mUnpluggedCounts = copyArray(mPluggedCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | @Override |
| 1089 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1090 | mPluggedCounts = copyArray(mCounts, mPluggedCounts); |
| 1091 | } |
| 1092 | |
| 1093 | @Override |
| 1094 | public long[] getCountsLocked(int which) { |
| 1095 | long[] val = copyArray(mTimeBase.isRunning() ? mCounts : mPluggedCounts, null); |
| 1096 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1097 | subtract(val, mUnpluggedCounts); |
| 1098 | } else if (which != STATS_SINCE_CHARGED) { |
| 1099 | subtract(val, mLoadedCounts); |
| 1100 | } |
| 1101 | return val; |
| 1102 | } |
| 1103 | |
| 1104 | @Override |
| 1105 | public void logState(Printer pw, String prefix) { |
| 1106 | pw.println(prefix + "mCounts=" + Arrays.toString(mCounts) |
| 1107 | + " mLoadedCounts=" + Arrays.toString(mLoadedCounts) |
| 1108 | + " mUnpluggedCounts=" + Arrays.toString(mUnpluggedCounts) |
| 1109 | + " mPluggedCounts=" + Arrays.toString(mPluggedCounts)); |
| 1110 | } |
| 1111 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1112 | public void addCountLocked(long[] counts) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1113 | if (counts == null) { |
| 1114 | return; |
| 1115 | } |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1116 | if (mTimeBase.isRunning()) { |
| 1117 | if (mCounts == null) { |
| 1118 | mCounts = new long[counts.length]; |
| 1119 | } |
| 1120 | for (int i = 0; i < counts.length; ++i) { |
| 1121 | mCounts[i] += counts[i]; |
| 1122 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 1126 | public int getSize() { |
| 1127 | return mCounts == null ? 0 : mCounts.length; |
| 1128 | } |
| 1129 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1130 | /** |
| 1131 | * Clear state of this counter. |
| 1132 | */ |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1133 | public void reset(boolean detachIfReset) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1134 | fillArray(mCounts, 0); |
| 1135 | fillArray(mLoadedCounts, 0); |
| 1136 | fillArray(mPluggedCounts, 0); |
| 1137 | fillArray(mUnpluggedCounts, 0); |
| 1138 | if (detachIfReset) { |
| 1139 | detach(); |
| 1140 | } |
| 1141 | } |
| 1142 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1143 | public void detach() { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1144 | mTimeBase.remove(this); |
| 1145 | } |
| 1146 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1147 | private void writeSummaryToParcelLocked(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1148 | out.writeLongArray(mCounts); |
| 1149 | } |
| 1150 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1151 | private void readSummaryFromParcelLocked(Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1152 | mCounts = in.createLongArray(); |
| 1153 | mLoadedCounts = copyArray(mCounts, mLoadedCounts); |
| 1154 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
| 1155 | mPluggedCounts = copyArray(mCounts, mPluggedCounts); |
| 1156 | } |
| 1157 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1158 | public static void writeToParcel(Parcel out, LongSamplingCounterArray counterArray) { |
| 1159 | if (counterArray != null) { |
| 1160 | out.writeInt(1); |
| 1161 | counterArray.writeToParcel(out); |
| 1162 | } else { |
| 1163 | out.writeInt(0); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | public static LongSamplingCounterArray readFromParcel(Parcel in, TimeBase timeBase) { |
| 1168 | if (in.readInt() != 0) { |
| 1169 | return new LongSamplingCounterArray(timeBase, in); |
| 1170 | } else { |
| 1171 | return null; |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | public static void writeSummaryToParcelLocked(Parcel out, |
| 1176 | LongSamplingCounterArray counterArray) { |
| 1177 | if (counterArray != null) { |
| 1178 | out.writeInt(1); |
| 1179 | counterArray.writeSummaryToParcelLocked(out); |
| 1180 | } else { |
| 1181 | out.writeInt(0); |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | public static LongSamplingCounterArray readSummaryFromParcelLocked(Parcel in, |
| 1186 | TimeBase timeBase) { |
| 1187 | if (in.readInt() != 0) { |
| 1188 | final LongSamplingCounterArray counterArray |
| 1189 | = new LongSamplingCounterArray(timeBase); |
| 1190 | counterArray.readSummaryFromParcelLocked(in); |
| 1191 | return counterArray; |
| 1192 | } else { |
| 1193 | return null; |
| 1194 | } |
| 1195 | } |
| 1196 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1197 | private static void fillArray(long[] a, long val) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1198 | if (a != null) { |
| 1199 | Arrays.fill(a, val); |
| 1200 | } |
| 1201 | } |
| 1202 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1203 | private static void subtract(@NonNull long[] val, long[] toSubtract) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1204 | if (toSubtract == null) { |
| 1205 | return; |
| 1206 | } |
| 1207 | for (int i = 0; i < val.length; i++) { |
| 1208 | val[i] -= toSubtract[i]; |
| 1209 | } |
| 1210 | } |
| 1211 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1212 | private static long[] copyArray(long[] src, long[] dest) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1213 | if (src == null) { |
| 1214 | return null; |
| 1215 | } else { |
| 1216 | if (dest == null) { |
| 1217 | dest = new long[src.length]; |
| 1218 | } |
| 1219 | System.arraycopy(src, 0, dest, 0, src.length); |
| 1220 | return dest; |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1225 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1226 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1227 | long mCount; |
| 1228 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1229 | long mUnpluggedCount; |
| 1230 | long mPluggedCount; |
| 1231 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1232 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 1233 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1234 | mPluggedCount = in.readLong(); |
| 1235 | mCount = mPluggedCount; |
| 1236 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1237 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1238 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1241 | LongSamplingCounter(TimeBase timeBase) { |
| 1242 | mTimeBase = timeBase; |
| 1243 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | public void writeToParcel(Parcel out) { |
| 1247 | out.writeLong(mCount); |
| 1248 | out.writeLong(mLoadedCount); |
| 1249 | out.writeLong(mUnpluggedCount); |
| 1250 | } |
| 1251 | |
| 1252 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1253 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1254 | mUnpluggedCount = mPluggedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1258 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1259 | mPluggedCount = mCount; |
| 1260 | } |
| 1261 | |
| 1262 | public long getCountLocked(int which) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1263 | long val = mTimeBase.isRunning() ? mCount : mPluggedCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1264 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1265 | val -= mUnpluggedCount; |
| 1266 | } else if (which != STATS_SINCE_CHARGED) { |
| 1267 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1268 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1269 | return val; |
| 1270 | } |
| 1271 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1272 | @Override |
| 1273 | public void logState(Printer pw, String prefix) { |
| 1274 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1275 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1276 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1277 | + " mPluggedCount=" + mPluggedCount); |
| 1278 | } |
| 1279 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1280 | void addCountLocked(long count) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1281 | if (mTimeBase.isRunning()) { |
| 1282 | mCount += count; |
| 1283 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * Clear state of this counter. |
| 1288 | */ |
| 1289 | void reset(boolean detachIfReset) { |
| 1290 | mCount = 0; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1291 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1292 | if (detachIfReset) { |
| 1293 | detach(); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1298 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1302 | out.writeLong(mCount); |
| 1303 | } |
| 1304 | |
| 1305 | void readSummaryFromParcelLocked(Parcel in) { |
| 1306 | mLoadedCount = in.readLong(); |
| 1307 | mCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1308 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 1309 | } |
| 1310 | } |
| 1311 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1312 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | * State for keeping track of timing information. |
| 1314 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1315 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1316 | protected final Clocks mClocks; |
| 1317 | protected final int mType; |
| 1318 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1319 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1320 | protected int mCount; |
| 1321 | protected int mLoadedCount; |
| 1322 | protected int mLastCount; |
| 1323 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | // Times are in microseconds for better accuracy when dividing by the |
| 1326 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | /** |
| 1329 | * The total time we have accumulated since the start of the original |
| 1330 | * boot, to the last time something interesting happened in the |
| 1331 | * current run. |
| 1332 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1333 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | /** |
| 1336 | * The total time we loaded for the previous runs. Subtract this from |
| 1337 | * mTotalTime to find the time for the current run of the system. |
| 1338 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1339 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | /** |
| 1342 | * The run time of the last run of the system, as loaded from the |
| 1343 | * saved data. |
| 1344 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1345 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | /** |
| 1348 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1349 | * this from mTotalTime to find the time since the last unplug from |
| 1350 | * power. |
| 1351 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1352 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1353 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1354 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1355 | * The total time this timer has been running until the latest mark has been set. |
| 1356 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1357 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1358 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1359 | |
| 1360 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1361 | * Constructs from a parcel. |
| 1362 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1363 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1364 | * @param in |
| 1365 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1366 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1367 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1369 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | mCount = in.readInt(); |
| 1372 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1373 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | mUnpluggedCount = in.readInt(); |
| 1375 | mTotalTime = in.readLong(); |
| 1376 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1377 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1379 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1380 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1381 | 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] | 1382 | } |
| 1383 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1384 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1385 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1387 | mTimeBase = timeBase; |
| 1388 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1389 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1390 | |
| 1391 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1392 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1393 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1394 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1395 | /** |
| 1396 | * Clear state of this timer. Returns true if the timer is inactive |
| 1397 | * so can be completely dropped. |
| 1398 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1399 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1400 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1401 | mCount = mLoadedCount = mLastCount = 0; |
| 1402 | if (detachIfReset) { |
| 1403 | detach(); |
| 1404 | } |
| 1405 | return true; |
| 1406 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1407 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1408 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1409 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1410 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1411 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1412 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1413 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1414 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1415 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1418 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1421 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1424 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1425 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1427 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1429 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1430 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1431 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1432 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | if (DEBUG && mType < 0) { |
| 1434 | Log.v(TAG, "unplug #" + mType |
| 1435 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1436 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1437 | } |
| 1438 | } |
| 1439 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1440 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1441 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1442 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1443 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1444 | + " old mTotalTime=" + mTotalTime); |
| 1445 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1446 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1447 | mCount = computeCurrentCountLocked(); |
| 1448 | if (DEBUG && mType < 0) { |
| 1449 | Log.v(TAG, "plug #" + mType |
| 1450 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | } |
| 1452 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | /** |
| 1455 | * Writes a possibly null Timer to a Parcel. |
| 1456 | * |
| 1457 | * @param out the Parcel to be written to. |
| 1458 | * @param timer a Timer, or null. |
| 1459 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1460 | 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] | 1461 | if (timer == null) { |
| 1462 | out.writeInt(0); // indicates null |
| 1463 | return; |
| 1464 | } |
| 1465 | out.writeInt(1); // indicates non-null |
| 1466 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1467 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1471 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1472 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1473 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1474 | val -= mUnpluggedTime; |
| 1475 | } else if (which != STATS_SINCE_CHARGED) { |
| 1476 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | return val; |
| 1480 | } |
| 1481 | |
| 1482 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1483 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1484 | int val = computeCurrentCountLocked(); |
| 1485 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1486 | val -= mUnpluggedCount; |
| 1487 | } else if (which != STATS_SINCE_CHARGED) { |
| 1488 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | return val; |
| 1492 | } |
| 1493 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1494 | @Override |
| 1495 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1496 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1497 | return val - mTimeBeforeMark; |
| 1498 | } |
| 1499 | |
| 1500 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1501 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1502 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1504 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1505 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1507 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1509 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1510 | |
| 1511 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1512 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1513 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1514 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1515 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1518 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1519 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1520 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1521 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1522 | mUnpluggedTime = mTotalTime; |
| 1523 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1524 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1525 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1526 | |
| 1527 | // When reading the summary, we set the mark to be the latest information. |
| 1528 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1529 | } |
| 1530 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1531 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1532 | /** |
| 1533 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1534 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1535 | * of the value is recorded. |
| 1536 | * |
| 1537 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1538 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1539 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1540 | * expected to increase monotonically from that point on. |
| 1541 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1542 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1543 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1544 | /** |
| 1545 | * The most recent reported count from /proc/wakelocks. |
| 1546 | */ |
| 1547 | int mCurrentReportedCount; |
| 1548 | |
| 1549 | /** |
| 1550 | * The reported count from /proc/wakelocks when unplug() was last |
| 1551 | * called. |
| 1552 | */ |
| 1553 | int mUnpluggedReportedCount; |
| 1554 | |
| 1555 | /** |
| 1556 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1557 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1558 | long mCurrentReportedTotalTime; |
| 1559 | |
| 1560 | |
| 1561 | /** |
| 1562 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1563 | * called. |
| 1564 | */ |
| 1565 | long mUnpluggedReportedTotalTime; |
| 1566 | |
| 1567 | /** |
| 1568 | * Whether we are currently in a discharge cycle. |
| 1569 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1570 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1571 | |
| 1572 | /** |
| 1573 | * Whether we are currently recording reported values. |
| 1574 | */ |
| 1575 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1576 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1577 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1578 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1579 | */ |
| 1580 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1581 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1582 | @VisibleForTesting |
| 1583 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1584 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1585 | mCurrentReportedCount = in.readInt(); |
| 1586 | mUnpluggedReportedCount = in.readInt(); |
| 1587 | mCurrentReportedTotalTime = in.readLong(); |
| 1588 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1589 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1590 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1591 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1592 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1593 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1594 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1595 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1596 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1597 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1598 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1599 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1600 | /** |
| 1601 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1602 | * be less than the values used for a previous invocation. |
| 1603 | */ |
| 1604 | public void endSample() { |
| 1605 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1606 | mCount = computeCurrentCountLocked(); |
| 1607 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1608 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1609 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1610 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1611 | public void setUpdateVersion(int version) { |
| 1612 | mUpdateVersion = version; |
| 1613 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1614 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1615 | public int getUpdateVersion() { |
| 1616 | return mUpdateVersion; |
| 1617 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1618 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1619 | /** |
| 1620 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1621 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1622 | * |
| 1623 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1624 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1625 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1626 | * increasing sample. |
| 1627 | * |
| 1628 | * @param totalTime total time of sample in microseconds. |
| 1629 | * @param count total number of times the event being sampled occurred. |
| 1630 | */ |
| 1631 | public void update(long totalTime, int count) { |
| 1632 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1633 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1634 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1635 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1636 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1637 | |
| 1638 | mTrackingReportedValues = true; |
| 1639 | |
| 1640 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1641 | endSample(); |
| 1642 | } |
| 1643 | |
| 1644 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1645 | mCurrentReportedCount = count; |
| 1646 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1647 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1648 | /** |
| 1649 | * Adds deltaTime and deltaCount to the current sample. |
| 1650 | * |
| 1651 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1652 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1653 | */ |
| 1654 | public void add(long deltaTime, int deltaCount) { |
| 1655 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1658 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1659 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1660 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1661 | if (mTrackingReportedValues) { |
| 1662 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1663 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1664 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1665 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1668 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1669 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1670 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1671 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1672 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1673 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1674 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1675 | public void logState(Printer pw, String prefix) { |
| 1676 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1677 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1678 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1679 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1680 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1681 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1682 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1683 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1684 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1685 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1686 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1687 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1688 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1689 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1690 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1691 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1692 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1693 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1694 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1695 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1696 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1697 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1698 | out.writeInt(mCurrentReportedCount); |
| 1699 | out.writeInt(mUnpluggedReportedCount); |
| 1700 | out.writeLong(mCurrentReportedTotalTime); |
| 1701 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1702 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1703 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1704 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1705 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1706 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1707 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1708 | mTrackingReportedValues = false; |
| 1709 | mUnpluggedReportedTotalTime = 0; |
| 1710 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1711 | return true; |
| 1712 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1713 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1714 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1715 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1716 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1717 | * for a pre-determined amount. |
| 1718 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1719 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1720 | final Uid mUid; |
| 1721 | |
| 1722 | /** |
| 1723 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1724 | */ |
| 1725 | long mLastAddedTime; |
| 1726 | |
| 1727 | /** |
| 1728 | * The last duration that we added to the timer. This is in microseconds. |
| 1729 | */ |
| 1730 | long mLastAddedDuration; |
| 1731 | |
| 1732 | /** |
| 1733 | * Whether we are currently in a discharge cycle. |
| 1734 | */ |
| 1735 | boolean mInDischarge; |
| 1736 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1737 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1738 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1739 | mUid = uid; |
| 1740 | mLastAddedTime = in.readLong(); |
| 1741 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1742 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1743 | } |
| 1744 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1745 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1746 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1747 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1748 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1752 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1753 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1754 | out.writeLong(mLastAddedTime); |
| 1755 | out.writeLong(mLastAddedDuration); |
| 1756 | } |
| 1757 | |
| 1758 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1759 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1760 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1761 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1762 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1766 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1767 | recomputeLastDuration(elapsedRealtime, false); |
| 1768 | mInDischarge = true; |
| 1769 | // If we are still within the last added duration, then re-added whatever remains. |
| 1770 | if (mLastAddedTime == elapsedRealtime) { |
| 1771 | mTotalTime += mLastAddedDuration; |
| 1772 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1773 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | @Override |
| 1777 | public void logState(Printer pw, String prefix) { |
| 1778 | super.logState(pw, prefix); |
| 1779 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1780 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1781 | } |
| 1782 | |
| 1783 | private long computeOverage(long curTime) { |
| 1784 | if (mLastAddedTime > 0) { |
| 1785 | return mLastTime + mLastAddedDuration - curTime; |
| 1786 | } |
| 1787 | return 0; |
| 1788 | } |
| 1789 | |
| 1790 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1791 | final long overage = computeOverage(curTime); |
| 1792 | if (overage > 0) { |
| 1793 | // Aborting before the duration ran out -- roll back the remaining |
| 1794 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1795 | // actually add the time. |
| 1796 | if (mInDischarge) { |
| 1797 | mTotalTime -= overage; |
| 1798 | } |
| 1799 | if (abort) { |
| 1800 | mLastAddedTime = 0; |
| 1801 | } else { |
| 1802 | mLastAddedTime = curTime; |
| 1803 | mLastAddedDuration -= overage; |
| 1804 | } |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1809 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1810 | recomputeLastDuration(now, true); |
| 1811 | mLastAddedTime = now; |
| 1812 | mLastAddedDuration = durationMillis * 1000; |
| 1813 | if (mInDischarge) { |
| 1814 | mTotalTime += mLastAddedDuration; |
| 1815 | mCount++; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1820 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1821 | recomputeLastDuration(now, true); |
| 1822 | } |
| 1823 | |
| 1824 | @Override |
| 1825 | protected int computeCurrentCountLocked() { |
| 1826 | return mCount; |
| 1827 | } |
| 1828 | |
| 1829 | @Override |
| 1830 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1831 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1832 | if (overage > 0) { |
| 1833 | return mTotalTime = overage; |
| 1834 | } |
| 1835 | return mTotalTime; |
| 1836 | } |
| 1837 | |
| 1838 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1839 | public boolean reset(boolean detachIfReset) { |
| 1840 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1841 | recomputeLastDuration(now, true); |
| 1842 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1843 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1844 | return !stillActive; |
| 1845 | } |
| 1846 | } |
| 1847 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1848 | |
| 1849 | /** |
| 1850 | * A StopwatchTimer that also tracks the total and max individual |
| 1851 | * time spent active according to the given timebase. Whereas |
| 1852 | * StopwatchTimer apportions the time amongst all in the pool, |
| 1853 | * the total and max durations are not apportioned. |
| 1854 | */ |
| 1855 | public static class DurationTimer extends StopwatchTimer { |
| 1856 | /** |
| 1857 | * The time (in ms) that the timer was last acquired or the time base |
| 1858 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 1859 | * |
| 1860 | * -1 if the timer is currently not running or the time base is not running. |
| 1861 | * |
| 1862 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 1863 | * StopwatchTimer. |
| 1864 | */ |
| 1865 | long mStartTimeMs = -1; |
| 1866 | |
| 1867 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1868 | * The longest time period (in ms) that the timer has been active. Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1869 | */ |
| 1870 | long mMaxDurationMs; |
| 1871 | |
| 1872 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1873 | * The time (in ms) that that the timer has been active since most recent |
| 1874 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1875 | */ |
| 1876 | long mCurrentDurationMs; |
| 1877 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1878 | /** |
| 1879 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 1880 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 1881 | * (but not including the present currentDuration) since reset. Not pooled. |
| 1882 | */ |
| 1883 | long mTotalDurationMs; |
| 1884 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1885 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1886 | TimeBase timeBase, Parcel in) { |
| 1887 | super(clocks, uid, type, timerPool, timeBase, in); |
| 1888 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1889 | mTotalDurationMs = in.readLong(); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 1890 | mCurrentDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1894 | TimeBase timeBase) { |
| 1895 | super(clocks, uid, type, timerPool, timeBase); |
| 1896 | } |
| 1897 | |
| 1898 | @Override |
| 1899 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1900 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1901 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 1902 | out.writeLong(mTotalDurationMs); |
| 1903 | out.writeLong(getCurrentDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /** |
| 1907 | * Write the summary to the parcel. |
| 1908 | * |
| 1909 | * Since the time base is probably meaningless after we come back, reading |
| 1910 | * from this will have the effect of stopping the timer. So here all we write |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1911 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1912 | */ |
| 1913 | @Override |
| 1914 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1915 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1916 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1917 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * Read the summary parcel. |
| 1922 | * |
| 1923 | * Has the side effect of stopping the timer. |
| 1924 | */ |
| 1925 | @Override |
| 1926 | public void readSummaryFromParcelLocked(Parcel in) { |
| 1927 | super.readSummaryFromParcelLocked(in); |
| 1928 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1929 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1930 | mStartTimeMs = -1; |
| 1931 | mCurrentDurationMs = 0; |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * The TimeBase time started (again). |
| 1936 | * |
| 1937 | * If the timer is also running, store the start time. |
| 1938 | */ |
| 1939 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 1940 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 1941 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1942 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | /** |
| 1947 | * The TimeBase stopped running. |
| 1948 | * |
| 1949 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 1950 | */ |
| 1951 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1952 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 1953 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1954 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1955 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 1956 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1957 | } |
| 1958 | mStartTimeMs = -1; |
| 1959 | } |
| 1960 | |
| 1961 | @Override |
| 1962 | public void logState(Printer pw, String prefix) { |
| 1963 | super.logState(pw, prefix); |
| 1964 | } |
| 1965 | |
| 1966 | @Override |
| 1967 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 1968 | super.startRunningLocked(elapsedRealtimeMs); |
| 1969 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 1970 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1971 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | /** |
| 1976 | * Decrements the mNesting ref-count on this timer. |
| 1977 | * |
| 1978 | * If it actually stopped (mNesting went to 0), then possibly update |
| 1979 | * mMaxDuration if the current duration was the longest ever. |
| 1980 | */ |
| 1981 | @Override |
| 1982 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1983 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1984 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1985 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1986 | if (durationMs > mMaxDurationMs) { |
| 1987 | mMaxDurationMs = durationMs; |
| 1988 | } |
| 1989 | mStartTimeMs = -1; |
| 1990 | mCurrentDurationMs = 0; |
| 1991 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1992 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 1993 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 1994 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | @Override |
| 1998 | public boolean reset(boolean detachIfReset) { |
| 1999 | boolean result = super.reset(detachIfReset); |
| 2000 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2001 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2002 | mCurrentDurationMs = 0; |
| 2003 | if (mNesting > 0) { |
| 2004 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 2005 | } else { |
| 2006 | mStartTimeMs = -1; |
| 2007 | } |
| 2008 | return result; |
| 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * Returns the max duration that this timer has ever seen. |
| 2013 | * |
| 2014 | * Note that this time is NOT split between the timers in the timer group that |
| 2015 | * this timer is attached to. It is the TOTAL time. |
| 2016 | */ |
| 2017 | @Override |
| 2018 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 2019 | if (mNesting > 0) { |
| 2020 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2021 | if (durationMs > mMaxDurationMs) { |
| 2022 | return durationMs; |
| 2023 | } |
| 2024 | } |
| 2025 | return mMaxDurationMs; |
| 2026 | } |
| 2027 | |
| 2028 | /** |
| 2029 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2030 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2031 | * |
| 2032 | * Note that this time is NOT split between the timers in the timer group that |
| 2033 | * this timer is attached to. It is the TOTAL time. |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2034 | * |
| 2035 | * Note that if running timer is parceled and unparceled, this method will return |
| 2036 | * current duration value at the time of parceling even though timer may not be |
| 2037 | * currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2038 | */ |
| 2039 | @Override |
| 2040 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 2041 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2042 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 2043 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 2044 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2045 | } |
| 2046 | return durationMs; |
| 2047 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2048 | |
| 2049 | /** |
| 2050 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 2051 | * If mTimerPool == null, this should be the same |
| 2052 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 2053 | * |
| 2054 | * Note that this time is NOT split between the timers in the timer group that |
| 2055 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 2056 | * the result will not be equivalent to getTotalTimeLocked. |
| 2057 | */ |
| 2058 | @Override |
| 2059 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 2060 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2061 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2064 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2065 | * State for keeping track of timing information. |
| 2066 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2067 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2068 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2069 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2070 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2071 | int mNesting; |
| 2072 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2073 | /** |
| 2074 | * The last time at which we updated the timer. If mNesting is > 0, |
| 2075 | * subtract this from the current battery time to find the amount of |
| 2076 | * time we have been running since we last computed an update. |
| 2077 | */ |
| 2078 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2079 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2080 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2081 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2082 | * was actually held for an interesting duration. If time base was not running when timer |
| 2083 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2084 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2085 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2086 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2087 | long mTimeout; |
| 2088 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2089 | /** |
| 2090 | * For partial wake locks, keep track of whether we are in the list |
| 2091 | * to consume CPU cycles. |
| 2092 | */ |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 2093 | @VisibleForTesting |
| 2094 | public boolean mInList; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2095 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2096 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2097 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2098 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2099 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2100 | mTimerPool = timerPool; |
| 2101 | mUpdateTime = in.readLong(); |
| 2102 | } |
| 2103 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2104 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2105 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2106 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2107 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2108 | mTimerPool = timerPool; |
| 2109 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2110 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2111 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2112 | mTimeout = timeout; |
| 2113 | } |
| 2114 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2115 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2116 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2117 | out.writeLong(mUpdateTime); |
| 2118 | } |
| 2119 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2120 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2121 | if (mNesting > 0) { |
| 2122 | if (DEBUG && mType < 0) { |
| 2123 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 2124 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2125 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2126 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2127 | if (DEBUG && mType < 0) { |
| 2128 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 2129 | } |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | public void logState(Printer pw, String prefix) { |
| 2134 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2135 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | + " mAcquireTime=" + mAcquireTime); |
| 2137 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2138 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2139 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2141 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2142 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | if (mTimerPool != null) { |
| 2144 | // Accumulate time to all currently active timers before adding |
| 2145 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2146 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | // Add this timer to the active pool |
| 2148 | mTimerPool.add(this); |
| 2149 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2150 | if (mTimeBase.isRunning()) { |
| 2151 | // Increment the count |
| 2152 | mCount++; |
| 2153 | mAcquireTime = mTotalTime; |
| 2154 | } else { |
| 2155 | mAcquireTime = -1; |
| 2156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | if (DEBUG && mType < 0) { |
| 2158 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2159 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2160 | + " mAcquireTime=" + mAcquireTime); |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2165 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2166 | return mNesting > 0; |
| 2167 | } |
| 2168 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2169 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | // Ignore attempt to stop a timer that isn't running |
| 2171 | if (mNesting == 0) { |
| 2172 | return; |
| 2173 | } |
| 2174 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2175 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | if (mTimerPool != null) { |
| 2177 | // Accumulate time to all active counters, scaled by the total |
| 2178 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2179 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | // Remove this timer from the active pool |
| 2181 | mTimerPool.remove(this); |
| 2182 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | mNesting = 1; |
| 2184 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 2185 | mNesting = 0; |
| 2186 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | if (DEBUG && mType < 0) { |
| 2189 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2190 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2191 | + " mAcquireTime=" + mAcquireTime); |
| 2192 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2193 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2194 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | // If there was no change in the time, then discard this |
| 2196 | // count. A somewhat cheezy strategy, but hey. |
| 2197 | mCount--; |
| 2198 | } |
| 2199 | } |
| 2200 | } |
| 2201 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2202 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 2203 | if (mNesting > 0) { |
| 2204 | mNesting = 1; |
| 2205 | stopRunningLocked(elapsedRealtimeMs); |
| 2206 | } |
| 2207 | } |
| 2208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | // Update the total time for all other running Timers with the same type as this Timer |
| 2210 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2211 | private static long refreshTimersLocked(long batteryRealtime, |
| 2212 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2213 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | final int N = pool.size(); |
| 2215 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2216 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2217 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 2218 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2219 | final long myTime = heldTime / N; |
| 2220 | if (t == self) { |
| 2221 | selfTime = myTime; |
| 2222 | } |
| 2223 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2224 | } |
| 2225 | t.mUpdateTime = batteryRealtime; |
| 2226 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2227 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | } |
| 2229 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2230 | @Override |
| 2231 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2232 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 2233 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 2234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | return mTotalTime + (mNesting > 0 |
| 2236 | ? (curBatteryRealtime - mUpdateTime) |
| 2237 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 2238 | : 0); |
| 2239 | } |
| 2240 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2241 | @Override |
| 2242 | protected int computeCurrentCountLocked() { |
| 2243 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2246 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2247 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2248 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2249 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2250 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2251 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2252 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2253 | mAcquireTime = -1; // to ensure mCount isn't decreased to -1 if timer is stopped later. |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2254 | return canDetach; |
| 2255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2256 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2257 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2258 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2259 | super.detach(); |
| 2260 | if (mTimerPool != null) { |
| 2261 | mTimerPool.remove(this); |
| 2262 | } |
| 2263 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2264 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2265 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2266 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2267 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | mNesting = 0; |
| 2269 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2270 | |
| 2271 | /** |
| 2272 | * Set the mark so that we can query later for the total time the timer has |
| 2273 | * accumulated since this point. The timer can be running or not. |
| 2274 | * |
| 2275 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2276 | */ |
| 2277 | public void setMark(long elapsedRealtimeMs) { |
| 2278 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2279 | if (mNesting > 0) { |
| 2280 | // We are running. |
| 2281 | if (mTimerPool != null) { |
| 2282 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2283 | } else { |
| 2284 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2285 | mUpdateTime = batteryRealtime; |
| 2286 | } |
| 2287 | } |
| 2288 | mTimeBeforeMark = mTotalTime; |
| 2289 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2291 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2292 | /** |
| 2293 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2294 | * TimeBase is effectively a subset of the other. |
| 2295 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2296 | public static class DualTimer extends DurationTimer { |
| 2297 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2298 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2299 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2300 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2301 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2302 | // determined by a subTimeBase. It is NOT pooled. |
| 2303 | private final DurationTimer mSubTimer; |
| 2304 | |
| 2305 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2306 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2307 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2308 | * The mSubTimer is based on the given subTimeBase. The mSubTimer is not pooled, even if |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2309 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2310 | */ |
| 2311 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2312 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2313 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2314 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2315 | } |
| 2316 | |
| 2317 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2318 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2319 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2320 | * The mSubTimer is based on the given subTimeBase. The mSubTimer is not pooled, even if |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2321 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2322 | */ |
| 2323 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2324 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2325 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2326 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2327 | } |
| 2328 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2329 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2330 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2331 | public DurationTimer getSubTimer() { |
| 2332 | return mSubTimer; |
| 2333 | } |
| 2334 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2335 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2336 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2337 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2338 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2339 | } |
| 2340 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2341 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2342 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2343 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2344 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2345 | } |
| 2346 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2347 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2348 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2349 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2350 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2351 | } |
| 2352 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2353 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2354 | public boolean reset(boolean detachIfReset) { |
| 2355 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2356 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2357 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2358 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2359 | return !active; |
| 2360 | } |
| 2361 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2362 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2363 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2364 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2365 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2368 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2369 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2370 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2371 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2372 | } |
| 2373 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2374 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2375 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2376 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2377 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2378 | } |
| 2379 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2380 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2381 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2382 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2383 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2388 | public abstract class OverflowArrayMap<T> { |
| 2389 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2390 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2391 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2392 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2393 | T mCurOverflow; |
| 2394 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2395 | long mLastOverflowTime; |
| 2396 | long mLastOverflowFinishTime; |
| 2397 | long mLastClearTime; |
| 2398 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2399 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2400 | public OverflowArrayMap(int uid) { |
| 2401 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | public ArrayMap<String, T> getMap() { |
| 2405 | return mMap; |
| 2406 | } |
| 2407 | |
| 2408 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2409 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2410 | mMap.clear(); |
| 2411 | mCurOverflow = null; |
| 2412 | mActiveOverflow = null; |
| 2413 | } |
| 2414 | |
| 2415 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2416 | if (name == null) { |
| 2417 | name = ""; |
| 2418 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2419 | mMap.put(name, obj); |
| 2420 | if (OVERFLOW_NAME.equals(name)) { |
| 2421 | mCurOverflow = obj; |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2426 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2427 | if (mActiveOverflow != null) { |
| 2428 | if (mActiveOverflow.size() == 0) { |
| 2429 | mActiveOverflow = null; |
| 2430 | } |
| 2431 | } |
| 2432 | if (mActiveOverflow == null) { |
| 2433 | // There is no currently active overflow, so we should no longer have |
| 2434 | // an overflow entry. |
| 2435 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2436 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2437 | + mMap.get(OVERFLOW_NAME)); |
| 2438 | mMap.remove(OVERFLOW_NAME); |
| 2439 | } |
| 2440 | mCurOverflow = null; |
| 2441 | } else { |
| 2442 | // There is currently active overflow, so we should still have an overflow entry. |
| 2443 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2444 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2445 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2451 | if (name == null) { |
| 2452 | name = ""; |
| 2453 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2454 | T obj = mMap.get(name); |
| 2455 | if (obj != null) { |
| 2456 | return obj; |
| 2457 | } |
| 2458 | |
| 2459 | // No object exists for the given name, but do we currently have it |
| 2460 | // running as part of the overflow? |
| 2461 | if (mActiveOverflow != null) { |
| 2462 | MutableInt over = mActiveOverflow.get(name); |
| 2463 | if (over != null) { |
| 2464 | // We are already actively counting this name in the overflow object. |
| 2465 | obj = mCurOverflow; |
| 2466 | if (obj == null) { |
| 2467 | // Shouldn't be here, but we'll try to recover. |
| 2468 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2469 | obj = mCurOverflow = instantiateObject(); |
| 2470 | mMap.put(OVERFLOW_NAME, obj); |
| 2471 | } |
| 2472 | over.value++; |
| 2473 | return obj; |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | // No object exists for given name nor in the overflow; we need to make |
| 2478 | // a new one. |
| 2479 | final int N = mMap.size(); |
| 2480 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2481 | // Went over the limit on number of objects to track; this one goes |
| 2482 | // in to the overflow. |
| 2483 | obj = mCurOverflow; |
| 2484 | if (obj == null) { |
| 2485 | // Need to start overflow now... |
| 2486 | obj = mCurOverflow = instantiateObject(); |
| 2487 | mMap.put(OVERFLOW_NAME, obj); |
| 2488 | } |
| 2489 | if (mActiveOverflow == null) { |
| 2490 | mActiveOverflow = new ArrayMap<>(); |
| 2491 | } |
| 2492 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2493 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2494 | return obj; |
| 2495 | } |
| 2496 | |
| 2497 | // Normal case where we just need to make a new object. |
| 2498 | obj = instantiateObject(); |
| 2499 | mMap.put(name, obj); |
| 2500 | return obj; |
| 2501 | } |
| 2502 | |
| 2503 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2504 | if (name == null) { |
| 2505 | name = ""; |
| 2506 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2507 | T obj = mMap.get(name); |
| 2508 | if (obj != null) { |
| 2509 | return obj; |
| 2510 | } |
| 2511 | |
| 2512 | // No object exists for the given name, but do we currently have it |
| 2513 | // running as part of the overflow? |
| 2514 | if (mActiveOverflow != null) { |
| 2515 | MutableInt over = mActiveOverflow.get(name); |
| 2516 | if (over != null) { |
| 2517 | // We are already actively counting this name in the overflow object. |
| 2518 | obj = mCurOverflow; |
| 2519 | if (obj != null) { |
| 2520 | over.value--; |
| 2521 | if (over.value <= 0) { |
| 2522 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2523 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2524 | } |
| 2525 | return obj; |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | // Huh, they are stopping an active operation but we can't find one! |
| 2531 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2532 | StringBuilder sb = new StringBuilder(); |
| 2533 | sb.append("Unable to find object for "); |
| 2534 | sb.append(name); |
| 2535 | sb.append(" in uid "); |
| 2536 | sb.append(mUid); |
| 2537 | sb.append(" mapsize="); |
| 2538 | sb.append(mMap.size()); |
| 2539 | sb.append(" activeoverflow="); |
| 2540 | sb.append(mActiveOverflow); |
| 2541 | sb.append(" curoverflow="); |
| 2542 | sb.append(mCurOverflow); |
| 2543 | long now = SystemClock.elapsedRealtime(); |
| 2544 | if (mLastOverflowTime != 0) { |
| 2545 | sb.append(" lastOverflowTime="); |
| 2546 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2547 | } |
| 2548 | if (mLastOverflowFinishTime != 0) { |
| 2549 | sb.append(" lastOverflowFinishTime="); |
| 2550 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2551 | } |
| 2552 | if (mLastClearTime != 0) { |
| 2553 | sb.append(" lastClearTime="); |
| 2554 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2555 | } |
| 2556 | if (mLastCleanupTime != 0) { |
| 2557 | sb.append(" lastCleanupTime="); |
| 2558 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2559 | } |
| 2560 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2561 | return null; |
| 2562 | } |
| 2563 | |
| 2564 | public abstract T instantiateObject(); |
| 2565 | } |
| 2566 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2567 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2568 | implements Parcelable { |
| 2569 | private final LongSamplingCounter mIdleTimeMillis; |
| 2570 | private final LongSamplingCounter mRxTimeMillis; |
| 2571 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2572 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2573 | |
| 2574 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2575 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 2576 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2577 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2578 | for (int i = 0; i < numTxStates; i++) { |
| 2579 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2580 | } |
| 2581 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2582 | } |
| 2583 | |
| 2584 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2585 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2586 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2587 | final int recordedTxStates = in.readInt(); |
| 2588 | if (recordedTxStates != numTxStates) { |
| 2589 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2590 | } |
| 2591 | |
| 2592 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2593 | for (int i = 0; i < numTxStates; i++) { |
| 2594 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2595 | } |
| 2596 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2597 | } |
| 2598 | |
| 2599 | public void readSummaryFromParcel(Parcel in) { |
| 2600 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 2601 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2602 | final int recordedTxStates = in.readInt(); |
| 2603 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2604 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2605 | } |
| 2606 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2607 | counter.readSummaryFromParcelLocked(in); |
| 2608 | } |
| 2609 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2610 | } |
| 2611 | |
| 2612 | @Override |
| 2613 | public int describeContents() { |
| 2614 | return 0; |
| 2615 | } |
| 2616 | |
| 2617 | public void writeSummaryToParcel(Parcel dest) { |
| 2618 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2619 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2620 | dest.writeInt(mTxTimeMillis.length); |
| 2621 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2622 | counter.writeSummaryFromParcelLocked(dest); |
| 2623 | } |
| 2624 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2625 | } |
| 2626 | |
| 2627 | @Override |
| 2628 | public void writeToParcel(Parcel dest, int flags) { |
| 2629 | mIdleTimeMillis.writeToParcel(dest); |
| 2630 | mRxTimeMillis.writeToParcel(dest); |
| 2631 | dest.writeInt(mTxTimeMillis.length); |
| 2632 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2633 | counter.writeToParcel(dest); |
| 2634 | } |
| 2635 | mPowerDrainMaMs.writeToParcel(dest); |
| 2636 | } |
| 2637 | |
| 2638 | public void reset(boolean detachIfReset) { |
| 2639 | mIdleTimeMillis.reset(detachIfReset); |
| 2640 | mRxTimeMillis.reset(detachIfReset); |
| 2641 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2642 | counter.reset(detachIfReset); |
| 2643 | } |
| 2644 | mPowerDrainMaMs.reset(detachIfReset); |
| 2645 | } |
| 2646 | |
| 2647 | public void detach() { |
| 2648 | mIdleTimeMillis.detach(); |
| 2649 | mRxTimeMillis.detach(); |
| 2650 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2651 | counter.detach(); |
| 2652 | } |
| 2653 | mPowerDrainMaMs.detach(); |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2658 | * milliseconds. |
| 2659 | */ |
| 2660 | @Override |
| 2661 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2662 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | /** |
| 2666 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2667 | * milliseconds. |
| 2668 | */ |
| 2669 | @Override |
| 2670 | public LongSamplingCounter getRxTimeCounter() { |
| 2671 | return mRxTimeMillis; |
| 2672 | } |
| 2673 | |
| 2674 | /** |
| 2675 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2676 | * milliseconds. |
| 2677 | */ |
| 2678 | @Override |
| 2679 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2680 | return mTxTimeMillis; |
| 2681 | } |
| 2682 | |
| 2683 | /** |
| 2684 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2685 | */ |
| 2686 | @Override |
| 2687 | public LongSamplingCounter getPowerCounter() { |
| 2688 | return mPowerDrainMaMs; |
| 2689 | } |
| 2690 | } |
| 2691 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2692 | /** Get Resource Power Manager stats. Create a new one if it doesn't already exist. */ |
| 2693 | public SamplingTimer getRpmTimerLocked(String name) { |
| 2694 | SamplingTimer rpmt = mRpmStats.get(name); |
| 2695 | if (rpmt == null) { |
| 2696 | rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2697 | mRpmStats.put(name, rpmt); |
| 2698 | } |
| 2699 | return rpmt; |
| 2700 | } |
| 2701 | |
| 2702 | /** Get Screen-off Resource Power Manager stats. Create new one if it doesn't already exist. */ |
| 2703 | public SamplingTimer getScreenOffRpmTimerLocked(String name) { |
| 2704 | SamplingTimer rpmt = mScreenOffRpmStats.get(name); |
| 2705 | if (rpmt == null) { |
| 2706 | rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
| 2707 | mScreenOffRpmStats.put(name, rpmt); |
| 2708 | } |
| 2709 | return rpmt; |
| 2710 | } |
| 2711 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2712 | /* |
| 2713 | * Get the wakeup reason counter, and create a new one if one |
| 2714 | * doesn't already exist. |
| 2715 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2716 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2717 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2718 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2719 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2720 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2721 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2722 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2725 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2726 | * 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] | 2727 | * doesn't already exist. |
| 2728 | */ |
| 2729 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2730 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2731 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2732 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2733 | mKernelWakelockStats.put(name, kwlt); |
| 2734 | } |
| 2735 | return kwlt; |
| 2736 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2737 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 2738 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 2739 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 2740 | if (kmt == null) { |
| 2741 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2742 | mKernelMemoryStats.put(bucket, kmt); |
| 2743 | } |
| 2744 | return kmt; |
| 2745 | } |
| 2746 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2747 | private int writeHistoryTag(HistoryTag tag) { |
| 2748 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2749 | int idx; |
| 2750 | if (idxObj != null) { |
| 2751 | idx = idxObj; |
| 2752 | } else { |
| 2753 | idx = mNextHistoryTagIdx; |
| 2754 | HistoryTag key = new HistoryTag(); |
| 2755 | key.setTo(tag); |
| 2756 | tag.poolIdx = idx; |
| 2757 | mHistoryTagPool.put(key, idx); |
| 2758 | mNextHistoryTagIdx++; |
| 2759 | mNumHistoryTagChars += key.string.length() + 1; |
| 2760 | } |
| 2761 | return idx; |
| 2762 | } |
| 2763 | |
| 2764 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2765 | tag.string = mReadHistoryStrings[index]; |
| 2766 | tag.uid = mReadHistoryUids[index]; |
| 2767 | tag.poolIdx = index; |
| 2768 | } |
| 2769 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2770 | /* |
| 2771 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 2772 | |
| 2773 | There is always the first token, which may contain the delta time, or an indicator of |
| 2774 | the length of the time (int or long) following this token. |
| 2775 | |
| 2776 | First token: always present, |
| 2777 | 31 23 15 7 0 |
| 2778 | â–ˆM|L|K|J|I|H|G|Fâ–ˆE|D|C|B|A|T|T|Tâ–ˆT|T|T|T|T|T|T|Tâ–ˆT|T|T|T|T|T|T|Tâ–ˆ |
| 2779 | |
| 2780 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 2781 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 2782 | delta time. |
| 2783 | A: battery level changed and an int follows with battery data. |
| 2784 | B: state changed and an int follows with state change data. |
| 2785 | C: state2 has changed and an int follows with state2 change data. |
| 2786 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 2787 | E: event data has changed and an event struct follows. |
| 2788 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 2789 | G: state flag denoting that the mobile radio was active. |
| 2790 | H: state flag denoting that the wifi radio was active. |
| 2791 | I: state flag denoting that a wifi scan occurred. |
| 2792 | J: state flag denoting that a wifi full lock was held. |
| 2793 | K: state flag denoting that the gps was on. |
| 2794 | L: state flag denoting that a wakelock was held. |
| 2795 | M: state flag denoting that the cpu was running. |
| 2796 | |
| 2797 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 2798 | with the time delta. |
| 2799 | |
| 2800 | Battery level int: if A in the first token is set, |
| 2801 | 31 23 15 7 0 |
| 2802 | â–ˆL|L|L|L|L|L|L|Tâ–ˆT|T|T|T|T|T|T|Tâ–ˆT|V|V|V|V|V|V|Vâ–ˆV|V|V|V|V|V|V|Dâ–ˆ |
| 2803 | |
| 2804 | D: indicates that extra history details follow. |
| 2805 | V: the battery voltage. |
| 2806 | T: the battery temperature. |
| 2807 | L: the battery level (out of 100). |
| 2808 | |
| 2809 | State change int: if B in the first token is set, |
| 2810 | 31 23 15 7 0 |
| 2811 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 2812 | |
| 2813 | A: wifi multicast was on. |
| 2814 | B: battery was plugged in. |
| 2815 | C: screen was on. |
| 2816 | D: phone was scanning for signal. |
| 2817 | E: audio was on. |
| 2818 | F: a sensor was active. |
| 2819 | |
| 2820 | State2 change int: if C in the first token is set, |
| 2821 | 31 23 15 7 0 |
| 2822 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 2823 | |
| 2824 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 2825 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 2826 | C: a bluetooth scan was active. |
| 2827 | D: the camera was active. |
| 2828 | E: bluetooth was on. |
| 2829 | F: a phone call was active. |
| 2830 | G: the device was charging. |
| 2831 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 2832 | I: the flashlight was on. |
| 2833 | J: wifi was on. |
| 2834 | K: wifi was running. |
| 2835 | L: video was playing. |
| 2836 | M: power save mode was on. |
| 2837 | |
| 2838 | Wakelock/wakereason struct: if D in the first token is set, |
| 2839 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 2840 | |
| 2841 | Event struct: if E in the first token is set, |
| 2842 | TODO(adamlesinski): describe the event struct. |
| 2843 | |
| 2844 | History step details struct: if D in the battery level int is set, |
| 2845 | TODO(adamlesinski): describe the history step details struct. |
| 2846 | |
| 2847 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 2848 | in coulombs follows. |
| 2849 | */ |
| 2850 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2851 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2852 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2853 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2854 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2855 | 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] | 2856 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2857 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2858 | // Flag in delta int: a new full state and battery status int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2859 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2860 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2861 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2862 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2863 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2864 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2865 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2866 | // Flag in delta int: contains the battery charge count in uAh. |
| 2867 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2868 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2869 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2870 | |
| 2871 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2872 | // the state int that have been packed in to the first delta int. They must fit |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2873 | // in STATE_BATTERY_MASK. |
| 2874 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2875 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2876 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2877 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2878 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2879 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2880 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2881 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2882 | // We use the low bit of the battery state int to indicate that we have full details |
| 2883 | // from a battery level change. |
| 2884 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2885 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2886 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2887 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2888 | dest.writeInt(DELTA_TIME_ABS); |
| 2889 | cur.writeToParcel(dest, 0); |
| 2890 | return; |
| 2891 | } |
| 2892 | |
| 2893 | final long deltaTime = cur.time - last.time; |
| 2894 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2895 | final int lastStateInt = buildStateInt(last); |
| 2896 | |
| 2897 | int deltaTimeToken; |
| 2898 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2899 | deltaTimeToken = DELTA_TIME_LONG; |
| 2900 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2901 | deltaTimeToken = DELTA_TIME_INT; |
| 2902 | } else { |
| 2903 | deltaTimeToken = (int)deltaTime; |
| 2904 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2905 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2906 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2907 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2908 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2909 | || mLastHistoryStepDetails == null; |
| 2910 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2911 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2912 | if (batteryLevelIntChanged) { |
| 2913 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2914 | } |
| 2915 | final int stateInt = buildStateInt(cur); |
| 2916 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2917 | if (stateIntChanged) { |
| 2918 | firstToken |= DELTA_STATE_FLAG; |
| 2919 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2920 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2921 | if (state2IntChanged) { |
| 2922 | firstToken |= DELTA_STATE2_FLAG; |
| 2923 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2924 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2925 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2926 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2927 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2928 | firstToken |= DELTA_EVENT_FLAG; |
| 2929 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2930 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2931 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 2932 | if (batteryChargeChanged) { |
| 2933 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2934 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2935 | dest.writeInt(firstToken); |
| 2936 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2937 | + " deltaTime=" + deltaTime); |
| 2938 | |
| 2939 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2940 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2941 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2942 | dest.writeInt((int)deltaTime); |
| 2943 | } else { |
| 2944 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2945 | dest.writeLong(deltaTime); |
| 2946 | } |
| 2947 | } |
| 2948 | if (batteryLevelIntChanged) { |
| 2949 | dest.writeInt(batteryLevelInt); |
| 2950 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2951 | + Integer.toHexString(batteryLevelInt) |
| 2952 | + " batteryLevel=" + cur.batteryLevel |
| 2953 | + " batteryTemp=" + cur.batteryTemperature |
| 2954 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2955 | } |
| 2956 | if (stateIntChanged) { |
| 2957 | dest.writeInt(stateInt); |
| 2958 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2959 | + Integer.toHexString(stateInt) |
| 2960 | + " batteryStatus=" + cur.batteryStatus |
| 2961 | + " batteryHealth=" + cur.batteryHealth |
| 2962 | + " batteryPlugType=" + cur.batteryPlugType |
| 2963 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2964 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2965 | if (state2IntChanged) { |
| 2966 | dest.writeInt(cur.states2); |
| 2967 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2968 | + Integer.toHexString(cur.states2)); |
| 2969 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2970 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2971 | int wakeLockIndex; |
| 2972 | int wakeReasonIndex; |
| 2973 | if (cur.wakelockTag != null) { |
| 2974 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2975 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2976 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2977 | } else { |
| 2978 | wakeLockIndex = 0xffff; |
| 2979 | } |
| 2980 | if (cur.wakeReasonTag != null) { |
| 2981 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2982 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2983 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2984 | } else { |
| 2985 | wakeReasonIndex = 0xffff; |
| 2986 | } |
| 2987 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2988 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2989 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2990 | int index = writeHistoryTag(cur.eventTag); |
| 2991 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2992 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2993 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2994 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2995 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2996 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2997 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 2998 | if (mPlatformIdleStateCallback != null) { |
| 2999 | mCurHistoryStepDetails.statPlatformIdleState = |
| 3000 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 3001 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 3002 | mCurHistoryStepDetails.statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 3003 | |
| 3004 | mCurHistoryStepDetails.statSubsystemPowerState = |
| 3005 | mPlatformIdleStateCallback.getSubsystemLowPowerStats(); |
| 3006 | if (DEBUG) Slog.i(TAG, "WRITE SubsystemPowerState:" + |
| 3007 | mCurHistoryStepDetails.statSubsystemPowerState); |
| 3008 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3009 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3010 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 3011 | if (includeStepDetails != 0) { |
| 3012 | mCurHistoryStepDetails.writeToParcel(dest); |
| 3013 | } |
| 3014 | cur.stepDetails = mCurHistoryStepDetails; |
| 3015 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 3016 | } else { |
| 3017 | cur.stepDetails = null; |
| 3018 | } |
| 3019 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 3020 | mLastHistoryStepDetails = null; |
| 3021 | } |
| 3022 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3023 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3024 | if (batteryChargeChanged) { |
| 3025 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 3026 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3027 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | private int buildBatteryLevelInt(HistoryItem h) { |
| 3031 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3032 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 3033 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 3034 | } |
| 3035 | |
| 3036 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 3037 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 3038 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 3039 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3043 | int plugType = 0; |
| 3044 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 3045 | plugType = 1; |
| 3046 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 3047 | plugType = 2; |
| 3048 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 3049 | plugType = 3; |
| 3050 | } |
| 3051 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 3052 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 3053 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3054 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3055 | } |
| 3056 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3057 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 3058 | final HistoryStepDetails last) { |
| 3059 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 3060 | |
| 3061 | // Perform a CPU update right after we do this collection, so we have started |
| 3062 | // collecting good data for the next step. |
| 3063 | requestImmediateCpuUpdate(); |
| 3064 | |
| 3065 | if (last == null) { |
| 3066 | // We are not generating a delta, so all we need to do is reset the stats |
| 3067 | // we will later be doing a delta from. |
| 3068 | final int NU = mUidStats.size(); |
| 3069 | for (int i=0; i<NU; i++) { |
| 3070 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3071 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3072 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3073 | } |
| 3074 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3075 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3076 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3077 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3078 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3079 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3080 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3081 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3082 | tmp.clear(); |
| 3083 | return; |
| 3084 | } |
| 3085 | if (DEBUG) { |
| 3086 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 3087 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 3088 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 3089 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 3090 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 3091 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 3092 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 3093 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 3094 | } |
| 3095 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 3096 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 3097 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 3098 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 3099 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 3100 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 3101 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 3102 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 3103 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 3104 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 3105 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 3106 | final int NU = mUidStats.size(); |
| 3107 | for (int i=0; i<NU; i++) { |
| 3108 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3109 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 3110 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 3111 | final int totalTime = totalUTime + totalSTime; |
| 3112 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3113 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3114 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 3115 | continue; |
| 3116 | } |
| 3117 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 3118 | out.appCpuUid3 = uid.mUid; |
| 3119 | out.appCpuUTime3 = totalUTime; |
| 3120 | out.appCpuSTime3 = totalSTime; |
| 3121 | } else { |
| 3122 | out.appCpuUid3 = out.appCpuUid2; |
| 3123 | out.appCpuUTime3 = out.appCpuUTime2; |
| 3124 | out.appCpuSTime3 = out.appCpuSTime2; |
| 3125 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 3126 | out.appCpuUid2 = uid.mUid; |
| 3127 | out.appCpuUTime2 = totalUTime; |
| 3128 | out.appCpuSTime2 = totalSTime; |
| 3129 | } else { |
| 3130 | out.appCpuUid2 = out.appCpuUid1; |
| 3131 | out.appCpuUTime2 = out.appCpuUTime1; |
| 3132 | out.appCpuSTime2 = out.appCpuSTime1; |
| 3133 | out.appCpuUid1 = uid.mUid; |
| 3134 | out.appCpuUTime1 = totalUTime; |
| 3135 | out.appCpuSTime1 = totalSTime; |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3140 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3141 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3142 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3143 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3144 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3145 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3146 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3147 | } |
| 3148 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3149 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 3150 | int firstToken = src.readInt(); |
| 3151 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3152 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3153 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3154 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3155 | + " deltaTimeToken=" + deltaTimeToken); |
| 3156 | |
| 3157 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 3158 | cur.time += deltaTimeToken; |
| 3159 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 3160 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3161 | cur.numReadInts += 2; |
| 3162 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3163 | cur.readFromParcel(src); |
| 3164 | return; |
| 3165 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 3166 | int delta = src.readInt(); |
| 3167 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3168 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3169 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3170 | } else { |
| 3171 | long delta = src.readLong(); |
| 3172 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3173 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3174 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3175 | } |
| 3176 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3177 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3178 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3179 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3180 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3181 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3182 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 3183 | + Integer.toHexString(batteryLevelInt) |
| 3184 | + " batteryLevel=" + cur.batteryLevel |
| 3185 | + " batteryTemp=" + cur.batteryTemperature |
| 3186 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3187 | } else { |
| 3188 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 3192 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3193 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3194 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 3195 | & STATE_BATTERY_STATUS_MASK); |
| 3196 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 3197 | & STATE_BATTERY_HEALTH_MASK); |
| 3198 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 3199 | & STATE_BATTERY_PLUG_MASK); |
| 3200 | switch (cur.batteryPlugType) { |
| 3201 | case 1: |
| 3202 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 3203 | break; |
| 3204 | case 2: |
| 3205 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 3206 | break; |
| 3207 | case 3: |
| 3208 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 3209 | break; |
| 3210 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3211 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3212 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 3213 | + Integer.toHexString(stateInt) |
| 3214 | + " batteryStatus=" + cur.batteryStatus |
| 3215 | + " batteryHealth=" + cur.batteryHealth |
| 3216 | + " batteryPlugType=" + cur.batteryPlugType |
| 3217 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3218 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3219 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3220 | } |
| 3221 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3222 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 3223 | cur.states2 = src.readInt(); |
| 3224 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 3225 | + Integer.toHexString(cur.states2)); |
| 3226 | } |
| 3227 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3228 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3229 | int indexes = src.readInt(); |
| 3230 | int wakeLockIndex = indexes&0xffff; |
| 3231 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 3232 | if (wakeLockIndex != 0xffff) { |
| 3233 | cur.wakelockTag = cur.localWakelockTag; |
| 3234 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 3235 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3236 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3237 | } else { |
| 3238 | cur.wakelockTag = null; |
| 3239 | } |
| 3240 | if (wakeReasonIndex != 0xffff) { |
| 3241 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3242 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 3243 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3244 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3245 | } else { |
| 3246 | cur.wakeReasonTag = null; |
| 3247 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3248 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3249 | } else { |
| 3250 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3251 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3252 | } |
| 3253 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3254 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3255 | cur.eventTag = cur.localEventTag; |
| 3256 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3257 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3258 | final int index = ((codeAndIndex>>16)&0xffff); |
| 3259 | readHistoryTag(index, cur.eventTag); |
| 3260 | cur.numReadInts += 1; |
| 3261 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 3262 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3263 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3264 | } else { |
| 3265 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3266 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3267 | |
| 3268 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 3269 | cur.stepDetails = mReadHistoryStepDetails; |
| 3270 | cur.stepDetails.readFromParcel(src); |
| 3271 | } else { |
| 3272 | cur.stepDetails = null; |
| 3273 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3274 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3275 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 3276 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3277 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3278 | } |
| 3279 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3280 | @Override |
| 3281 | public void commitCurrentHistoryBatchLocked() { |
| 3282 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 3283 | } |
| 3284 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3285 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3286 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3287 | return; |
| 3288 | } |
| 3289 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3290 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3291 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 3292 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3293 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3294 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3295 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 3296 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3297 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 3298 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3299 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3300 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3301 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3302 | && (diffStates2&lastDiffStates2) == 0 |
| 3303 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3304 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3305 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3306 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3307 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3308 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3309 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3310 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3311 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3312 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3313 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3314 | // 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] | 3315 | // 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] | 3316 | // as long as no bit has changed both between now and the last entry, as |
| 3317 | // well as the last entry and the one before it (so we capture any toggles). |
| 3318 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3319 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3320 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3321 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3322 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3323 | // If the last written history had a wakelock tag, we need to retain it. |
| 3324 | // Note that the condition above made sure that we aren't in a case where |
| 3325 | // both it and the current history item have a wakelock tag. |
| 3326 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3327 | cur.wakelockTag = cur.localWakelockTag; |
| 3328 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3329 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3330 | // If the last written history had a wake reason tag, we need to retain it. |
| 3331 | // Note that the condition above made sure that we aren't in a case where |
| 3332 | // both it and the current history item have a wakelock tag. |
| 3333 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3334 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3335 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3336 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3337 | // If the last written history had an event, we need to retain it. |
| 3338 | // Note that the condition above made sure that we aren't in a case where |
| 3339 | // both it and the current history item have an event. |
| 3340 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3341 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3342 | cur.eventTag = cur.localEventTag; |
| 3343 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3344 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3345 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3348 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3349 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3350 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3351 | // Clients can't deal with history buffers this large. This only |
| 3352 | // really happens when the device is on charger and interacted with |
| 3353 | // for long periods of time, like in retail mode. Since the device is |
| 3354 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3355 | // Reset the stats and mark that we overflowed. |
| 3356 | // b/32540341 |
| 3357 | resetAllStatsLocked(); |
| 3358 | |
| 3359 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3360 | // events. |
| 3361 | recordResetDueToOverflow = true; |
| 3362 | |
| 3363 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3364 | if (!mHistoryOverflow) { |
| 3365 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3366 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3367 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3368 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3371 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3372 | boolean writeAnyway = false; |
| 3373 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3374 | & mActiveHistoryStates; |
| 3375 | if (mHistoryLastWritten.states != curStates) { |
| 3376 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3377 | // forced to 0. |
| 3378 | int old = mActiveHistoryStates; |
| 3379 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3380 | writeAnyway |= old != mActiveHistoryStates; |
| 3381 | } |
| 3382 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3383 | & mActiveHistoryStates2; |
| 3384 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3385 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3386 | // forced to 0. |
| 3387 | int old = mActiveHistoryStates2; |
| 3388 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3389 | writeAnyway |= old != mActiveHistoryStates2; |
| 3390 | } |
| 3391 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3392 | // Once we've reached the maximum number of items, we only |
| 3393 | // record changes to the battery level and the most interesting states. |
| 3394 | // Once we've reached the maximum maximum number of items, we only |
| 3395 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3396 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3397 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3398 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3399 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3400 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3401 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3402 | return; |
| 3403 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3404 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3405 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3406 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3409 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3410 | // The history is currently empty; we need it to start with a time stamp. |
| 3411 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3412 | if (recordResetDueToOverflow) { |
| 3413 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
| 3414 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3415 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 3416 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3417 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3420 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 3421 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3422 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3423 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3424 | } |
| 3425 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3426 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3427 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3428 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3429 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3430 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3431 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3432 | cur.wakelockTag = null; |
| 3433 | cur.wakeReasonTag = null; |
| 3434 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3435 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3436 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3437 | + " now " + mHistoryBuffer.dataPosition() |
| 3438 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3441 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3442 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3443 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3444 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3445 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3446 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3447 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3448 | if (diffUptime < (diffElapsed-20)) { |
| 3449 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3450 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3451 | mHistoryAddTmp.wakelockTag = null; |
| 3452 | mHistoryAddTmp.wakeReasonTag = null; |
| 3453 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3454 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3455 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 3456 | } |
| 3457 | } |
| 3458 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3459 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3460 | mTrackRunningHistoryUptime = uptimeMs; |
| 3461 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 3462 | } |
| 3463 | |
| 3464 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 3465 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3466 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3467 | if (!USE_OLD_HISTORY) { |
| 3468 | return; |
| 3469 | } |
| 3470 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3471 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3472 | return; |
| 3473 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3474 | |
| 3475 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3476 | // and no states have since the last recorded entry changed and |
| 3477 | // are now resetting back to their original value, then just collapse |
| 3478 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3479 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3480 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3481 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3482 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3483 | // If the current is the same as the one before, then we no |
| 3484 | // longer need the entry. |
| 3485 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3486 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3487 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3488 | mHistoryLastEnd.next = null; |
| 3489 | mHistoryEnd.next = mHistoryCache; |
| 3490 | mHistoryCache = mHistoryEnd; |
| 3491 | mHistoryEnd = mHistoryLastEnd; |
| 3492 | mHistoryLastEnd = null; |
| 3493 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3494 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3495 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3496 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3497 | } |
| 3498 | return; |
| 3499 | } |
| 3500 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3501 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3502 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3503 | |
| 3504 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3505 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3506 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3509 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3510 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3511 | // record changes to the battery level and the most interesting states. |
| 3512 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3513 | // record changes to the battery level. |
| 3514 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3515 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3516 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3517 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3518 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3519 | return; |
| 3520 | } |
| 3521 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3522 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3523 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3524 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3525 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3526 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3527 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3528 | mHistoryCur.eventCode = code; |
| 3529 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3530 | mHistoryCur.eventTag.string = name; |
| 3531 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3532 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3535 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3536 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3537 | if (rec != null) { |
| 3538 | mHistoryCache = rec.next; |
| 3539 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3540 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3541 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3542 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3543 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3544 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3545 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3546 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3547 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3548 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3549 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3550 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3551 | if (mHistoryEnd != null) { |
| 3552 | mHistoryEnd.next = rec; |
| 3553 | mHistoryEnd = rec; |
| 3554 | } else { |
| 3555 | mHistory = mHistoryEnd = rec; |
| 3556 | } |
| 3557 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3558 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3559 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3560 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3561 | if (USE_OLD_HISTORY) { |
| 3562 | if (mHistory != null) { |
| 3563 | mHistoryEnd.next = mHistoryCache; |
| 3564 | mHistoryCache = mHistory; |
| 3565 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3566 | } |
| 3567 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3568 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3569 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3570 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3571 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3572 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3573 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3574 | |
| 3575 | mHistoryBuffer.setDataSize(0); |
| 3576 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3577 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3578 | mHistoryLastLastWritten.clear(); |
| 3579 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3580 | mHistoryTagPool.clear(); |
| 3581 | mNextHistoryTagIdx = 0; |
| 3582 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3583 | mHistoryBufferLastPos = -1; |
| 3584 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3585 | mActiveHistoryStates = 0xffffffff; |
| 3586 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3588 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3589 | public void updateTimeBasesLocked(boolean unplugged, int screenState, long uptime, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3590 | long realtime) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3591 | final boolean screenOff = isScreenOff(screenState) || isScreenDoze(screenState); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3592 | final boolean updateOnBatteryTimeBase = unplugged != mOnBatteryTimeBase.isRunning(); |
| 3593 | final boolean updateOnBatteryScreenOffTimeBase = |
| 3594 | (unplugged && screenOff) != mOnBatteryScreenOffTimeBase.isRunning(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3595 | |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3596 | if (updateOnBatteryScreenOffTimeBase || updateOnBatteryTimeBase) { |
| 3597 | if (updateOnBatteryScreenOffTimeBase) { |
| 3598 | updateKernelWakelocksLocked(); |
| 3599 | updateBatteryPropertiesLocked(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3600 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3601 | // This if{} is only necessary due to SCREEN_OFF_RPM_STATS_ENABLED, which exists because |
| 3602 | // updateRpmStatsLocked is too slow to run each screen change. When the speed is |
| 3603 | // improved, remove the surrounding if{}. |
| 3604 | if (SCREEN_OFF_RPM_STATS_ENABLED || updateOnBatteryTimeBase) { |
| 3605 | updateRpmStatsLocked(); // if either OnBattery or OnBatteryScreenOff timebase changes. |
| 3606 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3607 | if (DEBUG_ENERGY_CPU) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3608 | Slog.d(TAG, "Updating cpu time because screen is now " |
| 3609 | + Display.stateToString(screenState) |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3610 | + " and battery is " + (unplugged ? "on" : "off")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3611 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 3612 | updateCpuTimeLocked(); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3613 | |
| 3614 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3615 | if (updateOnBatteryTimeBase) { |
| 3616 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3617 | mUidStats.valueAt(i).updateOnBatteryBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3618 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3619 | } |
| 3620 | if (updateOnBatteryScreenOffTimeBase) { |
| 3621 | mOnBatteryScreenOffTimeBase.setRunning(unplugged && screenOff, uptime, realtime); |
| 3622 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3623 | mUidStats.valueAt(i).updateOnBatteryScreenOffBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3624 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | } |
| 3627 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3628 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3629 | private void updateBatteryPropertiesLocked() { |
| 3630 | try { |
| 3631 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 3632 | ServiceManager.getService("batteryproperties")); |
| 3633 | registrar.scheduleUpdate(); |
| 3634 | } catch (RemoteException e) { |
| 3635 | // Ignore. |
| 3636 | } |
| 3637 | } |
| 3638 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3639 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3640 | mIsolatedUids.put(isolatedUid, appUid); |
| 3641 | } |
| 3642 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3643 | /** |
| 3644 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3645 | * @see #removeIsolatedUidLocked(int) |
| 3646 | */ |
| 3647 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3648 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3649 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3650 | if (mExternalSync != null) { |
| 3651 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3652 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3653 | } |
| 3654 | } |
| 3655 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3656 | /** |
| 3657 | * This should only be called after the cpu times have been read. |
| 3658 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3659 | */ |
| 3660 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 3661 | mIsolatedUids.delete(isolatedUid); |
| 3662 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 3663 | mKernelUidCpuFreqTimeReader.removeUid(isolatedUid); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3666 | public int mapUid(int uid) { |
| 3667 | int isolated = mIsolatedUids.get(uid, -1); |
| 3668 | return isolated > 0 ? isolated : uid; |
| 3669 | } |
| 3670 | |
| 3671 | public void noteEventLocked(int code, String name, int uid) { |
| 3672 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3673 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3674 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3675 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3676 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3677 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3678 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3679 | } |
| 3680 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3681 | boolean ensureStartClockTime(final long currentTime) { |
| 3682 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3683 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3684 | // If the start clock time has changed by more than a year, then presumably |
| 3685 | // the previous time was completely bogus. So we are going to figure out a |
| 3686 | // new time based on how much time has elapsed since we started counting. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3687 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3688 | return true; |
| 3689 | } |
| 3690 | return false; |
| 3691 | } |
| 3692 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3693 | public void noteCurrentTimeChangedLocked() { |
| 3694 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3695 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3696 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3697 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3698 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3701 | public void noteProcessStartLocked(String name, int uid) { |
| 3702 | uid = mapUid(uid); |
| 3703 | if (isOnBattery()) { |
| 3704 | Uid u = getUidStatsLocked(uid); |
| 3705 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3706 | } |
| 3707 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3708 | return; |
| 3709 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3710 | if (!mRecordAllHistory) { |
| 3711 | return; |
| 3712 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3713 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3714 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3715 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 3716 | } |
| 3717 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3718 | public void noteProcessCrashLocked(String name, int uid) { |
| 3719 | uid = mapUid(uid); |
| 3720 | if (isOnBattery()) { |
| 3721 | Uid u = getUidStatsLocked(uid); |
| 3722 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | public void noteProcessAnrLocked(String name, int uid) { |
| 3727 | uid = mapUid(uid); |
| 3728 | if (isOnBattery()) { |
| 3729 | Uid u = getUidStatsLocked(uid); |
| 3730 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 3731 | } |
| 3732 | } |
| 3733 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3734 | public void noteUidProcessStateLocked(int uid, int state) { |
Amith Yamasani | fd3caf6 | 2017-07-26 11:48:35 -0700 | [diff] [blame] | 3735 | int parentUid = mapUid(uid); |
| 3736 | if (uid != parentUid) { |
| 3737 | // Isolated UIDs process state is already rolled up into parent, so no need to track |
| 3738 | // Otherwise the parent's process state will get downgraded incorrectly |
| 3739 | return; |
| 3740 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3741 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | public void noteProcessFinishLocked(String name, int uid) { |
| 3745 | uid = mapUid(uid); |
| 3746 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 3747 | return; |
| 3748 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3749 | if (!mRecordAllHistory) { |
| 3750 | return; |
| 3751 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3752 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3753 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3754 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3757 | public void noteSyncStartLocked(String name, int uid) { |
| 3758 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3759 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3760 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3761 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 3762 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 3763 | return; |
| 3764 | } |
| 3765 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 3766 | } |
| 3767 | |
| 3768 | public void noteSyncFinishLocked(String name, int uid) { |
| 3769 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3770 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3771 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3772 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 3773 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 3774 | return; |
| 3775 | } |
| 3776 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 3777 | } |
| 3778 | |
| 3779 | public void noteJobStartLocked(String name, int uid) { |
| 3780 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3781 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3782 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3783 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 3784 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 3785 | return; |
| 3786 | } |
| 3787 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 3788 | } |
| 3789 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3790 | public void noteJobFinishLocked(String name, int uid, int stopReason) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3791 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3792 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3793 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3794 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime, stopReason); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3795 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 3796 | return; |
| 3797 | } |
| 3798 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 3799 | } |
| 3800 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3801 | public void noteAlarmStartLocked(String name, int uid) { |
| 3802 | if (!mRecordAllHistory) { |
| 3803 | return; |
| 3804 | } |
| 3805 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3806 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3807 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3808 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 3809 | return; |
| 3810 | } |
| 3811 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 3812 | } |
| 3813 | |
| 3814 | public void noteAlarmFinishLocked(String name, int uid) { |
| 3815 | if (!mRecordAllHistory) { |
| 3816 | return; |
| 3817 | } |
| 3818 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3819 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3820 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3821 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 3822 | return; |
| 3823 | } |
| 3824 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 3825 | } |
| 3826 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3827 | private void requestWakelockCpuUpdate() { |
| 3828 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 3829 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 3830 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 3831 | } |
| 3832 | } |
| 3833 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3834 | private void requestImmediateCpuUpdate() { |
| 3835 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 3836 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 3837 | } |
| 3838 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3839 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 3840 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3841 | if (!enabled) { |
| 3842 | // Clear out any existing state. |
| 3843 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3844 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3845 | // Record the currently running processes as stopping, now that we are no |
| 3846 | // longer tracking them. |
| 3847 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3848 | HistoryItem.EVENT_PROC); |
| 3849 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3850 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3851 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3852 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3853 | SparseIntArray uids = ent.getValue(); |
| 3854 | for (int j=0; j<uids.size(); j++) { |
| 3855 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3856 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3857 | } |
| 3858 | } |
| 3859 | } |
| 3860 | } else { |
| 3861 | // Record the currently running processes as starting, now that we are tracking them. |
| 3862 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3863 | HistoryItem.EVENT_PROC); |
| 3864 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3865 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3866 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3867 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3868 | SparseIntArray uids = ent.getValue(); |
| 3869 | for (int j=0; j<uids.size(); j++) { |
| 3870 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3871 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3872 | } |
| 3873 | } |
| 3874 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3878 | public void setNoAutoReset(boolean enabled) { |
| 3879 | mNoAutoReset = enabled; |
| 3880 | } |
| 3881 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3882 | public void setPretendScreenOff(boolean pretendScreenOff) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3883 | if (mPretendScreenOff != pretendScreenOff) { |
| 3884 | mPretendScreenOff = pretendScreenOff; |
| 3885 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 3886 | } |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3887 | } |
| 3888 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3889 | private String mInitialAcquireWakeName; |
| 3890 | private int mInitialAcquireWakeUid = -1; |
| 3891 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3892 | 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] | 3893 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3894 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3895 | if (type == WAKE_TYPE_PARTIAL) { |
| 3896 | // Only care about partial wake locks, since full wake locks |
| 3897 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3898 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3899 | if (historyName == null) { |
| 3900 | historyName = name; |
| 3901 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3902 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3903 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3904 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3905 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3906 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3907 | } |
| 3908 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3909 | if (mWakeLockNesting == 0) { |
| 3910 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3911 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3912 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3913 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3914 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3915 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3916 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3917 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3918 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3919 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3920 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3921 | // We'll try to update the last tag. |
| 3922 | mHistoryLastWritten.wakelockTag = null; |
| 3923 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3924 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3925 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3926 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3927 | } |
| 3928 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3929 | } |
| 3930 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3931 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3932 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3933 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3934 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3935 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3936 | if (DEBUG_ENERGY_CPU) { |
| 3937 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3938 | } |
| 3939 | requestWakelockCpuUpdate(); |
| 3940 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3941 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3942 | } |
| 3943 | } |
| 3944 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3945 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3946 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3947 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3948 | if (type == WAKE_TYPE_PARTIAL) { |
| 3949 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3950 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3951 | if (historyName == null) { |
| 3952 | historyName = name; |
| 3953 | } |
| 3954 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3955 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3956 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3957 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3958 | } |
| 3959 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3960 | if (mWakeLockNesting == 0) { |
| 3961 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3962 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3963 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3964 | mInitialAcquireWakeName = null; |
| 3965 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3966 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3967 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3968 | } |
| 3969 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3970 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3971 | if (DEBUG_ENERGY_CPU) { |
| 3972 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3973 | } |
| 3974 | requestWakelockCpuUpdate(); |
| 3975 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3976 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3977 | } |
| 3978 | } |
| 3979 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3980 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3981 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3982 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3983 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3984 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3985 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3986 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3987 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3991 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3992 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3993 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3994 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3995 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3996 | // For correct semantics, we start the need worksources first, so that we won't |
| 3997 | // make inappropriate history items as if all wake locks went away and new ones |
| 3998 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3999 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4000 | for (int i=0; i<NN; i++) { |
| 4001 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4002 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4003 | } |
| 4004 | final int NO = ws.size(); |
| 4005 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4006 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4007 | } |
| 4008 | } |
| 4009 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4010 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4011 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4012 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4013 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4014 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4015 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4016 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4017 | } |
| 4018 | } |
| 4019 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4020 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
| 4021 | uid = mapUid(uid); |
| 4022 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4023 | final long uptime = mClocks.uptimeMillis(); |
| 4024 | if (historyName == null) { |
| 4025 | historyName = name; |
| 4026 | } |
| 4027 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 4028 | 0)) { |
| 4029 | return; |
| 4030 | } |
| 4031 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 4032 | historyName, uid); |
| 4033 | } |
| 4034 | |
| 4035 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
| 4036 | uid = mapUid(uid); |
| 4037 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4038 | final long uptime = mClocks.uptimeMillis(); |
| 4039 | if (historyName == null) { |
| 4040 | historyName = name; |
| 4041 | } |
| 4042 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 4043 | 0)) { |
| 4044 | return; |
| 4045 | } |
| 4046 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 4047 | historyName, uid); |
| 4048 | } |
| 4049 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4050 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 4051 | if (mLastWakeupReason != null) { |
| 4052 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4053 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 4054 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4055 | mLastWakeupReason = null; |
| 4056 | } |
| 4057 | } |
| 4058 | |
| 4059 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4060 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4061 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4062 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4063 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4064 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4065 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 4066 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4067 | mHistoryCur.wakeReasonTag.uid = 0; |
| 4068 | mLastWakeupReason = reason; |
| 4069 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4070 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4071 | } |
| 4072 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4073 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4074 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4075 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4076 | } |
| 4077 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4078 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 4079 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 4080 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4081 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 4082 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 4083 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 4084 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 4085 | mCurStepCpuUserTime += totalUTime; |
| 4086 | mCurStepCpuSystemTime += totalSTime; |
| 4087 | mCurStepStatUserTime += statUserTime; |
| 4088 | mCurStepStatSystemTime += statSystemTime; |
| 4089 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 4090 | mCurStepStatIrqTime += statIrqTime; |
| 4091 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 4092 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4095 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4096 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4097 | Uid u = mUidStats.get(uid); |
| 4098 | if (u != null) { |
| 4099 | u.mPids.remove(pid); |
| 4100 | } |
| 4101 | } |
| 4102 | |
| 4103 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4104 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4105 | Uid u = mUidStats.get(uid); |
| 4106 | if (u != null) { |
| 4107 | Uid.Pid p = u.mPids.get(pid); |
| 4108 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4109 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | return 0; |
| 4113 | } |
| 4114 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4115 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4116 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4117 | Uid u = mUidStats.get(uid); |
| 4118 | if (u != null) { |
| 4119 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 4120 | } |
| 4121 | } |
| 4122 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4123 | int mSensorNesting; |
| 4124 | |
| 4125 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4126 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4127 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4128 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4129 | if (mSensorNesting == 0) { |
| 4130 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4131 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 4132 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4133 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4134 | } |
| 4135 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4136 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4140 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4141 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4142 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4143 | mSensorNesting--; |
| 4144 | if (mSensorNesting == 0) { |
| 4145 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4146 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 4147 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4148 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4149 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4150 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4153 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4154 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4155 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4156 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4157 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4158 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4159 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4160 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4161 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 4162 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4163 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4164 | } |
| 4165 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4166 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4168 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4169 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4170 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4171 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4172 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4173 | mGpsNesting--; |
| 4174 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4175 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4176 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 4177 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4178 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4179 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4180 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4182 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4183 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4184 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4185 | |
| 4186 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 4187 | // original 4 are mapped to one of the originals. |
| 4188 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 4189 | switch (state) { |
| 4190 | case Display.STATE_VR: |
| 4191 | state = Display.STATE_ON; |
| 4192 | break; |
| 4193 | default: |
| 4194 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 4195 | break; |
| 4196 | } |
| 4197 | } |
| 4198 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4199 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4200 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4201 | final int oldState = mScreenState; |
| 4202 | mScreenState = state; |
| 4203 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 4204 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4205 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4206 | if (state != Display.STATE_UNKNOWN) { |
| 4207 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4208 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 4209 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 4210 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4211 | } else { |
| 4212 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 4213 | } |
| 4214 | } |
| 4215 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4216 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4217 | final long uptime = mClocks.uptimeMillis(); |
| 4218 | |
| 4219 | boolean updateHistory = false; |
| 4220 | if (isScreenDoze(state)) { |
| 4221 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4222 | mScreenDozeTimer.startRunningLocked(elapsedRealtime); |
| 4223 | updateHistory = true; |
| 4224 | } else if (isScreenDoze(oldState)) { |
| 4225 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4226 | mScreenDozeTimer.stopRunningLocked(elapsedRealtime); |
| 4227 | updateHistory = true; |
| 4228 | } |
| 4229 | if (isScreenOn(state)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4230 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4231 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 4232 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4233 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 4234 | if (mScreenBrightnessBin >= 0) { |
| 4235 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 4236 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4237 | updateHistory = true; |
| 4238 | } else if (isScreenOn(oldState)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4239 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4240 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 4241 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4242 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 4243 | if (mScreenBrightnessBin >= 0) { |
| 4244 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 4245 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4246 | updateHistory = true; |
| 4247 | } |
| 4248 | if (updateHistory) { |
| 4249 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen state to: " |
| 4250 | + Display.stateToString(state)); |
| 4251 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4252 | } |
| 4253 | if (isScreenOn(state)) { |
| 4254 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
| 4255 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
| 4256 | // Fake a wake lock, so we consider the device waked as long as the screen is on. |
| 4257 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 4258 | elapsedRealtime, uptime); |
| 4259 | } else if (isScreenOn(oldState)) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4260 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4261 | elapsedRealtime, uptime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4262 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4263 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4264 | } |
| 4265 | // Update discharge amounts. |
| 4266 | if (mOnBatteryInternal) { |
| 4267 | updateDischargeScreenLevelsLocked(oldState, state); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4268 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4269 | } |
| 4270 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4271 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4272 | public void noteScreenBrightnessLocked(int brightness) { |
| 4273 | // Bin the brightness. |
| 4274 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 4275 | if (bin < 0) bin = 0; |
| 4276 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 4277 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4278 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4279 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4280 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 4281 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4282 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 4283 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4284 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4285 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4286 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4287 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4288 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4289 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4290 | } |
| 4291 | mScreenBrightnessBin = bin; |
| 4292 | } |
| 4293 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4294 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4295 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4296 | if (mOnBatteryInternal) { |
| 4297 | uid = mapUid(uid); |
| 4298 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 4299 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4301 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4302 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4303 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4304 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4305 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 4306 | reason, reasonUid); |
| 4307 | } |
| 4308 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4309 | public void noteInteractiveLocked(boolean interactive) { |
| 4310 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4311 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4312 | mInteractive = interactive; |
| 4313 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 4314 | if (interactive) { |
| 4315 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 4316 | } else { |
| 4317 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 4318 | } |
| 4319 | } |
| 4320 | } |
| 4321 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4322 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4323 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4324 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4325 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 4326 | extra, type); |
| 4327 | mNumConnectivityChange++; |
| 4328 | } |
| 4329 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4330 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4331 | final long uptimeMillis, int uid) { |
| 4332 | uid = mapUid(uid); |
| 4333 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4334 | uid); |
| 4335 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 4336 | } |
| 4337 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4338 | /** |
| 4339 | * Updates the radio power state and returns true if an external stats collection should occur. |
| 4340 | */ |
| 4341 | public boolean noteMobileRadioPowerStateLocked(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4342 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4343 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4344 | if (mMobileRadioPowerState != powerState) { |
| 4345 | long realElapsedRealtimeMs; |
| 4346 | final boolean active = |
| 4347 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4348 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4349 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4350 | if (uid > 0) { |
| 4351 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4352 | } |
| 4353 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 4354 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4355 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4356 | } else { |
| 4357 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 4358 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4359 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 4360 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 4361 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4362 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4363 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 4364 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 4365 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4366 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4367 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4368 | } |
| 4369 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 4370 | + Integer.toHexString(mHistoryCur.states)); |
| 4371 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4372 | mMobileRadioPowerState = powerState; |
| 4373 | if (active) { |
| 4374 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 4375 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 4376 | } else { |
| 4377 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4378 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4379 | // Tell the caller to collect radio network/power stats. |
| 4380 | return true; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4381 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4382 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4383 | return false; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4384 | } |
| 4385 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4386 | public void notePowerSaveModeLocked(boolean enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4387 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4388 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 4389 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 4390 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4391 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4392 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4393 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4394 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4395 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4396 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4397 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4398 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4399 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4400 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4401 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4402 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4403 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4404 | } |
| 4405 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4406 | } |
| 4407 | } |
| 4408 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4409 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4410 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4411 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4412 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4413 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4414 | // We don't go out of general idling mode until explicitly taken out of |
| 4415 | // device idle through going active or significant motion. |
| 4416 | nowIdling = true; |
| 4417 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4418 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 4419 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 4420 | // We don't go out of general light idling mode until explicitly taken out of |
| 4421 | // device idle through going active or significant motion. |
| 4422 | nowLightIdling = true; |
| 4423 | } |
| 4424 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 4425 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 4426 | activeReason, activeUid); |
| 4427 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4428 | if (mDeviceIdling != nowIdling) { |
| 4429 | mDeviceIdling = nowIdling; |
| 4430 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 4431 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 4432 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4433 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4434 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 4435 | } else { |
| 4436 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 4437 | } |
| 4438 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4439 | if (mDeviceLightIdling != nowLightIdling) { |
| 4440 | mDeviceLightIdling = nowLightIdling; |
| 4441 | if (nowLightIdling) { |
| 4442 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4443 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4444 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4445 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4446 | } |
| 4447 | if (mDeviceIdleMode != mode) { |
| 4448 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 4449 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 4450 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 4451 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4452 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4453 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 4454 | mLastIdleTimeStart = elapsedRealtime; |
| 4455 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 4456 | if (lastDuration > mLongestLightIdleTime) { |
| 4457 | mLongestLightIdleTime = lastDuration; |
| 4458 | } |
| 4459 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4460 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4461 | if (lastDuration > mLongestFullIdleTime) { |
| 4462 | mLongestFullIdleTime = lastDuration; |
| 4463 | } |
| 4464 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 4465 | } |
| 4466 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 4467 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4468 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4469 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 4470 | } |
| 4471 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4472 | } |
| 4473 | } |
| 4474 | |
| 4475 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4476 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4477 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4478 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 4479 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4480 | PackageChange pc = new PackageChange(); |
| 4481 | pc.mPackageName = pkgName; |
| 4482 | pc.mUpdate = true; |
| 4483 | pc.mVersionCode = versionCode; |
| 4484 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4488 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4489 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4490 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 4491 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4492 | PackageChange pc = new PackageChange(); |
| 4493 | pc.mPackageName = pkgName; |
| 4494 | pc.mUpdate = true; |
| 4495 | addPackageChange(pc); |
| 4496 | } |
| 4497 | |
| 4498 | private void addPackageChange(PackageChange pc) { |
| 4499 | if (mDailyPackageChanges == null) { |
| 4500 | mDailyPackageChanges = new ArrayList<>(); |
| 4501 | } |
| 4502 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4503 | } |
| 4504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | public void notePhoneOnLocked() { |
| 4506 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4507 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4508 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4509 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4510 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 4511 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4512 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4514 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
| 4516 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | public void notePhoneOffLocked() { |
| 4519 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4520 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4521 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4522 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4523 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 4524 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4525 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4527 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4528 | } |
| 4529 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4530 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4531 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4532 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4533 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4534 | if (i == except) { |
| 4535 | continue; |
| 4536 | } |
| 4537 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4538 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4539 | } |
| 4540 | } |
| 4541 | } |
| 4542 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4543 | private int fixPhoneServiceState(int state, int signalBin) { |
| 4544 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 4545 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4546 | // to infer that we are scanning from other data. |
| 4547 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4548 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4549 | state = ServiceState.STATE_IN_SERVICE; |
| 4550 | } |
| 4551 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4552 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4553 | return state; |
| 4554 | } |
| 4555 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4556 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4557 | boolean scanning = false; |
| 4558 | boolean newHistory = false; |
| 4559 | |
| 4560 | mPhoneServiceStateRaw = state; |
| 4561 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4562 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 4563 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4564 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4565 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4566 | |
| 4567 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 4568 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4569 | // to infer that we are scanning from other data. |
| 4570 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4571 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4572 | state = ServiceState.STATE_IN_SERVICE; |
| 4573 | } |
| 4574 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4575 | |
| 4576 | // If the phone is powered off, stop all timers. |
| 4577 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4578 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4579 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4580 | // If we are in service, make sure the correct signal string timer is running. |
| 4581 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 4582 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4583 | |
| 4584 | // If we're out of service, we are in the lowest signal strength |
| 4585 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4586 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4587 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4588 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4589 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4590 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4591 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4592 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 4593 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4594 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4595 | } |
| 4596 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4597 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4598 | if (!scanning) { |
| 4599 | // If we are no longer scanning, then stop the scanning timer. |
| 4600 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 4601 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 4602 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 4603 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4604 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4605 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4609 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4610 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 4611 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4612 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4613 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4614 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4615 | mPhoneServiceState = state; |
| 4616 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4617 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4618 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4619 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4620 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4621 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4622 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4623 | if (strengthBin >= 0) { |
| 4624 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4625 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4626 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4627 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 4628 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4629 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4630 | + Integer.toHexString(mHistoryCur.states)); |
| 4631 | newHistory = true; |
| 4632 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4633 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4634 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4635 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4639 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | |
| 4643 | /** |
| 4644 | * Telephony stack updates the phone state. |
| 4645 | * @param state phone state from ServiceState.getState() |
| 4646 | */ |
| 4647 | public void notePhoneStateLocked(int state, int simState) { |
| 4648 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 4651 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4652 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4653 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4654 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4655 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4656 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4657 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 4658 | int bin = DATA_CONNECTION_NONE; |
| 4659 | if (hasData) { |
| 4660 | switch (dataType) { |
| 4661 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 4662 | bin = DATA_CONNECTION_EDGE; |
| 4663 | break; |
| 4664 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 4665 | bin = DATA_CONNECTION_GPRS; |
| 4666 | break; |
| 4667 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 4668 | bin = DATA_CONNECTION_UMTS; |
| 4669 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4670 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 4671 | bin = DATA_CONNECTION_CDMA; |
| 4672 | break; |
| 4673 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 4674 | bin = DATA_CONNECTION_EVDO_0; |
| 4675 | break; |
| 4676 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 4677 | bin = DATA_CONNECTION_EVDO_A; |
| 4678 | break; |
| 4679 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 4680 | bin = DATA_CONNECTION_1xRTT; |
| 4681 | break; |
| 4682 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 4683 | bin = DATA_CONNECTION_HSDPA; |
| 4684 | break; |
| 4685 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 4686 | bin = DATA_CONNECTION_HSUPA; |
| 4687 | break; |
| 4688 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 4689 | bin = DATA_CONNECTION_HSPA; |
| 4690 | break; |
| 4691 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 4692 | bin = DATA_CONNECTION_IDEN; |
| 4693 | break; |
| 4694 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 4695 | bin = DATA_CONNECTION_EVDO_B; |
| 4696 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 4697 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 4698 | bin = DATA_CONNECTION_LTE; |
| 4699 | break; |
| 4700 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 4701 | bin = DATA_CONNECTION_EHRPD; |
| 4702 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 4703 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 4704 | bin = DATA_CONNECTION_HSPAP; |
| 4705 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4706 | default: |
| 4707 | bin = DATA_CONNECTION_OTHER; |
| 4708 | break; |
| 4709 | } |
| 4710 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4711 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4712 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4713 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4714 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4715 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 4716 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4717 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 4718 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4719 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4720 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4721 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4722 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4723 | } |
| 4724 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4725 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4726 | } |
| 4727 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4728 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4729 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4730 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4731 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4732 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4733 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4734 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 4735 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4736 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4737 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4738 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4739 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4740 | } |
| 4741 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4742 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4743 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4744 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4745 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4746 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4747 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4748 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 4749 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4750 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4751 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4752 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4753 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4754 | } |
| 4755 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4756 | |
| 4757 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4758 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4759 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4760 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4761 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4762 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4763 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 4764 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4765 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4766 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4767 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4768 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4769 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4770 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4771 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4772 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4773 | if (mAudioOnNesting == 0) { |
| 4774 | return; |
| 4775 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4776 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4777 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4778 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4779 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4780 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4781 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4782 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4783 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4784 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4785 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4786 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4790 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4791 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4792 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4793 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4794 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4795 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 4796 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4797 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4798 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4799 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4800 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4801 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4802 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4803 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4804 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4805 | if (mVideoOnNesting == 0) { |
| 4806 | return; |
| 4807 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4808 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4809 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4810 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4811 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4812 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4813 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4814 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4815 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4816 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4817 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4818 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4819 | } |
| 4820 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4821 | public void noteResetAudioLocked() { |
| 4822 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4823 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4824 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4825 | mAudioOnNesting = 0; |
| 4826 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 4827 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4828 | + Integer.toHexString(mHistoryCur.states)); |
| 4829 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4830 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4831 | for (int i=0; i<mUidStats.size(); i++) { |
| 4832 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4833 | uid.noteResetAudioLocked(elapsedRealtime); |
| 4834 | } |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | public void noteResetVideoLocked() { |
| 4839 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4840 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4841 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4842 | mAudioOnNesting = 0; |
| 4843 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 4844 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4845 | + Integer.toHexString(mHistoryCur.states)); |
| 4846 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4847 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4848 | for (int i=0; i<mUidStats.size(); i++) { |
| 4849 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4850 | uid.noteResetVideoLocked(elapsedRealtime); |
| 4851 | } |
| 4852 | } |
| 4853 | } |
| 4854 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4855 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4856 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4857 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4861 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4862 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4863 | } |
| 4864 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4865 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4866 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4867 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 4868 | } |
| 4869 | |
| 4870 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4871 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4872 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 4873 | } |
| 4874 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4875 | public void noteFlashlightOnLocked(int uid) { |
| 4876 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4877 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4878 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4879 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4880 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4881 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4882 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4883 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4884 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 4885 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4886 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 4887 | } |
| 4888 | |
| 4889 | public void noteFlashlightOffLocked(int uid) { |
| 4890 | if (mFlashlightOnNesting == 0) { |
| 4891 | return; |
| 4892 | } |
| 4893 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4894 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4895 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4896 | if (--mFlashlightOnNesting == 0) { |
| 4897 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4898 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 4899 | + Integer.toHexString(mHistoryCur.states2)); |
| 4900 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4901 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 4902 | } |
| 4903 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 4904 | } |
| 4905 | |
| 4906 | public void noteCameraOnLocked(int uid) { |
| 4907 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4908 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4909 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4910 | if (mCameraOnNesting++ == 0) { |
| 4911 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 4912 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 4913 | + Integer.toHexString(mHistoryCur.states2)); |
| 4914 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4915 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 4916 | } |
| 4917 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4918 | } |
| 4919 | |
| 4920 | public void noteCameraOffLocked(int uid) { |
| 4921 | if (mCameraOnNesting == 0) { |
| 4922 | return; |
| 4923 | } |
| 4924 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4925 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4926 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4927 | if (--mCameraOnNesting == 0) { |
| 4928 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4929 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4930 | + Integer.toHexString(mHistoryCur.states2)); |
| 4931 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4932 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4933 | } |
| 4934 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4935 | } |
| 4936 | |
| 4937 | public void noteResetCameraLocked() { |
| 4938 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4939 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4940 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4941 | mCameraOnNesting = 0; |
| 4942 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4943 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4944 | + Integer.toHexString(mHistoryCur.states2)); |
| 4945 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4946 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4947 | for (int i=0; i<mUidStats.size(); i++) { |
| 4948 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4949 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4950 | } |
| 4951 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4952 | } |
| 4953 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4954 | public void noteResetFlashlightLocked() { |
| 4955 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4956 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4957 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4958 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4959 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4960 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4961 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4962 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4963 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4964 | for (int i=0; i<mUidStats.size(); i++) { |
| 4965 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4966 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4967 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4968 | } |
| 4969 | } |
| 4970 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4971 | private void noteBluetoothScanStartedLocked(int uid, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4972 | uid = mapUid(uid); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4973 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4974 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4975 | if (mBluetoothScanNesting == 0) { |
| 4976 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4977 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4978 | + Integer.toHexString(mHistoryCur.states2)); |
| 4979 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4980 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4981 | } |
| 4982 | mBluetoothScanNesting++; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4983 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4984 | } |
| 4985 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4986 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4987 | final int N = ws.size(); |
| 4988 | for (int i = 0; i < N; i++) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4989 | noteBluetoothScanStartedLocked(ws.get(i), isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4990 | } |
| 4991 | } |
| 4992 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 4993 | private void noteBluetoothScanStoppedLocked(int uid, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4994 | uid = mapUid(uid); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4995 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4996 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4997 | mBluetoothScanNesting--; |
| 4998 | if (mBluetoothScanNesting == 0) { |
| 4999 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5000 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 5001 | + Integer.toHexString(mHistoryCur.states2)); |
| 5002 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5003 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5004 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5005 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5006 | } |
| 5007 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5008 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5009 | final int N = ws.size(); |
| 5010 | for (int i = 0; i < N; i++) { |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5011 | noteBluetoothScanStoppedLocked(ws.get(i), isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | public void noteResetBluetoothScanLocked() { |
| 5016 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5017 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5018 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5019 | mBluetoothScanNesting = 0; |
| 5020 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5021 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 5022 | + Integer.toHexString(mHistoryCur.states2)); |
| 5023 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5024 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 5025 | for (int i=0; i<mUidStats.size(); i++) { |
| 5026 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5027 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 5028 | } |
| 5029 | } |
| 5030 | } |
| 5031 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5032 | public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5033 | final int N = ws.size(); |
| 5034 | for (int i = 0; i < N; i++) { |
| 5035 | int uid = mapUid(ws.get(i)); |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5036 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5037 | } |
| 5038 | } |
| 5039 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5040 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 5041 | final long uptimeMillis, int uid) { |
| 5042 | uid = mapUid(uid); |
| 5043 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 5044 | uid); |
| 5045 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 5046 | } |
| 5047 | |
| 5048 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5049 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5050 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5051 | if (mWifiRadioPowerState != powerState) { |
| 5052 | final boolean active = |
| 5053 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 5054 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 5055 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5056 | if (uid > 0) { |
| 5057 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 5058 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5059 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 5060 | } else { |
| 5061 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 5062 | } |
| 5063 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 5064 | + Integer.toHexString(mHistoryCur.states)); |
| 5065 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5066 | mWifiRadioPowerState = powerState; |
| 5067 | } |
| 5068 | } |
| 5069 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5070 | public void noteWifiRunningLocked(WorkSource ws) { |
| 5071 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5072 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5073 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5074 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5075 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 5076 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5077 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5078 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5079 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5080 | int N = ws.size(); |
| 5081 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5082 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5083 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5084 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5085 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5086 | } else { |
| 5087 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5088 | } |
| 5089 | } |
| 5090 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5091 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 5092 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5093 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5094 | int N = oldWs.size(); |
| 5095 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5096 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5097 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5098 | } |
| 5099 | N = newWs.size(); |
| 5100 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5101 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5102 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5103 | } |
| 5104 | } else { |
| 5105 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 5106 | } |
| 5107 | } |
| 5108 | |
| 5109 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 5110 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5111 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5112 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5113 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5114 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 5115 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5116 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5117 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5118 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5119 | int N = ws.size(); |
| 5120 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5121 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5122 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5123 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5124 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5125 | } else { |
| 5126 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5127 | } |
| 5128 | } |
| 5129 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5130 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 5131 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 5132 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5133 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5134 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5135 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5136 | } |
| 5137 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5138 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5139 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5140 | } |
| 5141 | } |
| 5142 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5143 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 5144 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 5145 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5146 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5147 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5148 | if (mWifiSupplState >= 0) { |
| 5149 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 5150 | } |
| 5151 | mWifiSupplState = supplState; |
| 5152 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 5153 | mHistoryCur.states2 = |
| 5154 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 5155 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 5156 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 5157 | + Integer.toHexString(mHistoryCur.states2)); |
| 5158 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5163 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5164 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 5165 | if (i == except) { |
| 5166 | continue; |
| 5167 | } |
| 5168 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 5169 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 5170 | } |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 5175 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 5176 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 5177 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5178 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5179 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5180 | if (mWifiSignalStrengthBin >= 0) { |
| 5181 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 5182 | elapsedRealtime); |
| 5183 | } |
| 5184 | if (strengthBin >= 0) { |
| 5185 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 5186 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 5187 | } |
| 5188 | mHistoryCur.states2 = |
| 5189 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 5190 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 5191 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 5192 | + Integer.toHexString(mHistoryCur.states2)); |
| 5193 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5194 | } else { |
| 5195 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 5196 | } |
| 5197 | mWifiSignalStrengthBin = strengthBin; |
| 5198 | } |
| 5199 | } |
| 5200 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5201 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5202 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5203 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5204 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5205 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5206 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5207 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5208 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5209 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 5210 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5211 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5212 | } |
| 5213 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5214 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5218 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5219 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5220 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5221 | mWifiFullLockNesting--; |
| 5222 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5223 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5224 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 5225 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5226 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5227 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5228 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5229 | } |
| 5230 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5231 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5232 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5233 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5234 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5235 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5236 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5237 | if (mWifiScanNesting == 0) { |
| 5238 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 5239 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5240 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5241 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5242 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5243 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5244 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5245 | } |
| 5246 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5247 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5248 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5249 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5250 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5251 | mWifiScanNesting--; |
| 5252 | if (mWifiScanNesting == 0) { |
| 5253 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 5254 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5255 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5256 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5257 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5258 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5259 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5260 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5261 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5262 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5263 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5264 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5265 | } |
| 5266 | |
| 5267 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5268 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5269 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5270 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5271 | } |
| 5272 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5273 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5274 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5275 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5276 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5277 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5278 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5279 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5280 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5281 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 5282 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5283 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5284 | } |
| 5285 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5286 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5290 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5291 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5292 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5293 | mWifiMulticastNesting--; |
| 5294 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5295 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5296 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 5297 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5298 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5299 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5300 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5303 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 5304 | int N = ws.size(); |
| 5305 | for (int i=0; i<N; i++) { |
| 5306 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 5311 | int N = ws.size(); |
| 5312 | for (int i=0; i<N; i++) { |
| 5313 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 5314 | } |
| 5315 | } |
| 5316 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5317 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5318 | int N = ws.size(); |
| 5319 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5320 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5324 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5325 | int N = ws.size(); |
| 5326 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5327 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5328 | } |
| 5329 | } |
| 5330 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5331 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 5332 | int N = ws.size(); |
| 5333 | for (int i=0; i<N; i++) { |
| 5334 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 5339 | int N = ws.size(); |
| 5340 | for (int i=0; i<N; i++) { |
| 5341 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 5342 | } |
| 5343 | } |
| 5344 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5345 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 5346 | int N = ws.size(); |
| 5347 | for (int i=0; i<N; i++) { |
| 5348 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 5353 | int N = ws.size(); |
| 5354 | for (int i=0; i<N; i++) { |
| 5355 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 5356 | } |
| 5357 | } |
| 5358 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5359 | private static String[] includeInStringArray(String[] array, String str) { |
| 5360 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 5361 | return array; |
| 5362 | } |
| 5363 | String[] newArray = new String[array.length+1]; |
| 5364 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 5365 | newArray[array.length] = str; |
| 5366 | return newArray; |
| 5367 | } |
| 5368 | |
| 5369 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 5370 | int index = ArrayUtils.indexOf(array, str); |
| 5371 | if (index >= 0) { |
| 5372 | String[] newArray = new String[array.length-1]; |
| 5373 | if (index > 0) { |
| 5374 | System.arraycopy(array, 0, newArray, 0, index); |
| 5375 | } |
| 5376 | if (index < array.length-1) { |
| 5377 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 5378 | } |
| 5379 | return newArray; |
| 5380 | } |
| 5381 | return array; |
| 5382 | } |
| 5383 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5384 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 5385 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5386 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 5387 | synchronized (mModemNetworkLock) { |
| 5388 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 5389 | mModemIfaces = includeInStringArray(mModemIfaces, iface); |
| 5390 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mModemIfaces); |
| 5391 | } else { |
| 5392 | mModemIfaces = excludeFromStringArray(mModemIfaces, iface); |
| 5393 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mModemIfaces); |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | synchronized (mWifiNetworkLock) { |
| 5398 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 5399 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 5400 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
| 5401 | } else { |
| 5402 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 5403 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
| 5404 | } |
| 5405 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5406 | } |
| 5407 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5408 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 5409 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5410 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5411 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5412 | @Override public int getScreenOnCount(int which) { |
| 5413 | return mScreenOnTimer.getCountLocked(which); |
| 5414 | } |
| 5415 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 5416 | @Override public long getScreenDozeTime(long elapsedRealtimeUs, int which) { |
| 5417 | return mScreenDozeTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5418 | } |
| 5419 | |
| 5420 | @Override public int getScreenDozeCount(int which) { |
| 5421 | return mScreenDozeTimer.getCountLocked(which); |
| 5422 | } |
| 5423 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5424 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5425 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5426 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5427 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5428 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5429 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5430 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 5431 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5432 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5433 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5434 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 5435 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5436 | } |
| 5437 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5438 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 5439 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 5440 | } |
| 5441 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5442 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 5443 | int which) { |
| 5444 | switch (mode) { |
| 5445 | case DEVICE_IDLE_MODE_LIGHT: |
| 5446 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5447 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5448 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5449 | } |
| 5450 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5451 | } |
| 5452 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5453 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 5454 | switch (mode) { |
| 5455 | case DEVICE_IDLE_MODE_LIGHT: |
| 5456 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5457 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5458 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 5459 | } |
| 5460 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5461 | } |
| 5462 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5463 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 5464 | switch (mode) { |
| 5465 | case DEVICE_IDLE_MODE_LIGHT: |
| 5466 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5467 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5468 | return mLongestFullIdleTime; |
| 5469 | } |
| 5470 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5473 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 5474 | switch (mode) { |
| 5475 | case DEVICE_IDLE_MODE_LIGHT: |
| 5476 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5477 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5478 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5479 | } |
| 5480 | return 0; |
| 5481 | } |
| 5482 | |
| 5483 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 5484 | switch (mode) { |
| 5485 | case DEVICE_IDLE_MODE_LIGHT: |
| 5486 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5487 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5488 | return mDeviceIdlingTimer.getCountLocked(which); |
| 5489 | } |
| 5490 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5491 | } |
| 5492 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5493 | @Override public int getNumConnectivityChange(int which) { |
| 5494 | int val = mNumConnectivityChange; |
| 5495 | if (which == STATS_CURRENT) { |
| 5496 | val -= mLoadedNumConnectivityChange; |
| 5497 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5498 | val -= mUnpluggedNumConnectivityChange; |
| 5499 | } |
| 5500 | return val; |
| 5501 | } |
| 5502 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5503 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 5504 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5506 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5507 | @Override public int getPhoneOnCount(int which) { |
| 5508 | return mPhoneOnTimer.getCountLocked(which); |
| 5509 | } |
| 5510 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5511 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5512 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5513 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5514 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5515 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5516 | |
| 5517 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5518 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5519 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5520 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5521 | } |
| 5522 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 5523 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 5524 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5525 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5526 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5527 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5528 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5529 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5530 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5531 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5532 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5533 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5534 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5535 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5536 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5537 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 5538 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5539 | } |
| 5540 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5541 | @Override public int getMobileRadioActiveCount(int which) { |
| 5542 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 5543 | } |
| 5544 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5545 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 5546 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 5547 | } |
| 5548 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5549 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 5550 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 5551 | } |
| 5552 | |
| 5553 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 5554 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 5555 | } |
| 5556 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5557 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 5558 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5559 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5560 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5561 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 5562 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5565 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5566 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5567 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5568 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 5572 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 5573 | } |
| 5574 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5575 | @Override public long getWifiSupplStateTime(int state, |
| 5576 | long elapsedRealtimeUs, int which) { |
| 5577 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 5578 | elapsedRealtimeUs, which); |
| 5579 | } |
| 5580 | |
| 5581 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 5582 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 5583 | } |
| 5584 | |
| 5585 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 5586 | long elapsedRealtimeUs, int which) { |
| 5587 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 5588 | elapsedRealtimeUs, which); |
| 5589 | } |
| 5590 | |
| 5591 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 5592 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 5593 | } |
| 5594 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5595 | @Override |
| 5596 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5597 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5600 | @Override |
| 5601 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5602 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5605 | @Override |
| 5606 | public ControllerActivityCounter getModemControllerActivity() { |
| 5607 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5610 | @Override |
| 5611 | public boolean hasBluetoothActivityReporting() { |
| 5612 | return mHasBluetoothReporting; |
| 5613 | } |
| 5614 | |
| 5615 | @Override |
| 5616 | public boolean hasWifiActivityReporting() { |
| 5617 | return mHasWifiReporting; |
| 5618 | } |
| 5619 | |
| 5620 | @Override |
| 5621 | public boolean hasModemActivityReporting() { |
| 5622 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5623 | } |
| 5624 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5625 | @Override |
| 5626 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5627 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5628 | } |
| 5629 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5630 | @Override |
| 5631 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5632 | return mFlashlightOnTimer.getCountLocked(which); |
| 5633 | } |
| 5634 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5635 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5636 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 5637 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5638 | } |
| 5639 | |
| 5640 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5641 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 5642 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5643 | } |
| 5644 | |
| 5645 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5646 | public long getNetworkActivityBytes(int type, int which) { |
| 5647 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 5648 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5649 | } else { |
| 5650 | return 0; |
| 5651 | } |
| 5652 | } |
| 5653 | |
| 5654 | @Override |
| 5655 | public long getNetworkActivityPackets(int type, int which) { |
| 5656 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 5657 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5658 | } else { |
| 5659 | return 0; |
| 5660 | } |
| 5661 | } |
| 5662 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5663 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 5664 | final long currentTime = System.currentTimeMillis(); |
| 5665 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5666 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 5667 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 5668 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5669 | return mStartClockTime; |
| 5670 | } |
| 5671 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5672 | @Override public String getStartPlatformVersion() { |
| 5673 | return mStartPlatformVersion; |
| 5674 | } |
| 5675 | |
| 5676 | @Override public String getEndPlatformVersion() { |
| 5677 | return mEndPlatformVersion; |
| 5678 | } |
| 5679 | |
| 5680 | @Override public int getParcelVersion() { |
| 5681 | return VERSION; |
| 5682 | } |
| 5683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5684 | @Override public boolean getIsOnBattery() { |
| 5685 | return mOnBattery; |
| 5686 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 5689 | return mUidStats; |
| 5690 | } |
| 5691 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5692 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 5693 | if (timer != null) { |
| 5694 | timer.detach(); |
| 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 5699 | boolean detachIfReset) { |
| 5700 | if (timer != null) { |
| 5701 | return timer.reset(detachIfReset); |
| 5702 | } |
| 5703 | return true; |
| 5704 | } |
| 5705 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5706 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 5707 | if (timer != null) { |
| 5708 | return timer.reset(detachIfReset); |
| 5709 | } |
| 5710 | return true; |
| 5711 | } |
| 5712 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5713 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 5714 | if (counter != null) { |
| 5715 | counter.detach(); |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 5720 | boolean detachIfReset) { |
| 5721 | if (counter != null) { |
| 5722 | counter.reset(detachIfReset); |
| 5723 | } |
| 5724 | } |
| 5725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | /** |
| 5727 | * The statistics associated with a particular uid. |
| 5728 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5729 | public static class Uid extends BatteryStats.Uid { |
| 5730 | /** |
| 5731 | * BatteryStatsImpl that we are associated with. |
| 5732 | */ |
| 5733 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5736 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5737 | /** TimeBase for when uid is in background and device is on battery. */ |
| 5738 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 5739 | public final TimeBase mOnBatteryBackgroundTimeBase; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5740 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 5741 | public final TimeBase mOnBatteryScreenOffBackgroundTimeBase; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5742 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5743 | boolean mWifiRunning; |
| 5744 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5745 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5746 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5747 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5748 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5749 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5750 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5751 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5752 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5753 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5754 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 5755 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5756 | boolean mWifiMulticastEnabled; |
| 5757 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5758 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5759 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5760 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5761 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 5762 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5763 | StopwatchTimer mForegroundActivityTimer; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5764 | StopwatchTimer mForegroundServiceTimer; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5765 | /** Total time spent by the uid holding any partial wakelocks. */ |
| 5766 | DualTimer mAggregatedPartialWakelockTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5767 | DualTimer mBluetoothScanTimer; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5768 | DualTimer mBluetoothUnoptimizedScanTimer; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5769 | Counter mBluetoothScanResultCounter; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5770 | Counter mBluetoothScanResultBgCounter; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5771 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5772 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5773 | StopwatchTimer[] mProcessStateTimer; |
| 5774 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5775 | boolean mInForegroundService = false; |
| 5776 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5777 | BatchTimer mVibratorOnTimer; |
| 5778 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5779 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5780 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5781 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 5782 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5783 | LongSamplingCounter mMobileRadioActiveTime; |
| 5784 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5786 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5787 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 5788 | */ |
| 5789 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 5790 | |
| 5791 | /** |
| 5792 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 5793 | */ |
| 5794 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 5795 | |
| 5796 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5797 | * The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5798 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5799 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5800 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5801 | |
| 5802 | /** |
| 5803 | * The amount of time this uid has kept the Bluetooth controller in idle, tx, and rx mode. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5804 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5805 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5806 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 5807 | |
| 5808 | /** |
| 5809 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 5810 | * Can be null if the UID has had no such activity. |
| 5811 | */ |
| 5812 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5813 | |
| 5814 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5815 | * The CPU times we had at the last history details update. |
| 5816 | */ |
| 5817 | long mLastStepUserTime; |
| 5818 | long mLastStepSystemTime; |
| 5819 | long mCurStepUserTime; |
| 5820 | long mCurStepSystemTime; |
| 5821 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5822 | LongSamplingCounter mUserCpuTime; |
| 5823 | LongSamplingCounter mSystemCpuTime; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 5824 | LongSamplingCounter[][] mCpuClusterSpeedTimesUs; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5825 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5826 | LongSamplingCounterArray mCpuFreqTimeMs; |
| 5827 | LongSamplingCounterArray mScreenOffCpuFreqTimeMs; |
| 5828 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5829 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | * The statistics we have collected for this uid's wake locks. |
| 5831 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5832 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5833 | |
| 5834 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5835 | * The statistics we have collected for this uid's syncs. |
| 5836 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5837 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5838 | |
| 5839 | /** |
| 5840 | * The statistics we have collected for this uid's jobs. |
| 5841 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5842 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5843 | |
| 5844 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5845 | * Count of the jobs that have completed and the reasons why they completed. |
| 5846 | */ |
| 5847 | final ArrayMap<String, SparseIntArray> mJobCompletions = new ArrayMap<>(); |
| 5848 | |
| 5849 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | * The statistics we have collected for this uid's sensor activations. |
| 5851 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5852 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5853 | |
| 5854 | /** |
| 5855 | * The statistics we have collected for this uid's processes. |
| 5856 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5857 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5858 | |
| 5859 | /** |
| 5860 | * The statistics we have collected for this uid's processes. |
| 5861 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5862 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5863 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5864 | /** |
| 5865 | * The transient wake stats we have collected for this uid's pids. |
| 5866 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5867 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5868 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5869 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 5870 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5872 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5873 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 5874 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 5875 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 5876 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5877 | mOnBatteryScreenOffBackgroundTimeBase = new TimeBase(); |
| 5878 | mOnBatteryScreenOffBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 5879 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 5880 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5881 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5882 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5883 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 5884 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5885 | @Override public Wakelock instantiateObject() { |
| 5886 | return new Wakelock(mBsi, Uid.this); |
| 5887 | } |
| 5888 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5889 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 5890 | @Override public DualTimer instantiateObject() { |
| 5891 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 5892 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5893 | } |
| 5894 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5895 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 5896 | @Override public DualTimer instantiateObject() { |
| 5897 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 5898 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5899 | } |
| 5900 | }; |
| 5901 | |
| 5902 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 5903 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 5904 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 5905 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5906 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 5907 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5908 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5909 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 5910 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5911 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | @Override |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5915 | public long[] getCpuFreqTimes(int which) { |
| 5916 | if (mCpuFreqTimeMs == null) { |
| 5917 | return null; |
| 5918 | } |
| 5919 | final long[] cpuFreqTimes = mCpuFreqTimeMs.getCountsLocked(which); |
| 5920 | if (cpuFreqTimes == null) { |
| 5921 | return null; |
| 5922 | } |
| 5923 | // Return cpuFreqTimes only if atleast one of the elements in non-zero. |
| 5924 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5925 | if (cpuFreqTimes[i] != 0) { |
| 5926 | return cpuFreqTimes; |
| 5927 | } |
| 5928 | } |
| 5929 | return null; |
| 5930 | } |
| 5931 | |
| 5932 | @Override |
| 5933 | public long[] getScreenOffCpuFreqTimes(int which) { |
| 5934 | if (mScreenOffCpuFreqTimeMs == null) { |
| 5935 | return null; |
| 5936 | } |
| 5937 | final long[] cpuFreqTimes = mScreenOffCpuFreqTimeMs.getCountsLocked(which); |
| 5938 | if (cpuFreqTimes == null) { |
| 5939 | return null; |
| 5940 | } |
| 5941 | // Return cpuFreqTimes only if atleast one of the elements in non-zero. |
| 5942 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5943 | if (cpuFreqTimes[i] != 0) { |
| 5944 | return cpuFreqTimes; |
| 5945 | } |
| 5946 | } |
| 5947 | return null; |
| 5948 | } |
| 5949 | |
| 5950 | @Override |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5951 | public Timer getAggregatedPartialWakelockTimer() { |
| 5952 | return mAggregatedPartialWakelockTimer; |
| 5953 | } |
| 5954 | |
| 5955 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5956 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5957 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5961 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5962 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5966 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5967 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | @Override |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5971 | public ArrayMap<String, SparseIntArray> getJobCompletionStats() { |
| 5972 | return mJobCompletions; |
| 5973 | } |
| 5974 | |
| 5975 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5976 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5977 | return mSensorStats; |
| 5978 | } |
| 5979 | |
| 5980 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5981 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5982 | return mProcessStats; |
| 5983 | } |
| 5984 | |
| 5985 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5986 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5987 | return mPackageStats; |
| 5988 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5989 | |
| 5990 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | public int getUid() { |
| 5992 | return mUid; |
| 5993 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5994 | |
| 5995 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5996 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5997 | if (!mWifiRunning) { |
| 5998 | mWifiRunning = true; |
| 5999 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6000 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6001 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6002 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6003 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6004 | } |
| 6005 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6006 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6007 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6008 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6009 | if (mWifiRunning) { |
| 6010 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6011 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6012 | } |
| 6013 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6014 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6015 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6016 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6017 | if (!mFullWifiLockOut) { |
| 6018 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6019 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6020 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6021 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6022 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6023 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6024 | } |
| 6025 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6026 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6027 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6028 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6029 | if (mFullWifiLockOut) { |
| 6030 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6031 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6032 | } |
| 6033 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6034 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6035 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6036 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6037 | if (!mWifiScanStarted) { |
| 6038 | mWifiScanStarted = true; |
| 6039 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6040 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6041 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 6042 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6043 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6044 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6045 | } |
| 6046 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6047 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6048 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6049 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6050 | if (mWifiScanStarted) { |
| 6051 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6052 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6053 | } |
| 6054 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6055 | |
| 6056 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6057 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6058 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 6059 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6060 | csph = csph >> 3; |
| 6061 | bin++; |
| 6062 | } |
| 6063 | |
| 6064 | if (mWifiBatchedScanBinStarted == bin) return; |
| 6065 | |
| 6066 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 6067 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6068 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6069 | } |
| 6070 | mWifiBatchedScanBinStarted = bin; |
| 6071 | if (mWifiBatchedScanTimer[bin] == null) { |
| 6072 | makeWifiBatchedScanBin(bin, null); |
| 6073 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6074 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6078 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6079 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 6080 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6081 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6082 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6087 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6088 | if (!mWifiMulticastEnabled) { |
| 6089 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6090 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6091 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6092 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6093 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6094 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6099 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6100 | if (mWifiMulticastEnabled) { |
| 6101 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6102 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6106 | @Override |
| 6107 | public ControllerActivityCounter getWifiControllerActivity() { |
| 6108 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6109 | } |
| 6110 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6111 | @Override |
| 6112 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 6113 | return mBluetoothControllerActivity; |
| 6114 | } |
| 6115 | |
| 6116 | @Override |
| 6117 | public ControllerActivityCounter getModemControllerActivity() { |
| 6118 | return mModemControllerActivity; |
| 6119 | } |
| 6120 | |
| 6121 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 6122 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6123 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6124 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 6125 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6126 | return mWifiControllerActivity; |
| 6127 | } |
| 6128 | |
| 6129 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 6130 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6131 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6132 | NUM_BT_TX_LEVELS); |
| 6133 | } |
| 6134 | return mBluetoothControllerActivity; |
| 6135 | } |
| 6136 | |
| 6137 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 6138 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6139 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6140 | ModemActivityInfo.TX_POWER_LEVELS); |
| 6141 | } |
| 6142 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 6143 | } |
| 6144 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6145 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 6146 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6147 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6148 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6149 | } |
| 6150 | return mAudioTurnedOnTimer; |
| 6151 | } |
| 6152 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6153 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 6154 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6155 | } |
| 6156 | |
| 6157 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 6158 | if (mAudioTurnedOnTimer != null) { |
| 6159 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6160 | } |
| 6161 | } |
| 6162 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 6163 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 6164 | if (mAudioTurnedOnTimer != null) { |
| 6165 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6169 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 6170 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6171 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6172 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6173 | } |
| 6174 | return mVideoTurnedOnTimer; |
| 6175 | } |
| 6176 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6177 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 6178 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6179 | } |
| 6180 | |
| 6181 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 6182 | if (mVideoTurnedOnTimer != null) { |
| 6183 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6184 | } |
| 6185 | } |
| 6186 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 6187 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 6188 | if (mVideoTurnedOnTimer != null) { |
| 6189 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6190 | } |
| 6191 | } |
| 6192 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6193 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 6194 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6195 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6196 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6197 | } |
| 6198 | return mFlashlightTurnedOnTimer; |
| 6199 | } |
| 6200 | |
| 6201 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 6202 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6203 | } |
| 6204 | |
| 6205 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 6206 | if (mFlashlightTurnedOnTimer != null) { |
| 6207 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6208 | } |
| 6209 | } |
| 6210 | |
| 6211 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 6212 | if (mFlashlightTurnedOnTimer != null) { |
| 6213 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6214 | } |
| 6215 | } |
| 6216 | |
| 6217 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 6218 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6219 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6220 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6221 | } |
| 6222 | return mCameraTurnedOnTimer; |
| 6223 | } |
| 6224 | |
| 6225 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 6226 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6227 | } |
| 6228 | |
| 6229 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 6230 | if (mCameraTurnedOnTimer != null) { |
| 6231 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6232 | } |
| 6233 | } |
| 6234 | |
| 6235 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 6236 | if (mCameraTurnedOnTimer != null) { |
| 6237 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6238 | } |
| 6239 | } |
| 6240 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6241 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 6242 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6243 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6244 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6245 | } |
| 6246 | return mForegroundActivityTimer; |
| 6247 | } |
| 6248 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6249 | public StopwatchTimer createForegroundServiceTimerLocked() { |
| 6250 | if (mForegroundServiceTimer == null) { |
| 6251 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6252 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase); |
| 6253 | } |
| 6254 | return mForegroundServiceTimer; |
| 6255 | } |
| 6256 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6257 | public DualTimer createAggregatedPartialWakelockTimerLocked() { |
| 6258 | if (mAggregatedPartialWakelockTimer == null) { |
| 6259 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 6260 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 6261 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); |
| 6262 | } |
| 6263 | return mAggregatedPartialWakelockTimer; |
| 6264 | } |
| 6265 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6266 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6267 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6268 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6269 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 6270 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6271 | } |
| 6272 | return mBluetoothScanTimer; |
| 6273 | } |
| 6274 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6275 | public DualTimer createBluetoothUnoptimizedScanTimerLocked() { |
| 6276 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 6277 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 6278 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 6279 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
| 6280 | } |
| 6281 | return mBluetoothUnoptimizedScanTimer; |
| 6282 | } |
| 6283 | |
| 6284 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6285 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6286 | if (isUnoptimized) { |
| 6287 | createBluetoothUnoptimizedScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6288 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6289 | } |
| 6290 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 6291 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6292 | if (mBluetoothScanTimer != null) { |
| 6293 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6294 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 6295 | if (isUnoptimized && mBluetoothUnoptimizedScanTimer != null) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6296 | mBluetoothUnoptimizedScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6297 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 6301 | if (mBluetoothScanTimer != null) { |
| 6302 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6303 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6304 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 6305 | mBluetoothUnoptimizedScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6306 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6307 | } |
| 6308 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6309 | public Counter createBluetoothScanResultCounterLocked() { |
| 6310 | if (mBluetoothScanResultCounter == null) { |
| 6311 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase); |
| 6312 | } |
| 6313 | return mBluetoothScanResultCounter; |
| 6314 | } |
| 6315 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6316 | public Counter createBluetoothScanResultBgCounterLocked() { |
| 6317 | if (mBluetoothScanResultBgCounter == null) { |
| 6318 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase); |
| 6319 | } |
| 6320 | return mBluetoothScanResultBgCounter; |
| 6321 | } |
| 6322 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 6323 | public void noteBluetoothScanResultsLocked(int numNewResults) { |
| 6324 | createBluetoothScanResultCounterLocked().addAtomic(numNewResults); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6325 | // Uses background timebase, so the count will only be incremented if uid in background. |
| 6326 | createBluetoothScanResultBgCounterLocked().addAtomic(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6327 | } |
| 6328 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6329 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6330 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6331 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6332 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6336 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6337 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6338 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6339 | } |
| 6340 | } |
| 6341 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6342 | public void noteForegroundServiceResumedLocked(long elapsedRealtimeMs) { |
| 6343 | createForegroundServiceTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6344 | } |
| 6345 | |
| 6346 | public void noteForegroundServicePausedLocked(long elapsedRealtimeMs) { |
| 6347 | if (mForegroundServiceTimer != null) { |
| 6348 | mForegroundServiceTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6349 | } |
| 6350 | } |
| 6351 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6352 | public BatchTimer createVibratorOnTimerLocked() { |
| 6353 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6354 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6355 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6356 | } |
| 6357 | return mVibratorOnTimer; |
| 6358 | } |
| 6359 | |
| 6360 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6361 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | public void noteVibratorOffLocked() { |
| 6365 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6366 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6367 | } |
| 6368 | } |
| 6369 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6370 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6371 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6372 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6373 | return 0; |
| 6374 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6375 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6376 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6377 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6378 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6379 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6380 | if (mFullWifiLockTimer == null) { |
| 6381 | return 0; |
| 6382 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6383 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6384 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6385 | |
| 6386 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6387 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6388 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6389 | return 0; |
| 6390 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6391 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6392 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6393 | |
| 6394 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6395 | public int getWifiScanCount(int which) { |
| 6396 | if (mWifiScanTimer == null) { |
| 6397 | return 0; |
| 6398 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6399 | return mWifiScanTimer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | @Override |
| 6403 | public int getWifiScanBackgroundCount(int which) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6404 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6405 | return 0; |
| 6406 | } |
| 6407 | return mWifiScanTimer.getSubTimer().getCountLocked(which); |
| 6408 | } |
| 6409 | |
| 6410 | @Override |
| 6411 | public long getWifiScanActualTime(final long elapsedRealtimeUs) { |
| 6412 | if (mWifiScanTimer == null) { |
| 6413 | return 0; |
| 6414 | } |
| 6415 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6416 | return mWifiScanTimer.getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | @Override |
| 6420 | public long getWifiScanBackgroundTime(final long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6421 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6422 | return 0; |
| 6423 | } |
| 6424 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
| 6425 | return mWifiScanTimer.getSubTimer().getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6429 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6430 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 6431 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 6432 | return 0; |
| 6433 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6434 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6438 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 6439 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 6440 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 6441 | return 0; |
| 6442 | } |
| 6443 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 6444 | } |
| 6445 | |
| 6446 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6447 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6448 | if (mWifiMulticastTimer == null) { |
| 6449 | return 0; |
| 6450 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6451 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6452 | } |
| 6453 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6454 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6455 | public Timer getAudioTurnedOnTimer() { |
| 6456 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6457 | } |
| 6458 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6459 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6460 | public Timer getVideoTurnedOnTimer() { |
| 6461 | return mVideoTurnedOnTimer; |
| 6462 | } |
| 6463 | |
| 6464 | @Override |
| 6465 | public Timer getFlashlightTurnedOnTimer() { |
| 6466 | return mFlashlightTurnedOnTimer; |
| 6467 | } |
| 6468 | |
| 6469 | @Override |
| 6470 | public Timer getCameraTurnedOnTimer() { |
| 6471 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6472 | } |
| 6473 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6474 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6475 | public Timer getForegroundActivityTimer() { |
| 6476 | return mForegroundActivityTimer; |
| 6477 | } |
| 6478 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6479 | @Override |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6480 | public Timer getForegroundServiceTimer() { |
| 6481 | return mForegroundServiceTimer; |
| 6482 | } |
| 6483 | |
| 6484 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6485 | public Timer getBluetoothScanTimer() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6486 | return mBluetoothScanTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | @Override |
| 6490 | public Timer getBluetoothScanBackgroundTimer() { |
| 6491 | if (mBluetoothScanTimer == null) { |
| 6492 | return null; |
| 6493 | } |
| 6494 | return mBluetoothScanTimer.getSubTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6495 | } |
| 6496 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6497 | @Override |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6498 | public Timer getBluetoothUnoptimizedScanTimer() { |
| 6499 | return mBluetoothUnoptimizedScanTimer; |
| 6500 | } |
| 6501 | |
| 6502 | @Override |
| 6503 | public Timer getBluetoothUnoptimizedScanBackgroundTimer() { |
| 6504 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 6505 | return null; |
| 6506 | } |
| 6507 | return mBluetoothUnoptimizedScanTimer.getSubTimer(); |
| 6508 | } |
| 6509 | |
| 6510 | @Override |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6511 | public Counter getBluetoothScanResultCounter() { |
| 6512 | return mBluetoothScanResultCounter; |
| 6513 | } |
| 6514 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6515 | @Override |
| 6516 | public Counter getBluetoothScanResultBgCounter() { |
| 6517 | return mBluetoothScanResultBgCounter; |
| 6518 | } |
| 6519 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6520 | void makeProcessState(int i, Parcel in) { |
| 6521 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 6522 | |
| 6523 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6524 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 6525 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6526 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6527 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 6528 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6529 | } |
| 6530 | } |
| 6531 | |
| 6532 | @Override |
| 6533 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 6534 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 6535 | if (mProcessStateTimer[state] == null) { |
| 6536 | return 0; |
| 6537 | } |
| 6538 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6539 | } |
| 6540 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6541 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 6542 | public Timer getProcessStateTimer(int state) { |
| 6543 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 6544 | return mProcessStateTimer[state]; |
| 6545 | } |
| 6546 | |
| 6547 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6548 | public Timer getVibratorOnTimer() { |
| 6549 | return mVibratorOnTimer; |
| 6550 | } |
| 6551 | |
| 6552 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6553 | public void noteUserActivityLocked(int type) { |
| 6554 | if (mUserActivityCounters == null) { |
| 6555 | initUserActivityLocked(); |
| 6556 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 6557 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 6558 | mUserActivityCounters[type].stepAtomic(); |
| 6559 | } else { |
| 6560 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 6561 | new Throwable()); |
| 6562 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6563 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6564 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6565 | @Override |
| 6566 | public boolean hasUserActivity() { |
| 6567 | return mUserActivityCounters != null; |
| 6568 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6569 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6570 | @Override |
| 6571 | public int getUserActivityCount(int type, int which) { |
| 6572 | if (mUserActivityCounters == null) { |
| 6573 | return 0; |
| 6574 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6575 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6576 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6577 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6578 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 6579 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 6580 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6581 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6582 | if (collected == null) { |
| 6583 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6584 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6585 | } |
| 6586 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6587 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 6588 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6589 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6590 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 6591 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6596 | void initUserActivityLocked() { |
| 6597 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6598 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6599 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6600 | } |
| 6601 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6602 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6603 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 6604 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6605 | initNetworkActivityLocked(); |
| 6606 | } |
| 6607 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6608 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 6609 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6610 | } else { |
| 6611 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 6612 | new Throwable()); |
| 6613 | } |
| 6614 | } |
| 6615 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6616 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 6617 | if (mNetworkByteActivityCounters == null) { |
| 6618 | initNetworkActivityLocked(); |
| 6619 | } |
| 6620 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 6621 | mMobileRadioActiveCount.addCountLocked(1); |
| 6622 | } |
| 6623 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6624 | @Override |
| 6625 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6626 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6627 | } |
| 6628 | |
| 6629 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6630 | public long getNetworkActivityBytes(int type, int which) { |
| 6631 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 6632 | && type < mNetworkByteActivityCounters.length) { |
| 6633 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6634 | } else { |
| 6635 | return 0; |
| 6636 | } |
| 6637 | } |
| 6638 | |
| 6639 | @Override |
| 6640 | public long getNetworkActivityPackets(int type, int which) { |
| 6641 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 6642 | && type < mNetworkPacketActivityCounters.length) { |
| 6643 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6644 | } else { |
| 6645 | return 0; |
| 6646 | } |
| 6647 | } |
| 6648 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6649 | @Override |
| 6650 | public long getMobileRadioActiveTime(int which) { |
| 6651 | return mMobileRadioActiveTime != null |
| 6652 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 6653 | } |
| 6654 | |
| 6655 | @Override |
| 6656 | public int getMobileRadioActiveCount(int which) { |
| 6657 | return mMobileRadioActiveCount != null |
| 6658 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 6659 | } |
| 6660 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6661 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6662 | public long getUserCpuTimeUs(int which) { |
| 6663 | return mUserCpuTime.getCountLocked(which); |
| 6664 | } |
| 6665 | |
| 6666 | @Override |
| 6667 | public long getSystemCpuTimeUs(int which) { |
| 6668 | return mSystemCpuTime.getCountLocked(which); |
| 6669 | } |
| 6670 | |
| 6671 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6672 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 6673 | if (mCpuClusterSpeedTimesUs != null) { |
| 6674 | if (cluster >= 0 && cluster < mCpuClusterSpeedTimesUs.length) { |
| 6675 | final LongSamplingCounter[] cpuSpeedTimesUs = mCpuClusterSpeedTimesUs[cluster]; |
| 6676 | if (cpuSpeedTimesUs != null) { |
| 6677 | if (step >= 0 && step < cpuSpeedTimesUs.length) { |
| 6678 | final LongSamplingCounter c = cpuSpeedTimesUs[step]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6679 | if (c != null) { |
| 6680 | return c.getCountLocked(which); |
| 6681 | } |
| 6682 | } |
| 6683 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6684 | } |
| 6685 | } |
| 6686 | return 0; |
| 6687 | } |
| 6688 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6689 | public void noteMobileRadioApWakeupLocked() { |
| 6690 | if (mMobileRadioApWakeupCount == null) { |
| 6691 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6692 | } |
| 6693 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 6694 | } |
| 6695 | |
| 6696 | @Override |
| 6697 | public long getMobileRadioApWakeupCount(int which) { |
| 6698 | if (mMobileRadioApWakeupCount != null) { |
| 6699 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 6700 | } |
| 6701 | return 0; |
| 6702 | } |
| 6703 | |
| 6704 | public void noteWifiRadioApWakeupLocked() { |
| 6705 | if (mWifiRadioApWakeupCount == null) { |
| 6706 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6707 | } |
| 6708 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 6709 | } |
| 6710 | |
| 6711 | @Override |
| 6712 | public long getWifiRadioApWakeupCount(int which) { |
| 6713 | if (mWifiRadioApWakeupCount != null) { |
| 6714 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 6715 | } |
| 6716 | return 0; |
| 6717 | } |
| 6718 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6719 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6720 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6721 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6722 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6723 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6724 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6725 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6726 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6727 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6728 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6729 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6730 | /** |
| 6731 | * Clear all stats for this uid. Returns true if the uid is completely |
| 6732 | * inactive so can be dropped. |
| 6733 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 6734 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 6735 | public boolean reset(long uptime, long realtime) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6736 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6737 | |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 6738 | mOnBatteryBackgroundTimeBase.init(uptime, realtime); |
| 6739 | mOnBatteryScreenOffBackgroundTimeBase.init(uptime, realtime); |
| 6740 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6741 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6742 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6743 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6744 | } |
| 6745 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6746 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6747 | active |= mFullWifiLockOut; |
| 6748 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6749 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6750 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6751 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6752 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6753 | if (mWifiBatchedScanTimer != null) { |
| 6754 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6755 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6756 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6757 | } |
| 6758 | } |
| 6759 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 6760 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6761 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6762 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6763 | active |= mWifiMulticastEnabled; |
| 6764 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6765 | |
| 6766 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 6767 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 6768 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 6769 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 6770 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6771 | active |= !resetTimerIfNotNull(mForegroundServiceTimer, false); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6772 | active |= !resetTimerIfNotNull(mAggregatedPartialWakelockTimer, false); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6773 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6774 | active |= !resetTimerIfNotNull(mBluetoothUnoptimizedScanTimer, false); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6775 | if (mBluetoothScanResultCounter != null) { |
| 6776 | mBluetoothScanResultCounter.reset(false); |
| 6777 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6778 | if (mBluetoothScanResultBgCounter != null) { |
| 6779 | mBluetoothScanResultBgCounter.reset(false); |
| 6780 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6781 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6782 | if (mProcessStateTimer != null) { |
| 6783 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6784 | if (mProcessStateTimer[i] != null) { |
| 6785 | active |= !mProcessStateTimer[i].reset(false); |
| 6786 | } |
| 6787 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6788 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6789 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6790 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6791 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6792 | mVibratorOnTimer.detach(); |
| 6793 | mVibratorOnTimer = null; |
| 6794 | } else { |
| 6795 | active = true; |
| 6796 | } |
| 6797 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6798 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6799 | if (mUserActivityCounters != null) { |
| 6800 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6801 | mUserActivityCounters[i].reset(false); |
| 6802 | } |
| 6803 | } |
| 6804 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6805 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6806 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6807 | mNetworkByteActivityCounters[i].reset(false); |
| 6808 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6809 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6810 | mMobileRadioActiveTime.reset(false); |
| 6811 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6812 | } |
| 6813 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6814 | if (mWifiControllerActivity != null) { |
| 6815 | mWifiControllerActivity.reset(false); |
| 6816 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6817 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6818 | if (mBluetoothControllerActivity != null) { |
| 6819 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6820 | } |
| 6821 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6822 | if (mModemControllerActivity != null) { |
| 6823 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6824 | } |
| 6825 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6826 | mUserCpuTime.reset(false); |
| 6827 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6828 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 6829 | if (mCpuClusterSpeedTimesUs != null) { |
| 6830 | for (LongSamplingCounter[] speeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6831 | if (speeds != null) { |
| 6832 | for (LongSamplingCounter speed : speeds) { |
| 6833 | if (speed != null) { |
| 6834 | speed.reset(false); |
| 6835 | } |
| 6836 | } |
| 6837 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6838 | } |
| 6839 | } |
| 6840 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6841 | if (mCpuFreqTimeMs != null) { |
| 6842 | mCpuFreqTimeMs.reset(false); |
| 6843 | } |
| 6844 | if (mScreenOffCpuFreqTimeMs != null) { |
| 6845 | mScreenOffCpuFreqTimeMs.reset(false); |
| 6846 | } |
| 6847 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6848 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 6849 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 6850 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6851 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6852 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 6853 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6854 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6855 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6856 | } else { |
| 6857 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6858 | } |
| 6859 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6860 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6861 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6862 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6863 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6864 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6865 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6866 | timer.detach(); |
| 6867 | } else { |
| 6868 | active = true; |
| 6869 | } |
| 6870 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6871 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6872 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6873 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6874 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6875 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6876 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6877 | timer.detach(); |
| 6878 | } else { |
| 6879 | active = true; |
| 6880 | } |
| 6881 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6882 | mJobStats.cleanup(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 6883 | mJobCompletions.clear(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6884 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 6885 | Sensor s = mSensorStats.valueAt(ise); |
| 6886 | if (s.reset()) { |
| 6887 | mSensorStats.removeAt(ise); |
| 6888 | } else { |
| 6889 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6890 | } |
| 6891 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6892 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6893 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6894 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6895 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6896 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6897 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6898 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6899 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6900 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6901 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6902 | } else { |
| 6903 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6904 | } |
| 6905 | } |
| 6906 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6907 | if (mPackageStats.size() > 0) { |
| 6908 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 6909 | while (it.hasNext()) { |
| 6910 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 6911 | Pkg p = pkgEntry.getValue(); |
| 6912 | p.detach(); |
| 6913 | if (p.mServiceStats.size() > 0) { |
| 6914 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 6915 | = p.mServiceStats.entrySet().iterator(); |
| 6916 | while (it2.hasNext()) { |
| 6917 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 6918 | servEntry.getValue().detach(); |
| 6919 | } |
| 6920 | } |
| 6921 | } |
| 6922 | mPackageStats.clear(); |
| 6923 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6924 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6925 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 6926 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 6927 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6928 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6929 | if (mWifiRunningTimer != null) { |
| 6930 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6931 | } |
| 6932 | if (mFullWifiLockTimer != null) { |
| 6933 | mFullWifiLockTimer.detach(); |
| 6934 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6935 | if (mWifiScanTimer != null) { |
| 6936 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6937 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6938 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6939 | if (mWifiBatchedScanTimer[i] != null) { |
| 6940 | mWifiBatchedScanTimer[i].detach(); |
| 6941 | } |
| 6942 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6943 | if (mWifiMulticastTimer != null) { |
| 6944 | mWifiMulticastTimer.detach(); |
| 6945 | } |
| 6946 | if (mAudioTurnedOnTimer != null) { |
| 6947 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6948 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6949 | } |
| 6950 | if (mVideoTurnedOnTimer != null) { |
| 6951 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6952 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6953 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6954 | if (mFlashlightTurnedOnTimer != null) { |
| 6955 | mFlashlightTurnedOnTimer.detach(); |
| 6956 | mFlashlightTurnedOnTimer = null; |
| 6957 | } |
| 6958 | if (mCameraTurnedOnTimer != null) { |
| 6959 | mCameraTurnedOnTimer.detach(); |
| 6960 | mCameraTurnedOnTimer = null; |
| 6961 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6962 | if (mForegroundActivityTimer != null) { |
| 6963 | mForegroundActivityTimer.detach(); |
| 6964 | mForegroundActivityTimer = null; |
| 6965 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6966 | if (mForegroundServiceTimer != null) { |
| 6967 | mForegroundServiceTimer.detach(); |
| 6968 | mForegroundServiceTimer = null; |
| 6969 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6970 | if (mAggregatedPartialWakelockTimer != null) { |
| 6971 | mAggregatedPartialWakelockTimer.detach(); |
| 6972 | mAggregatedPartialWakelockTimer = null; |
| 6973 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6974 | if (mBluetoothScanTimer != null) { |
| 6975 | mBluetoothScanTimer.detach(); |
| 6976 | mBluetoothScanTimer = null; |
| 6977 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6978 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 6979 | mBluetoothUnoptimizedScanTimer.detach(); |
| 6980 | mBluetoothUnoptimizedScanTimer = null; |
| 6981 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6982 | if (mBluetoothScanResultCounter != null) { |
| 6983 | mBluetoothScanResultCounter.detach(); |
| 6984 | mBluetoothScanResultCounter = null; |
| 6985 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6986 | if (mBluetoothScanResultBgCounter != null) { |
| 6987 | mBluetoothScanResultBgCounter.detach(); |
| 6988 | mBluetoothScanResultBgCounter = null; |
| 6989 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6990 | if (mUserActivityCounters != null) { |
| 6991 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6992 | mUserActivityCounters[i].detach(); |
| 6993 | } |
| 6994 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6995 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6996 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6997 | mNetworkByteActivityCounters[i].detach(); |
| 6998 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6999 | } |
| 7000 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7001 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7002 | if (mWifiControllerActivity != null) { |
| 7003 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7004 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7005 | |
| 7006 | if (mBluetoothControllerActivity != null) { |
| 7007 | mBluetoothControllerActivity.detach(); |
| 7008 | } |
| 7009 | |
| 7010 | if (mModemControllerActivity != null) { |
| 7011 | mModemControllerActivity.detach(); |
| 7012 | } |
| 7013 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7014 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7015 | |
| 7016 | mUserCpuTime.detach(); |
| 7017 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7018 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7019 | if (mCpuClusterSpeedTimesUs != null) { |
| 7020 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7021 | if (cpuSpeeds != null) { |
| 7022 | for (LongSamplingCounter c : cpuSpeeds) { |
| 7023 | if (c != null) { |
| 7024 | c.detach(); |
| 7025 | } |
| 7026 | } |
| 7027 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7028 | } |
| 7029 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7030 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7031 | if (mCpuFreqTimeMs != null) { |
| 7032 | mCpuFreqTimeMs.detach(); |
| 7033 | } |
| 7034 | if (mScreenOffCpuFreqTimeMs != null) { |
| 7035 | mScreenOffCpuFreqTimeMs.detach(); |
| 7036 | } |
| 7037 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7038 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 7039 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7040 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7041 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7042 | return !active; |
| 7043 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7044 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7045 | void writeJobCompletionsToParcelLocked(Parcel out) { |
| 7046 | int NJC = mJobCompletions.size(); |
| 7047 | out.writeInt(NJC); |
| 7048 | for (int ijc=0; ijc<NJC; ijc++) { |
| 7049 | out.writeString(mJobCompletions.keyAt(ijc)); |
| 7050 | SparseIntArray types = mJobCompletions.valueAt(ijc); |
| 7051 | int NT = types.size(); |
| 7052 | out.writeInt(NT); |
| 7053 | for (int it=0; it<NT; it++) { |
| 7054 | out.writeInt(types.keyAt(it)); |
| 7055 | out.writeInt(types.valueAt(it)); |
| 7056 | } |
| 7057 | } |
| 7058 | } |
| 7059 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7060 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 7061 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7062 | mOnBatteryScreenOffBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7063 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7064 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 7065 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7066 | out.writeInt(NW); |
| 7067 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7068 | out.writeString(wakeStats.keyAt(iw)); |
| 7069 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7070 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | } |
| 7072 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 7073 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7074 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7075 | out.writeInt(NS); |
| 7076 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7077 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 7078 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7079 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 7080 | } |
| 7081 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7082 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7083 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7084 | out.writeInt(NJ); |
| 7085 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7086 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7087 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7088 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 7089 | } |
| 7090 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7091 | writeJobCompletionsToParcelLocked(out); |
| 7092 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7093 | int NSE = mSensorStats.size(); |
| 7094 | out.writeInt(NSE); |
| 7095 | for (int ise=0; ise<NSE; ise++) { |
| 7096 | out.writeInt(mSensorStats.keyAt(ise)); |
| 7097 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7098 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | } |
| 7100 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7101 | int NP = mProcessStats.size(); |
| 7102 | out.writeInt(NP); |
| 7103 | for (int ip=0; ip<NP; ip++) { |
| 7104 | out.writeString(mProcessStats.keyAt(ip)); |
| 7105 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | proc.writeToParcelLocked(out); |
| 7107 | } |
| 7108 | |
| 7109 | out.writeInt(mPackageStats.size()); |
| 7110 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 7111 | out.writeString(pkgEntry.getKey()); |
| 7112 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 7113 | pkg.writeToParcelLocked(out); |
| 7114 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7115 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7116 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7117 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7118 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7119 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7120 | out.writeInt(0); |
| 7121 | } |
| 7122 | if (mFullWifiLockTimer != null) { |
| 7123 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7124 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7125 | } else { |
| 7126 | out.writeInt(0); |
| 7127 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7128 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7129 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7130 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7131 | } else { |
| 7132 | out.writeInt(0); |
| 7133 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7134 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7135 | if (mWifiBatchedScanTimer[i] != null) { |
| 7136 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7137 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7138 | } else { |
| 7139 | out.writeInt(0); |
| 7140 | } |
| 7141 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7142 | if (mWifiMulticastTimer != null) { |
| 7143 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7144 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7145 | } else { |
| 7146 | out.writeInt(0); |
| 7147 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7148 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7149 | if (mAudioTurnedOnTimer != null) { |
| 7150 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7151 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7152 | } else { |
| 7153 | out.writeInt(0); |
| 7154 | } |
| 7155 | if (mVideoTurnedOnTimer != null) { |
| 7156 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7157 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7158 | } else { |
| 7159 | out.writeInt(0); |
| 7160 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7161 | if (mFlashlightTurnedOnTimer != null) { |
| 7162 | out.writeInt(1); |
| 7163 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 7164 | } else { |
| 7165 | out.writeInt(0); |
| 7166 | } |
| 7167 | if (mCameraTurnedOnTimer != null) { |
| 7168 | out.writeInt(1); |
| 7169 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 7170 | } else { |
| 7171 | out.writeInt(0); |
| 7172 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7173 | if (mForegroundActivityTimer != null) { |
| 7174 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7175 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7176 | } else { |
| 7177 | out.writeInt(0); |
| 7178 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7179 | if (mForegroundServiceTimer != null) { |
| 7180 | out.writeInt(1); |
| 7181 | mForegroundServiceTimer.writeToParcel(out, elapsedRealtimeUs); |
| 7182 | } else { |
| 7183 | out.writeInt(0); |
| 7184 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7185 | if (mAggregatedPartialWakelockTimer != null) { |
| 7186 | out.writeInt(1); |
| 7187 | mAggregatedPartialWakelockTimer.writeToParcel(out, elapsedRealtimeUs); |
| 7188 | } else { |
| 7189 | out.writeInt(0); |
| 7190 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7191 | if (mBluetoothScanTimer != null) { |
| 7192 | out.writeInt(1); |
| 7193 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 7194 | } else { |
| 7195 | out.writeInt(0); |
| 7196 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7197 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 7198 | out.writeInt(1); |
| 7199 | mBluetoothUnoptimizedScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 7200 | } else { |
| 7201 | out.writeInt(0); |
| 7202 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7203 | if (mBluetoothScanResultCounter != null) { |
| 7204 | out.writeInt(1); |
| 7205 | mBluetoothScanResultCounter.writeToParcel(out); |
| 7206 | } else { |
| 7207 | out.writeInt(0); |
| 7208 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7209 | if (mBluetoothScanResultBgCounter != null) { |
| 7210 | out.writeInt(1); |
| 7211 | mBluetoothScanResultBgCounter.writeToParcel(out); |
| 7212 | } else { |
| 7213 | out.writeInt(0); |
| 7214 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7215 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7216 | if (mProcessStateTimer[i] != null) { |
| 7217 | out.writeInt(1); |
| 7218 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 7219 | } else { |
| 7220 | out.writeInt(0); |
| 7221 | } |
| 7222 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7223 | if (mVibratorOnTimer != null) { |
| 7224 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7225 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7226 | } else { |
| 7227 | out.writeInt(0); |
| 7228 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7229 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7230 | out.writeInt(1); |
| 7231 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 7232 | mUserActivityCounters[i].writeToParcel(out); |
| 7233 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7234 | } else { |
| 7235 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7236 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7237 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7238 | out.writeInt(1); |
| 7239 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7240 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 7241 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7242 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7243 | mMobileRadioActiveTime.writeToParcel(out); |
| 7244 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7245 | } else { |
| 7246 | out.writeInt(0); |
| 7247 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7248 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7249 | if (mWifiControllerActivity != null) { |
| 7250 | out.writeInt(1); |
| 7251 | mWifiControllerActivity.writeToParcel(out, 0); |
| 7252 | } else { |
| 7253 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7254 | } |
| 7255 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7256 | if (mBluetoothControllerActivity != null) { |
| 7257 | out.writeInt(1); |
| 7258 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 7259 | } else { |
| 7260 | out.writeInt(0); |
| 7261 | } |
| 7262 | |
| 7263 | if (mModemControllerActivity != null) { |
| 7264 | out.writeInt(1); |
| 7265 | mModemControllerActivity.writeToParcel(out, 0); |
| 7266 | } else { |
| 7267 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7268 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7269 | |
| 7270 | mUserCpuTime.writeToParcel(out); |
| 7271 | mSystemCpuTime.writeToParcel(out); |
| 7272 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7273 | if (mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7274 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7275 | out.writeInt(mCpuClusterSpeedTimesUs.length); |
| 7276 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7277 | if (cpuSpeeds != null) { |
| 7278 | out.writeInt(1); |
| 7279 | out.writeInt(cpuSpeeds.length); |
| 7280 | for (LongSamplingCounter c : cpuSpeeds) { |
| 7281 | if (c != null) { |
| 7282 | out.writeInt(1); |
| 7283 | c.writeToParcel(out); |
| 7284 | } else { |
| 7285 | out.writeInt(0); |
| 7286 | } |
| 7287 | } |
| 7288 | } else { |
| 7289 | out.writeInt(0); |
| 7290 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7291 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7292 | } else { |
| 7293 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7294 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7295 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 7296 | LongSamplingCounterArray.writeToParcel(out, mCpuFreqTimeMs); |
| 7297 | LongSamplingCounterArray.writeToParcel(out, mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7298 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7299 | if (mMobileRadioApWakeupCount != null) { |
| 7300 | out.writeInt(1); |
| 7301 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 7302 | } else { |
| 7303 | out.writeInt(0); |
| 7304 | } |
| 7305 | |
| 7306 | if (mWifiRadioApWakeupCount != null) { |
| 7307 | out.writeInt(1); |
| 7308 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 7309 | } else { |
| 7310 | out.writeInt(0); |
| 7311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | } |
| 7313 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7314 | void readJobCompletionsFromParcelLocked(Parcel in) { |
| 7315 | int numJobCompletions = in.readInt(); |
| 7316 | mJobCompletions.clear(); |
| 7317 | for (int j = 0; j < numJobCompletions; j++) { |
| 7318 | String jobName = in.readString(); |
| 7319 | int numTypes = in.readInt(); |
| 7320 | if (numTypes > 0) { |
| 7321 | SparseIntArray types = new SparseIntArray(); |
| 7322 | for (int k = 0; k < numTypes; k++) { |
| 7323 | int type = in.readInt(); |
| 7324 | int count = in.readInt(); |
| 7325 | types.put(type, count); |
| 7326 | } |
| 7327 | mJobCompletions.put(jobName, types); |
| 7328 | } |
| 7329 | } |
| 7330 | } |
| 7331 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7332 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7333 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7334 | mOnBatteryScreenOffBackgroundTimeBase.readFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7336 | int numWakelocks = in.readInt(); |
| 7337 | mWakelockStats.clear(); |
| 7338 | for (int j = 0; j < numWakelocks; j++) { |
| 7339 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7340 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7341 | wakelock.readFromParcelLocked( |
| 7342 | timeBase, screenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7343 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | } |
| 7345 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7346 | int numSyncs = in.readInt(); |
| 7347 | mSyncStats.clear(); |
| 7348 | for (int j = 0; j < numSyncs; j++) { |
| 7349 | String syncName = in.readString(); |
| 7350 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 7351 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 7352 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7353 | } |
| 7354 | } |
| 7355 | |
| 7356 | int numJobs = in.readInt(); |
| 7357 | mJobStats.clear(); |
| 7358 | for (int j = 0; j < numJobs; j++) { |
| 7359 | String jobName = in.readString(); |
| 7360 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7361 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 7362 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7363 | } |
| 7364 | } |
| 7365 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7366 | readJobCompletionsFromParcelLocked(in); |
| 7367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7368 | int numSensors = in.readInt(); |
| 7369 | mSensorStats.clear(); |
| 7370 | for (int k = 0; k < numSensors; k++) { |
| 7371 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7372 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7373 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 7374 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7375 | mSensorStats.put(sensorNumber, sensor); |
| 7376 | } |
| 7377 | |
| 7378 | int numProcs = in.readInt(); |
| 7379 | mProcessStats.clear(); |
| 7380 | for (int k = 0; k < numProcs; k++) { |
| 7381 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7382 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | proc.readFromParcelLocked(in); |
| 7384 | mProcessStats.put(processName, proc); |
| 7385 | } |
| 7386 | |
| 7387 | int numPkgs = in.readInt(); |
| 7388 | mPackageStats.clear(); |
| 7389 | for (int l = 0; l < numPkgs; l++) { |
| 7390 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7391 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | pkg.readFromParcelLocked(in); |
| 7393 | mPackageStats.put(packageName, pkg); |
| 7394 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7395 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7396 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7397 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7398 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 7399 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7400 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7401 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7402 | } |
| 7403 | mFullWifiLockOut = false; |
| 7404 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7405 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 7406 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7407 | } else { |
| 7408 | mFullWifiLockTimer = null; |
| 7409 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7410 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7411 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7412 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 7413 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 7414 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7415 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7416 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7417 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7418 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 7419 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7420 | if (in.readInt() != 0) { |
| 7421 | makeWifiBatchedScanBin(i, in); |
| 7422 | } else { |
| 7423 | mWifiBatchedScanTimer[i] = null; |
| 7424 | } |
| 7425 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7426 | mWifiMulticastEnabled = false; |
| 7427 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7428 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 7429 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7430 | } else { |
| 7431 | mWifiMulticastTimer = null; |
| 7432 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7433 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7434 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 7435 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7436 | } else { |
| 7437 | mAudioTurnedOnTimer = null; |
| 7438 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7439 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7440 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 7441 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7442 | } else { |
| 7443 | mVideoTurnedOnTimer = null; |
| 7444 | } |
| 7445 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7446 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7447 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7448 | } else { |
| 7449 | mFlashlightTurnedOnTimer = null; |
| 7450 | } |
| 7451 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7452 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 7453 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7454 | } else { |
| 7455 | mCameraTurnedOnTimer = null; |
| 7456 | } |
| 7457 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7458 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7459 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7460 | } else { |
| 7461 | mForegroundActivityTimer = null; |
| 7462 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7463 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7464 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7465 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase, in); |
| 7466 | } else { |
| 7467 | mForegroundServiceTimer = null; |
| 7468 | } |
| 7469 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7470 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 7471 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 7472 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, |
| 7473 | in); |
| 7474 | } else { |
| 7475 | mAggregatedPartialWakelockTimer = null; |
| 7476 | } |
| 7477 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7478 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 7479 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 7480 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7481 | } else { |
| 7482 | mBluetoothScanTimer = null; |
| 7483 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7484 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7485 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 7486 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 7487 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); |
| 7488 | } else { |
| 7489 | mBluetoothUnoptimizedScanTimer = null; |
| 7490 | } |
| 7491 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7492 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 7493 | } else { |
| 7494 | mBluetoothScanResultCounter = null; |
| 7495 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7496 | if (in.readInt() != 0) { |
| 7497 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase, in); |
| 7498 | } else { |
| 7499 | mBluetoothScanResultBgCounter = null; |
| 7500 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7501 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7502 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7503 | if (in.readInt() != 0) { |
| 7504 | makeProcessState(i, in); |
| 7505 | } else { |
| 7506 | mProcessStateTimer[i] = null; |
| 7507 | } |
| 7508 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7509 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7510 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 7511 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7512 | } else { |
| 7513 | mVibratorOnTimer = null; |
| 7514 | } |
| 7515 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7516 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 7517 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7518 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7519 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7520 | } else { |
| 7521 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7522 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7523 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7524 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 7525 | mNetworkPacketActivityCounters |
| 7526 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7527 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7528 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7529 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7530 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7531 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7532 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7533 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7534 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7535 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7536 | mNetworkByteActivityCounters = null; |
| 7537 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7538 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7539 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7540 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7541 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7542 | NUM_WIFI_TX_LEVELS, in); |
| 7543 | } else { |
| 7544 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7545 | } |
| 7546 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7547 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7548 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7549 | NUM_BT_TX_LEVELS, in); |
| 7550 | } else { |
| 7551 | mBluetoothControllerActivity = null; |
| 7552 | } |
| 7553 | |
| 7554 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7555 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7556 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 7557 | } else { |
| 7558 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7559 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7560 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7561 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7562 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7563 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7564 | if (in.readInt() != 0) { |
| 7565 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7566 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7567 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7568 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7569 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7570 | mCpuClusterSpeedTimesUs = new LongSamplingCounter[numCpuClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7571 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 7572 | if (in.readInt() != 0) { |
| 7573 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7574 | if (mBsi.mPowerProfile != null && |
| 7575 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7576 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 7577 | } |
| 7578 | |
| 7579 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7580 | mCpuClusterSpeedTimesUs[cluster] = cpuSpeeds; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7581 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 7582 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7583 | cpuSpeeds[speed] = new LongSamplingCounter( |
| 7584 | mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7585 | } |
| 7586 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 7587 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7588 | mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7589 | } |
| 7590 | } |
| 7591 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7592 | mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7593 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7594 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 7595 | mCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel(in, mBsi.mOnBatteryTimeBase); |
| 7596 | mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel( |
| 7597 | in, mBsi.mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7598 | |
| 7599 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7600 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7601 | } else { |
| 7602 | mMobileRadioApWakeupCount = null; |
| 7603 | } |
| 7604 | |
| 7605 | if (in.readInt() != 0) { |
| 7606 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7607 | } else { |
| 7608 | mWifiRadioApWakeupCount = null; |
| 7609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | /** |
| 7613 | * The statistics associated with a particular wake lock. |
| 7614 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7615 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 7616 | /** |
| 7617 | * BatteryStatsImpl that we are associated with. |
| 7618 | */ |
| 7619 | protected BatteryStatsImpl mBsi; |
| 7620 | |
| 7621 | /** |
| 7622 | * BatteryStatsImpl that we are associated with. |
| 7623 | */ |
| 7624 | protected Uid mUid; |
| 7625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | /** |
| 7627 | * How long (in ms) this uid has been keeping the device partially awake. |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7628 | * Tracks both the total time and the time while the app was in the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7630 | DualTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7631 | |
| 7632 | /** |
| 7633 | * How long (in ms) this uid has been keeping the device fully awake. |
| 7634 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7635 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7636 | |
| 7637 | /** |
| 7638 | * How long (in ms) this uid has had a window keeping the device awake. |
| 7639 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7640 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7641 | |
| 7642 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7643 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7644 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7645 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7646 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7647 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 7648 | mBsi = bsi; |
| 7649 | mUid = uid; |
| 7650 | } |
| 7651 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7652 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7653 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 7654 | * proper timer pool from the given BatteryStatsImpl object. |
| 7655 | * |
| 7656 | * @param in the Parcel to be read from. |
| 7657 | * return a new Timer, or null. |
| 7658 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7659 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 7660 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7661 | if (in.readInt() == 0) { |
| 7662 | return null; |
| 7663 | } |
| 7664 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7665 | return new StopwatchTimer(mBsi.mClocks, mUid, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7666 | } |
| 7667 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7668 | /** |
| 7669 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 7670 | * proper timer pool from the given BatteryStatsImpl object. |
| 7671 | * |
| 7672 | * @param in the Parcel to be read from. |
| 7673 | * return a new Timer, or null. |
| 7674 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7675 | private DualTimer readDualTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
| 7676 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7677 | if (in.readInt() == 0) { |
| 7678 | return null; |
| 7679 | } |
| 7680 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7681 | return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7682 | } |
| 7683 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7684 | boolean reset() { |
| 7685 | boolean wlactive = false; |
| 7686 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7687 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7688 | } |
| 7689 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7690 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7691 | } |
| 7692 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7693 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7694 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7695 | if (mTimerDraw != null) { |
| 7696 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7697 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7698 | if (!wlactive) { |
| 7699 | if (mTimerFull != null) { |
| 7700 | mTimerFull.detach(); |
| 7701 | mTimerFull = null; |
| 7702 | } |
| 7703 | if (mTimerPartial != null) { |
| 7704 | mTimerPartial.detach(); |
| 7705 | mTimerPartial = null; |
| 7706 | } |
| 7707 | if (mTimerWindow != null) { |
| 7708 | mTimerWindow.detach(); |
| 7709 | mTimerWindow = null; |
| 7710 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7711 | if (mTimerDraw != null) { |
| 7712 | mTimerDraw.detach(); |
| 7713 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7714 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7715 | } |
| 7716 | return !wlactive; |
| 7717 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7718 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7719 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, |
| 7720 | TimeBase screenOffBgTimeBase, Parcel in) { |
| 7721 | mTimerPartial = readDualTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 7722 | mBsi.mPartialTimers, screenOffTimeBase, screenOffBgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7723 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 7724 | mBsi.mFullTimers, timeBase, in); |
| 7725 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 7726 | mBsi.mWindowTimers, timeBase, in); |
| 7727 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 7728 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7729 | } |
| 7730 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7731 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 7732 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 7733 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 7734 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7735 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7736 | } |
| 7737 | |
| 7738 | @Override |
| 7739 | public Timer getWakeTime(int type) { |
| 7740 | switch (type) { |
| 7741 | case WAKE_TYPE_FULL: return mTimerFull; |
| 7742 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 7743 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7744 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | default: throw new IllegalArgumentException("type = " + type); |
| 7746 | } |
| 7747 | } |
| 7748 | } |
| 7749 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7750 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 7751 | /** |
| 7752 | * BatteryStatsImpl that we are associated with. |
| 7753 | */ |
| 7754 | protected BatteryStatsImpl mBsi; |
| 7755 | |
| 7756 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7757 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7758 | */ |
| 7759 | protected Uid mUid; |
| 7760 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7761 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7762 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7763 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7764 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 7765 | mBsi = bsi; |
| 7766 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7767 | mHandle = handle; |
| 7768 | } |
| 7769 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7770 | private DualTimer readTimersFromParcel( |
| 7771 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7772 | if (in.readInt() == 0) { |
| 7773 | return null; |
| 7774 | } |
| 7775 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7776 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7777 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7778 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7779 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7780 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7781 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7782 | } |
| 7783 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7784 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7785 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7786 | mTimer = null; |
| 7787 | return true; |
| 7788 | } |
| 7789 | return false; |
| 7790 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7791 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7792 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 7793 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | } |
| 7795 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7796 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7797 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7798 | } |
| 7799 | |
| 7800 | @Override |
| 7801 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7802 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7803 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7804 | |
| 7805 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7806 | public Timer getSensorBackgroundTime() { |
| 7807 | if (mTimer == null) { |
| 7808 | return null; |
| 7809 | } |
| 7810 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7811 | } |
| 7812 | |
| 7813 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7814 | public int getHandle() { |
| 7815 | return mHandle; |
| 7816 | } |
| 7817 | } |
| 7818 | |
| 7819 | /** |
| 7820 | * The statistics associated with a particular process. |
| 7821 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7822 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 7823 | /** |
| 7824 | * BatteryStatsImpl that we are associated with. |
| 7825 | */ |
| 7826 | protected BatteryStatsImpl mBsi; |
| 7827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7828 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7829 | * The name of this process. |
| 7830 | */ |
| 7831 | final String mName; |
| 7832 | |
| 7833 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7834 | * Remains true until removed from the stats. |
| 7835 | */ |
| 7836 | boolean mActive = true; |
| 7837 | |
| 7838 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7839 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | */ |
| 7841 | long mUserTime; |
| 7842 | |
| 7843 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7844 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7845 | */ |
| 7846 | long mSystemTime; |
| 7847 | |
| 7848 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7849 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7850 | */ |
| 7851 | long mForegroundTime; |
| 7852 | |
| 7853 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7854 | * Number of times the process has been started. |
| 7855 | */ |
| 7856 | int mStarts; |
| 7857 | |
| 7858 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7859 | * Number of times the process has crashed. |
| 7860 | */ |
| 7861 | int mNumCrashes; |
| 7862 | |
| 7863 | /** |
| 7864 | * Number of times the process has had an ANR. |
| 7865 | */ |
| 7866 | int mNumAnrs; |
| 7867 | |
| 7868 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | * The amount of user time loaded from a previous save. |
| 7870 | */ |
| 7871 | long mLoadedUserTime; |
| 7872 | |
| 7873 | /** |
| 7874 | * The amount of system time loaded from a previous save. |
| 7875 | */ |
| 7876 | long mLoadedSystemTime; |
| 7877 | |
| 7878 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7879 | * The amount of foreground time loaded from a previous save. |
| 7880 | */ |
| 7881 | long mLoadedForegroundTime; |
| 7882 | |
| 7883 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7884 | * The number of times the process has started from a previous save. |
| 7885 | */ |
| 7886 | int mLoadedStarts; |
| 7887 | |
| 7888 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7889 | * 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] | 7890 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7891 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | |
| 7893 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7894 | * 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] | 7895 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7896 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7897 | |
| 7898 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7899 | * The amount of user time when last unplugged. |
| 7900 | */ |
| 7901 | long mUnpluggedUserTime; |
| 7902 | |
| 7903 | /** |
| 7904 | * The amount of system time when last unplugged. |
| 7905 | */ |
| 7906 | long mUnpluggedSystemTime; |
| 7907 | |
| 7908 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7909 | * The amount of foreground time since unplugged. |
| 7910 | */ |
| 7911 | long mUnpluggedForegroundTime; |
| 7912 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7913 | /** |
| 7914 | * The number of times the process has started before unplugged. |
| 7915 | */ |
| 7916 | int mUnpluggedStarts; |
| 7917 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7918 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7919 | * Number of times the process has crashed before unplugged. |
| 7920 | */ |
| 7921 | int mUnpluggedNumCrashes; |
| 7922 | |
| 7923 | /** |
| 7924 | * Number of times the process has had an ANR before unplugged. |
| 7925 | */ |
| 7926 | int mUnpluggedNumAnrs; |
| 7927 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7928 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7929 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7930 | public Proc(BatteryStatsImpl bsi, String name) { |
| 7931 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7932 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7933 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7934 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7935 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7936 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7937 | mUnpluggedUserTime = mUserTime; |
| 7938 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7939 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7940 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7941 | mUnpluggedNumCrashes = mNumCrashes; |
| 7942 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7943 | } |
| 7944 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7945 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7947 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7948 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7949 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7950 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7951 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7952 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7953 | public int countExcessivePowers() { |
| 7954 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7955 | } |
| 7956 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7957 | public ExcessivePower getExcessivePower(int i) { |
| 7958 | if (mExcessivePower != null) { |
| 7959 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7960 | } |
| 7961 | return null; |
| 7962 | } |
| 7963 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7964 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 7965 | if (mExcessivePower == null) { |
| 7966 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 7967 | } |
| 7968 | ExcessivePower ew = new ExcessivePower(); |
| 7969 | ew.type = ExcessivePower.TYPE_CPU; |
| 7970 | ew.overTime = overTime; |
| 7971 | ew.usedTime = usedTime; |
| 7972 | mExcessivePower.add(ew); |
| 7973 | } |
| 7974 | |
| 7975 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 7976 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7977 | out.writeInt(0); |
| 7978 | return; |
| 7979 | } |
| 7980 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7981 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7982 | out.writeInt(N); |
| 7983 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7984 | ExcessivePower ew = mExcessivePower.get(i); |
| 7985 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7986 | out.writeLong(ew.overTime); |
| 7987 | out.writeLong(ew.usedTime); |
| 7988 | } |
| 7989 | } |
| 7990 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7991 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7992 | final int N = in.readInt(); |
| 7993 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7994 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7995 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7996 | } |
| 7997 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7998 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7999 | throw new ParcelFormatException( |
| 8000 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 8001 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8002 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 8003 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8004 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8005 | ExcessivePower ew = new ExcessivePower(); |
| 8006 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8007 | ew.overTime = in.readLong(); |
| 8008 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8009 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8010 | } |
| 8011 | } |
| 8012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | void writeToParcelLocked(Parcel out) { |
| 8014 | out.writeLong(mUserTime); |
| 8015 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8016 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8017 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8018 | out.writeInt(mNumCrashes); |
| 8019 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | out.writeLong(mLoadedUserTime); |
| 8021 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8022 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8023 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8024 | out.writeInt(mLoadedNumCrashes); |
| 8025 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8026 | out.writeLong(mUnpluggedUserTime); |
| 8027 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8028 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8029 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8030 | out.writeInt(mUnpluggedNumCrashes); |
| 8031 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8032 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | } |
| 8034 | |
| 8035 | void readFromParcelLocked(Parcel in) { |
| 8036 | mUserTime = in.readLong(); |
| 8037 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8038 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8039 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8040 | mNumCrashes = in.readInt(); |
| 8041 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8042 | mLoadedUserTime = in.readLong(); |
| 8043 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8044 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8046 | mLoadedNumCrashes = in.readInt(); |
| 8047 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | mUnpluggedUserTime = in.readLong(); |
| 8049 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8050 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8051 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8052 | mUnpluggedNumCrashes = in.readInt(); |
| 8053 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8054 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | } |
| 8056 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8057 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8058 | mUserTime += utime; |
| 8059 | mSystemTime += stime; |
| 8060 | } |
| 8061 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8062 | public void addForegroundTimeLocked(long ttime) { |
| 8063 | mForegroundTime += ttime; |
| 8064 | } |
| 8065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8066 | public void incStartsLocked() { |
| 8067 | mStarts++; |
| 8068 | } |
| 8069 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8070 | public void incNumCrashesLocked() { |
| 8071 | mNumCrashes++; |
| 8072 | } |
| 8073 | |
| 8074 | public void incNumAnrsLocked() { |
| 8075 | mNumAnrs++; |
| 8076 | } |
| 8077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8078 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8079 | public boolean isActive() { |
| 8080 | return mActive; |
| 8081 | } |
| 8082 | |
| 8083 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8084 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8085 | long val = mUserTime; |
| 8086 | if (which == STATS_CURRENT) { |
| 8087 | val -= mLoadedUserTime; |
| 8088 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8089 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8090 | } |
| 8091 | return val; |
| 8092 | } |
| 8093 | |
| 8094 | @Override |
| 8095 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8096 | long val = mSystemTime; |
| 8097 | if (which == STATS_CURRENT) { |
| 8098 | val -= mLoadedSystemTime; |
| 8099 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8100 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8101 | } |
| 8102 | return val; |
| 8103 | } |
| 8104 | |
| 8105 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8106 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8107 | long val = mForegroundTime; |
| 8108 | if (which == STATS_CURRENT) { |
| 8109 | val -= mLoadedForegroundTime; |
| 8110 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8111 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8112 | } |
| 8113 | return val; |
| 8114 | } |
| 8115 | |
| 8116 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8117 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8118 | int val = mStarts; |
| 8119 | if (which == STATS_CURRENT) { |
| 8120 | val -= mLoadedStarts; |
| 8121 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8122 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8123 | } |
| 8124 | return val; |
| 8125 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 8126 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8127 | @Override |
| 8128 | public int getNumCrashes(int which) { |
| 8129 | int val = mNumCrashes; |
| 8130 | if (which == STATS_CURRENT) { |
| 8131 | val -= mLoadedNumCrashes; |
| 8132 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8133 | val -= mUnpluggedNumCrashes; |
| 8134 | } |
| 8135 | return val; |
| 8136 | } |
| 8137 | |
| 8138 | @Override |
| 8139 | public int getNumAnrs(int which) { |
| 8140 | int val = mNumAnrs; |
| 8141 | if (which == STATS_CURRENT) { |
| 8142 | val -= mLoadedNumAnrs; |
| 8143 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8144 | val -= mUnpluggedNumAnrs; |
| 8145 | } |
| 8146 | return val; |
| 8147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8148 | } |
| 8149 | |
| 8150 | /** |
| 8151 | * The statistics associated with a particular package. |
| 8152 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8153 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 8154 | /** |
| 8155 | * BatteryStatsImpl that we are associated with. |
| 8156 | */ |
| 8157 | protected BatteryStatsImpl mBsi; |
| 8158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8159 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8160 | * Number of times wakeup alarms have occurred for this app. |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 8161 | * On screen-off timebase starting in report v25. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8162 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8163 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | |
| 8165 | /** |
| 8166 | * The statics we have collected for this package's services. |
| 8167 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8168 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8169 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8170 | public Pkg(BatteryStatsImpl bsi) { |
| 8171 | mBsi = bsi; |
| 8172 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8174 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8175 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8176 | } |
| 8177 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8178 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8179 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8180 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8181 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8182 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8183 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8185 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8186 | int numWA = in.readInt(); |
| 8187 | mWakeupAlarms.clear(); |
| 8188 | for (int i=0; i<numWA; i++) { |
| 8189 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 8190 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryScreenOffTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | |
| 8193 | int numServs = in.readInt(); |
| 8194 | mServiceStats.clear(); |
| 8195 | for (int m = 0; m < numServs; m++) { |
| 8196 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8197 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8198 | mServiceStats.put(serviceName, serv); |
| 8199 | |
| 8200 | serv.readFromParcelLocked(in); |
| 8201 | } |
| 8202 | } |
| 8203 | |
| 8204 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8205 | int numWA = mWakeupAlarms.size(); |
| 8206 | out.writeInt(numWA); |
| 8207 | for (int i=0; i<numWA; i++) { |
| 8208 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 8209 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 8210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8211 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8212 | final int NS = mServiceStats.size(); |
| 8213 | out.writeInt(NS); |
| 8214 | for (int i=0; i<NS; i++) { |
| 8215 | out.writeString(mServiceStats.keyAt(i)); |
| 8216 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8217 | serv.writeToParcelLocked(out); |
| 8218 | } |
| 8219 | } |
| 8220 | |
| 8221 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8222 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 8223 | return mWakeupAlarms; |
| 8224 | } |
| 8225 | |
| 8226 | public void noteWakeupAlarmLocked(String tag) { |
| 8227 | Counter c = mWakeupAlarms.get(tag); |
| 8228 | if (c == null) { |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 8229 | c = new Counter(mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8230 | mWakeupAlarms.put(tag, c); |
| 8231 | } |
| 8232 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | } |
| 8234 | |
| 8235 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8236 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 8237 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8238 | } |
| 8239 | |
| 8240 | /** |
| 8241 | * The statistics associated with a particular service. |
| 8242 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8243 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 8244 | /** |
| 8245 | * BatteryStatsImpl that we are associated with. |
| 8246 | */ |
| 8247 | protected BatteryStatsImpl mBsi; |
| 8248 | |
| 8249 | /** |
| 8250 | * The android package in which this service resides. |
| 8251 | */ |
| 8252 | protected Pkg mPkg; |
| 8253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | /** |
| 8255 | * Total time (ms in battery uptime) the service has been left started. |
| 8256 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8257 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8258 | |
| 8259 | /** |
| 8260 | * If service has been started and not yet stopped, this is |
| 8261 | * when it was started. |
| 8262 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8263 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8264 | |
| 8265 | /** |
| 8266 | * True if we are currently running. |
| 8267 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8268 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8269 | |
| 8270 | /** |
| 8271 | * Total number of times startService() has been called. |
| 8272 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8273 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | |
| 8275 | /** |
| 8276 | * Total time (ms in battery uptime) the service has been left launched. |
| 8277 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8278 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | |
| 8280 | /** |
| 8281 | * If service has been launched and not yet exited, this is |
| 8282 | * when it was launched (ms in battery uptime). |
| 8283 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8284 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8285 | |
| 8286 | /** |
| 8287 | * True if we are currently launched. |
| 8288 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8289 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8290 | |
| 8291 | /** |
| 8292 | * Total number times the service has been launched. |
| 8293 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8294 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8295 | |
| 8296 | /** |
| 8297 | * The amount of time spent started loaded from a previous save |
| 8298 | * (ms in battery uptime). |
| 8299 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8300 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8301 | |
| 8302 | /** |
| 8303 | * The number of starts loaded from a previous save. |
| 8304 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8305 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8306 | |
| 8307 | /** |
| 8308 | * The number of launches loaded from a previous save. |
| 8309 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8310 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8311 | |
| 8312 | /** |
| 8313 | * The amount of time spent started as of the last run (ms |
| 8314 | * in battery uptime). |
| 8315 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8316 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8317 | |
| 8318 | /** |
| 8319 | * The number of starts as of the last run. |
| 8320 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8321 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8322 | |
| 8323 | /** |
| 8324 | * The number of launches as of the last run. |
| 8325 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8326 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8327 | |
| 8328 | /** |
| 8329 | * The amount of time spent started when last unplugged (ms |
| 8330 | * in battery uptime). |
| 8331 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8332 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8333 | |
| 8334 | /** |
| 8335 | * The number of starts when last unplugged. |
| 8336 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8337 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8338 | |
| 8339 | /** |
| 8340 | * The number of launches when last unplugged. |
| 8341 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8342 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8343 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8344 | /** |
| 8345 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 8346 | */ |
| 8347 | public Serv(BatteryStatsImpl bsi) { |
| 8348 | mBsi = bsi; |
| 8349 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8350 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8351 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8352 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 8353 | long baseRealtime) { |
| 8354 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8355 | mUnpluggedStarts = mStarts; |
| 8356 | mUnpluggedLaunches = mLaunches; |
| 8357 | } |
| 8358 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8359 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 8360 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8361 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8362 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8363 | /** |
| 8364 | * Remove this Serv as a listener from the time base. |
| 8365 | */ |
| 8366 | public void detach() { |
| 8367 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8368 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8369 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8370 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8371 | mStartTime = in.readLong(); |
| 8372 | mRunningSince = in.readLong(); |
| 8373 | mRunning = in.readInt() != 0; |
| 8374 | mStarts = in.readInt(); |
| 8375 | mLaunchedTime = in.readLong(); |
| 8376 | mLaunchedSince = in.readLong(); |
| 8377 | mLaunched = in.readInt() != 0; |
| 8378 | mLaunches = in.readInt(); |
| 8379 | mLoadedStartTime = in.readLong(); |
| 8380 | mLoadedStarts = in.readInt(); |
| 8381 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8382 | mLastStartTime = 0; |
| 8383 | mLastStarts = 0; |
| 8384 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8385 | mUnpluggedStartTime = in.readLong(); |
| 8386 | mUnpluggedStarts = in.readInt(); |
| 8387 | mUnpluggedLaunches = in.readInt(); |
| 8388 | } |
| 8389 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8390 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8391 | out.writeLong(mStartTime); |
| 8392 | out.writeLong(mRunningSince); |
| 8393 | out.writeInt(mRunning ? 1 : 0); |
| 8394 | out.writeInt(mStarts); |
| 8395 | out.writeLong(mLaunchedTime); |
| 8396 | out.writeLong(mLaunchedSince); |
| 8397 | out.writeInt(mLaunched ? 1 : 0); |
| 8398 | out.writeInt(mLaunches); |
| 8399 | out.writeLong(mLoadedStartTime); |
| 8400 | out.writeInt(mLoadedStarts); |
| 8401 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8402 | out.writeLong(mUnpluggedStartTime); |
| 8403 | out.writeInt(mUnpluggedStarts); |
| 8404 | out.writeInt(mUnpluggedLaunches); |
| 8405 | } |
| 8406 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8407 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8408 | if (!mLaunched) return mLaunchedTime; |
| 8409 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 8410 | } |
| 8411 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8412 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8413 | if (!mRunning) return mStartTime; |
| 8414 | return mStartTime + batteryUptime - mRunningSince; |
| 8415 | } |
| 8416 | |
| 8417 | public void startLaunchedLocked() { |
| 8418 | if (!mLaunched) { |
| 8419 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8420 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8421 | mLaunched = true; |
| 8422 | } |
| 8423 | } |
| 8424 | |
| 8425 | public void stopLaunchedLocked() { |
| 8426 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8427 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8428 | if (time > 0) { |
| 8429 | mLaunchedTime += time; |
| 8430 | } else { |
| 8431 | mLaunches--; |
| 8432 | } |
| 8433 | mLaunched = false; |
| 8434 | } |
| 8435 | } |
| 8436 | |
| 8437 | public void startRunningLocked() { |
| 8438 | if (!mRunning) { |
| 8439 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8440 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8441 | mRunning = true; |
| 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | public void stopRunningLocked() { |
| 8446 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8447 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8448 | if (time > 0) { |
| 8449 | mStartTime += time; |
| 8450 | } else { |
| 8451 | mStarts--; |
| 8452 | } |
| 8453 | mRunning = false; |
| 8454 | } |
| 8455 | } |
| 8456 | |
| 8457 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8458 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8459 | } |
| 8460 | |
| 8461 | @Override |
| 8462 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8463 | int val = mLaunches; |
| 8464 | if (which == STATS_CURRENT) { |
| 8465 | val -= mLoadedLaunches; |
| 8466 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8467 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | return val; |
| 8470 | } |
| 8471 | |
| 8472 | @Override |
| 8473 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8474 | long val = getStartTimeToNowLocked(now); |
| 8475 | if (which == STATS_CURRENT) { |
| 8476 | val -= mLoadedStartTime; |
| 8477 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8478 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8479 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8480 | return val; |
| 8481 | } |
| 8482 | |
| 8483 | @Override |
| 8484 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8485 | int val = mStarts; |
| 8486 | if (which == STATS_CURRENT) { |
| 8487 | val -= mLoadedStarts; |
| 8488 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8489 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8490 | } |
| 8491 | |
| 8492 | return val; |
| 8493 | } |
| 8494 | } |
| 8495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8496 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8497 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | } |
| 8499 | } |
| 8500 | |
| 8501 | /** |
| 8502 | * Retrieve the statistics object for a particular process, creating |
| 8503 | * if needed. |
| 8504 | */ |
| 8505 | public Proc getProcessStatsLocked(String name) { |
| 8506 | Proc ps = mProcessStats.get(name); |
| 8507 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8508 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8509 | mProcessStats.put(name, ps); |
| 8510 | } |
| 8511 | |
| 8512 | return ps; |
| 8513 | } |
| 8514 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8515 | public void updateUidProcessStateLocked(int procState) { |
| 8516 | int uidRunningState; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8517 | // Make special note of Foreground Services |
| 8518 | final boolean userAwareService = |
| 8519 | (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8520 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 8521 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 8522 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 8523 | uidRunningState = PROCESS_STATE_TOP; |
| 8524 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 8525 | // Persistent and other foreground states go here. |
| 8526 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 8527 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 8528 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 8529 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 8530 | // Persistent and other foreground states go here. |
| 8531 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 8532 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 8533 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8534 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8535 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8536 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8537 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8538 | if (mProcessState == uidRunningState && userAwareService == mInForegroundService) { |
| 8539 | return; |
| 8540 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8541 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8542 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8543 | if (mProcessState != uidRunningState) { |
| 8544 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8545 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8546 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 8547 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8548 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8549 | mProcessState = uidRunningState; |
| 8550 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 8551 | if (mProcessStateTimer[uidRunningState] == null) { |
| 8552 | makeProcessState(uidRunningState, null); |
| 8553 | } |
| 8554 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
| 8555 | } |
| 8556 | |
| 8557 | updateOnBatteryBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 8558 | updateOnBatteryScreenOffBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8559 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8560 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8561 | if (userAwareService != mInForegroundService) { |
| 8562 | if (userAwareService) { |
| 8563 | noteForegroundServiceResumedLocked(elapsedRealtimeMs); |
| 8564 | } else { |
| 8565 | noteForegroundServicePausedLocked(elapsedRealtimeMs); |
| 8566 | } |
| 8567 | mInForegroundService = userAwareService; |
| 8568 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8569 | } |
| 8570 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8571 | /** Whether to consider Uid to be in the background for background timebase purposes. */ |
| 8572 | public boolean isInBackground() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8573 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 8574 | // also considered to be 'background' for our purposes, because it's not foreground. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8575 | return mProcessState >= PROCESS_STATE_BACKGROUND; |
| 8576 | } |
| 8577 | |
| 8578 | public boolean updateOnBatteryBgTimeBase(long uptimeUs, long realtimeUs) { |
| 8579 | boolean on = mBsi.mOnBatteryTimeBase.isRunning() && isInBackground(); |
| 8580 | return mOnBatteryBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
| 8581 | } |
| 8582 | |
| 8583 | public boolean updateOnBatteryScreenOffBgTimeBase(long uptimeUs, long realtimeUs) { |
| 8584 | boolean on = mBsi.mOnBatteryScreenOffTimeBase.isRunning() && isInBackground(); |
| 8585 | return mOnBatteryScreenOffBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8586 | } |
| 8587 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8588 | public SparseArray<? extends Pid> getPidStats() { |
| 8589 | return mPids; |
| 8590 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8591 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8592 | public Pid getPidStatsLocked(int pid) { |
| 8593 | Pid p = mPids.get(pid); |
| 8594 | if (p == null) { |
| 8595 | p = new Pid(); |
| 8596 | mPids.put(pid, p); |
| 8597 | } |
| 8598 | return p; |
| 8599 | } |
| 8600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8601 | /** |
| 8602 | * Retrieve the statistics object for a particular service, creating |
| 8603 | * if needed. |
| 8604 | */ |
| 8605 | public Pkg getPackageStatsLocked(String name) { |
| 8606 | Pkg ps = mPackageStats.get(name); |
| 8607 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8608 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8609 | mPackageStats.put(name, ps); |
| 8610 | } |
| 8611 | |
| 8612 | return ps; |
| 8613 | } |
| 8614 | |
| 8615 | /** |
| 8616 | * Retrieve the statistics object for a particular service, creating |
| 8617 | * if needed. |
| 8618 | */ |
| 8619 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 8620 | Pkg ps = getPackageStatsLocked(pkg); |
| 8621 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 8622 | if (ss == null) { |
| 8623 | ss = ps.newServiceStatsLocked(); |
| 8624 | ps.mServiceStats.put(serv, ss); |
| 8625 | } |
| 8626 | |
| 8627 | return ss; |
| 8628 | } |
| 8629 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8630 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8631 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8632 | timer.readSummaryFromParcelLocked(in); |
| 8633 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8634 | } |
| 8635 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8636 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8637 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8638 | timer.readSummaryFromParcelLocked(in); |
| 8639 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8640 | } |
| 8641 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8642 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8643 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8644 | mWakelockStats.add(wlName, wl); |
| 8645 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8646 | getWakelockTimerLocked(wl, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8647 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8648 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8649 | getWakelockTimerLocked(wl, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8650 | } |
| 8651 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8652 | getWakelockTimerLocked(wl, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8654 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8655 | getWakelockTimerLocked(wl, WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8657 | } |
| 8658 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8659 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8660 | Sensor se = mSensorStats.get(sensor); |
| 8661 | if (se == null) { |
| 8662 | if (!create) { |
| 8663 | return null; |
| 8664 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8665 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | mSensorStats.put(sensor, se); |
| 8667 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8668 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8669 | if (t != null) { |
| 8670 | return t; |
| 8671 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8672 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8673 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8674 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8675 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8676 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8677 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 8678 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | se.mTimer = t; |
| 8680 | return t; |
| 8681 | } |
| 8682 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8683 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8684 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8685 | if (t != null) { |
| 8686 | t.startRunningLocked(elapsedRealtimeMs); |
| 8687 | } |
| 8688 | } |
| 8689 | |
| 8690 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8691 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8692 | if (t != null) { |
| 8693 | t.stopRunningLocked(elapsedRealtimeMs); |
| 8694 | } |
| 8695 | } |
| 8696 | |
| 8697 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8698 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8699 | if (t != null) { |
| 8700 | t.startRunningLocked(elapsedRealtimeMs); |
| 8701 | } |
| 8702 | } |
| 8703 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8704 | public void noteStopJobLocked(String name, long elapsedRealtimeMs, int stopReason) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8705 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8706 | if (t != null) { |
| 8707 | t.stopRunningLocked(elapsedRealtimeMs); |
| 8708 | } |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8709 | if (mBsi.mOnBatteryTimeBase.isRunning()) { |
| 8710 | SparseIntArray types = mJobCompletions.get(name); |
| 8711 | if (types == null) { |
| 8712 | types = new SparseIntArray(); |
| 8713 | mJobCompletions.put(name, types); |
| 8714 | } |
| 8715 | int last = types.get(stopReason, 0); |
| 8716 | types.put(stopReason, last + 1); |
| 8717 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8718 | } |
| 8719 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8720 | public StopwatchTimer getWakelockTimerLocked(Wakelock wl, int type) { |
| 8721 | if (wl == null) { |
| 8722 | return null; |
| 8723 | } |
| 8724 | switch (type) { |
| 8725 | case WAKE_TYPE_PARTIAL: { |
| 8726 | DualTimer t = wl.mTimerPartial; |
| 8727 | if (t == null) { |
| 8728 | t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, |
| 8729 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, |
| 8730 | mOnBatteryScreenOffBackgroundTimeBase); |
| 8731 | wl.mTimerPartial = t; |
| 8732 | } |
| 8733 | return t; |
| 8734 | } |
| 8735 | case WAKE_TYPE_FULL: { |
| 8736 | StopwatchTimer t = wl.mTimerFull; |
| 8737 | if (t == null) { |
| 8738 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, |
| 8739 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
| 8740 | wl.mTimerFull = t; |
| 8741 | } |
| 8742 | return t; |
| 8743 | } |
| 8744 | case WAKE_TYPE_WINDOW: { |
| 8745 | StopwatchTimer t = wl.mTimerWindow; |
| 8746 | if (t == null) { |
| 8747 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, |
| 8748 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
| 8749 | wl.mTimerWindow = t; |
| 8750 | } |
| 8751 | return t; |
| 8752 | } |
| 8753 | case WAKE_TYPE_DRAW: { |
| 8754 | StopwatchTimer t = wl.mTimerDraw; |
| 8755 | if (t == null) { |
| 8756 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, |
| 8757 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
| 8758 | wl.mTimerDraw = t; |
| 8759 | } |
| 8760 | return t; |
| 8761 | } |
| 8762 | default: |
| 8763 | throw new IllegalArgumentException("type=" + type); |
| 8764 | } |
| 8765 | } |
| 8766 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8767 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8768 | Wakelock wl = mWakelockStats.startObject(name); |
| 8769 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8770 | getWakelockTimerLocked(wl, type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8771 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8772 | if (type == WAKE_TYPE_PARTIAL) { |
| 8773 | createAggregatedPartialWakelockTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 8774 | if (pid >= 0) { |
| 8775 | Pid p = getPidStatsLocked(pid); |
| 8776 | if (p.mWakeNesting++ == 0) { |
| 8777 | p.mWakeStartMs = elapsedRealtimeMs; |
| 8778 | } |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 8779 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8780 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8781 | } |
| 8782 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8783 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8784 | Wakelock wl = mWakelockStats.stopObject(name); |
| 8785 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8786 | getWakelockTimerLocked(wl, type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8787 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8788 | if (type == WAKE_TYPE_PARTIAL) { |
| 8789 | if (mAggregatedPartialWakelockTimer != null) { |
| 8790 | mAggregatedPartialWakelockTimer.stopRunningLocked(elapsedRealtimeMs); |
| 8791 | } |
| 8792 | if (pid >= 0) { |
| 8793 | Pid p = mPids.get(pid); |
| 8794 | if (p != null && p.mWakeNesting > 0) { |
| 8795 | if (p.mWakeNesting-- == 1) { |
| 8796 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 8797 | p.mWakeStartMs = 0; |
| 8798 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8799 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8800 | } |
| 8801 | } |
| 8802 | } |
| 8803 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8804 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 8805 | Proc p = getProcessStatsLocked(proc); |
| 8806 | if (p != null) { |
| 8807 | p.addExcessiveCpu(overTime, usedTime); |
| 8808 | } |
| 8809 | } |
| 8810 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8811 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8812 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 8813 | t.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8814 | } |
| 8815 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8816 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8817 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8818 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8819 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8820 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8821 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8822 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8823 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8824 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8825 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8826 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8827 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8828 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8829 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8830 | } |
| 8831 | |
| 8832 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8833 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8834 | } |
| 8835 | } |
| 8836 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8837 | public long[] getCpuFreqs() { |
| 8838 | return mCpuFreqs; |
| 8839 | } |
| 8840 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 8841 | public BatteryStatsImpl(File systemDir, Handler handler, PlatformIdleStateCallback cb, |
| 8842 | UserInfoProvider userInfoProvider) { |
| 8843 | this(new SystemClocks(), systemDir, handler, cb, userInfoProvider); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8844 | } |
| 8845 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 8846 | private BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 8847 | PlatformIdleStateCallback cb, |
| 8848 | UserInfoProvider userInfoProvider) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8849 | init(clocks); |
| 8850 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8851 | if (systemDir != null) { |
| 8852 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 8853 | new File(systemDir, "batterystats.bin.tmp")); |
| 8854 | } else { |
| 8855 | mFile = null; |
| 8856 | } |
| 8857 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8858 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 8859 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8860 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8861 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 8862 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8863 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8864 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8865 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8866 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8867 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 8868 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 8869 | mOnBatteryTimeBase); |
| 8870 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 8871 | mOnBatteryTimeBase); |
| 8872 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 8873 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 8874 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 8875 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 8876 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 8877 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 8878 | mOnBatteryTimeBase); |
| 8879 | } |
| 8880 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 8881 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8882 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8883 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8884 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8885 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8886 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8887 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8888 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8889 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8890 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 8891 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8892 | NUM_BT_TX_LEVELS); |
| 8893 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8894 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8895 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 8896 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 8897 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8898 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8899 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8900 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8901 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 8902 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8903 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8904 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8905 | mOnBatteryTimeBase); |
| 8906 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8907 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8908 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 8909 | mOnBatteryTimeBase); |
| 8910 | } |
| 8911 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8912 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 8913 | mOnBatteryTimeBase); |
| 8914 | } |
| 8915 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 8916 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 8917 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 8918 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 8919 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8920 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 8921 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8922 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8923 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8924 | long uptime = mClocks.uptimeMillis() * 1000; |
| 8925 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8926 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8927 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8928 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8929 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8930 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8931 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8932 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8933 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8934 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8935 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8936 | mPlatformIdleStateCallback = cb; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 8937 | mUserInfoProvider = userInfoProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8938 | } |
| 8939 | |
| 8940 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8941 | this(new SystemClocks(), p); |
| 8942 | } |
| 8943 | |
| 8944 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 8945 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8946 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8947 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8948 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8949 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8950 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8951 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8953 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | } |
| 8955 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8956 | public void setPowerProfileLocked(PowerProfile profile) { |
| 8957 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8958 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8959 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 8960 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 8961 | // information. |
| 8962 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8963 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 8964 | int firstCpuOfCluster = 0; |
| 8965 | for (int i = 0; i < numClusters; i++) { |
| 8966 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 8967 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 8968 | numSpeedSteps); |
| 8969 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 8970 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 8971 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8972 | if (mEstimatedBatteryCapacity == -1) { |
| 8973 | // Initialize the estimated battery capacity to a known preset one. |
| 8974 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8975 | } |
| 8976 | } |
| 8977 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8978 | public void setCallback(BatteryCallback cb) { |
| 8979 | mCallback = cb; |
| 8980 | } |
| 8981 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8982 | public void setRadioScanningTimeoutLocked(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8983 | if (mPhoneSignalScanningTimer != null) { |
| 8984 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 8985 | } |
| 8986 | } |
| 8987 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8988 | public void setExternalStatsSyncLocked(ExternalStatsSync sync) { |
| 8989 | mExternalSync = sync; |
| 8990 | } |
| 8991 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8992 | public void updateDailyDeadlineLocked() { |
| 8993 | // Get the current time. |
| 8994 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 8995 | Calendar calDeadline = Calendar.getInstance(); |
| 8996 | calDeadline.setTimeInMillis(currentTime); |
| 8997 | |
| 8998 | // Move time up to the next day, ranging from 1am to 3pm. |
| 8999 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 9000 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 9001 | calDeadline.set(Calendar.SECOND, 0); |
| 9002 | calDeadline.set(Calendar.MINUTE, 0); |
| 9003 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 9004 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 9005 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 9006 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 9007 | } |
| 9008 | |
| 9009 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 9010 | long currentTime = System.currentTimeMillis(); |
| 9011 | if (currentTime >= mNextMaxDailyDeadline) { |
| 9012 | recordDailyStatsLocked(); |
| 9013 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 9014 | recordDailyStatsLocked(); |
| 9015 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 9016 | recordDailyStatsLocked(); |
| 9017 | } |
| 9018 | } |
| 9019 | |
| 9020 | public void recordDailyStatsLocked() { |
| 9021 | DailyItem item = new DailyItem(); |
| 9022 | item.mStartTime = mDailyStartTime; |
| 9023 | item.mEndTime = System.currentTimeMillis(); |
| 9024 | boolean hasData = false; |
| 9025 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 9026 | hasData = true; |
| 9027 | item.mDischargeSteps = new LevelStepTracker( |
| 9028 | mDailyDischargeStepTracker.mNumStepDurations, |
| 9029 | mDailyDischargeStepTracker.mStepDurations); |
| 9030 | } |
| 9031 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 9032 | hasData = true; |
| 9033 | item.mChargeSteps = new LevelStepTracker( |
| 9034 | mDailyChargeStepTracker.mNumStepDurations, |
| 9035 | mDailyChargeStepTracker.mStepDurations); |
| 9036 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9037 | if (mDailyPackageChanges != null) { |
| 9038 | hasData = true; |
| 9039 | item.mPackageChanges = mDailyPackageChanges; |
| 9040 | mDailyPackageChanges = null; |
| 9041 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9042 | mDailyDischargeStepTracker.init(); |
| 9043 | mDailyChargeStepTracker.init(); |
| 9044 | updateDailyDeadlineLocked(); |
| 9045 | |
| 9046 | if (hasData) { |
| 9047 | mDailyItems.add(item); |
| 9048 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 9049 | mDailyItems.remove(0); |
| 9050 | } |
| 9051 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 9052 | try { |
| 9053 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 9054 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9055 | writeDailyItemsLocked(out); |
| 9056 | BackgroundThread.getHandler().post(new Runnable() { |
| 9057 | @Override |
| 9058 | public void run() { |
| 9059 | synchronized (mCheckinFile) { |
| 9060 | FileOutputStream stream = null; |
| 9061 | try { |
| 9062 | stream = mDailyFile.startWrite(); |
| 9063 | memStream.writeTo(stream); |
| 9064 | stream.flush(); |
| 9065 | FileUtils.sync(stream); |
| 9066 | stream.close(); |
| 9067 | mDailyFile.finishWrite(stream); |
| 9068 | } catch (IOException e) { |
| 9069 | Slog.w("BatteryStats", |
| 9070 | "Error writing battery daily items", e); |
| 9071 | mDailyFile.failWrite(stream); |
| 9072 | } |
| 9073 | } |
| 9074 | } |
| 9075 | }); |
| 9076 | } catch (IOException e) { |
| 9077 | } |
| 9078 | } |
| 9079 | } |
| 9080 | |
| 9081 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 9082 | StringBuilder sb = new StringBuilder(64); |
| 9083 | out.startDocument(null, true); |
| 9084 | out.startTag(null, "daily-items"); |
| 9085 | for (int i=0; i<mDailyItems.size(); i++) { |
| 9086 | final DailyItem dit = mDailyItems.get(i); |
| 9087 | out.startTag(null, "item"); |
| 9088 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 9089 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 9090 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 9091 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9092 | if (dit.mPackageChanges != null) { |
| 9093 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 9094 | PackageChange pc = dit.mPackageChanges.get(j); |
| 9095 | if (pc.mUpdate) { |
| 9096 | out.startTag(null, "upd"); |
| 9097 | out.attribute(null, "pkg", pc.mPackageName); |
| 9098 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 9099 | out.endTag(null, "upd"); |
| 9100 | } else { |
| 9101 | out.startTag(null, "rem"); |
| 9102 | out.attribute(null, "pkg", pc.mPackageName); |
| 9103 | out.endTag(null, "rem"); |
| 9104 | } |
| 9105 | } |
| 9106 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9107 | out.endTag(null, "item"); |
| 9108 | } |
| 9109 | out.endTag(null, "daily-items"); |
| 9110 | out.endDocument(); |
| 9111 | } |
| 9112 | |
| 9113 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 9114 | StringBuilder tmpBuilder) throws IOException { |
| 9115 | if (steps != null) { |
| 9116 | out.startTag(null, tag); |
| 9117 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 9118 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 9119 | out.startTag(null, "s"); |
| 9120 | tmpBuilder.setLength(0); |
| 9121 | steps.encodeEntryAt(i, tmpBuilder); |
| 9122 | out.attribute(null, "v", tmpBuilder.toString()); |
| 9123 | out.endTag(null, "s"); |
| 9124 | } |
| 9125 | out.endTag(null, tag); |
| 9126 | } |
| 9127 | } |
| 9128 | |
| 9129 | public void readDailyStatsLocked() { |
| 9130 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 9131 | mDailyItems.clear(); |
| 9132 | FileInputStream stream; |
| 9133 | try { |
| 9134 | stream = mDailyFile.openRead(); |
| 9135 | } catch (FileNotFoundException e) { |
| 9136 | return; |
| 9137 | } |
| 9138 | try { |
| 9139 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 9140 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9141 | readDailyItemsLocked(parser); |
| 9142 | } catch (XmlPullParserException e) { |
| 9143 | } finally { |
| 9144 | try { |
| 9145 | stream.close(); |
| 9146 | } catch (IOException e) { |
| 9147 | } |
| 9148 | } |
| 9149 | } |
| 9150 | |
| 9151 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 9152 | try { |
| 9153 | int type; |
| 9154 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 9155 | && type != XmlPullParser.END_DOCUMENT) { |
| 9156 | ; |
| 9157 | } |
| 9158 | |
| 9159 | if (type != XmlPullParser.START_TAG) { |
| 9160 | throw new IllegalStateException("no start tag found"); |
| 9161 | } |
| 9162 | |
| 9163 | int outerDepth = parser.getDepth(); |
| 9164 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 9165 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 9166 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 9167 | continue; |
| 9168 | } |
| 9169 | |
| 9170 | String tagName = parser.getName(); |
| 9171 | if (tagName.equals("item")) { |
| 9172 | readDailyItemTagLocked(parser); |
| 9173 | } else { |
| 9174 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 9175 | + parser.getName()); |
| 9176 | XmlUtils.skipCurrentTag(parser); |
| 9177 | } |
| 9178 | } |
| 9179 | |
| 9180 | } catch (IllegalStateException e) { |
| 9181 | Slog.w(TAG, "Failed parsing daily " + e); |
| 9182 | } catch (NullPointerException e) { |
| 9183 | Slog.w(TAG, "Failed parsing daily " + e); |
| 9184 | } catch (NumberFormatException e) { |
| 9185 | Slog.w(TAG, "Failed parsing daily " + e); |
| 9186 | } catch (XmlPullParserException e) { |
| 9187 | Slog.w(TAG, "Failed parsing daily " + e); |
| 9188 | } catch (IOException e) { |
| 9189 | Slog.w(TAG, "Failed parsing daily " + e); |
| 9190 | } catch (IndexOutOfBoundsException e) { |
| 9191 | Slog.w(TAG, "Failed parsing daily " + e); |
| 9192 | } |
| 9193 | } |
| 9194 | |
| 9195 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 9196 | XmlPullParserException, IOException { |
| 9197 | DailyItem dit = new DailyItem(); |
| 9198 | String attr = parser.getAttributeValue(null, "start"); |
| 9199 | if (attr != null) { |
| 9200 | dit.mStartTime = Long.parseLong(attr); |
| 9201 | } |
| 9202 | attr = parser.getAttributeValue(null, "end"); |
| 9203 | if (attr != null) { |
| 9204 | dit.mEndTime = Long.parseLong(attr); |
| 9205 | } |
| 9206 | int outerDepth = parser.getDepth(); |
| 9207 | int type; |
| 9208 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 9209 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 9210 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 9211 | continue; |
| 9212 | } |
| 9213 | |
| 9214 | String tagName = parser.getName(); |
| 9215 | if (tagName.equals("dis")) { |
| 9216 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 9217 | } else if (tagName.equals("chg")) { |
| 9218 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9219 | } else if (tagName.equals("upd")) { |
| 9220 | if (dit.mPackageChanges == null) { |
| 9221 | dit.mPackageChanges = new ArrayList<>(); |
| 9222 | } |
| 9223 | PackageChange pc = new PackageChange(); |
| 9224 | pc.mUpdate = true; |
| 9225 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 9226 | String verStr = parser.getAttributeValue(null, "ver"); |
| 9227 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 9228 | dit.mPackageChanges.add(pc); |
| 9229 | XmlUtils.skipCurrentTag(parser); |
| 9230 | } else if (tagName.equals("rem")) { |
| 9231 | if (dit.mPackageChanges == null) { |
| 9232 | dit.mPackageChanges = new ArrayList<>(); |
| 9233 | } |
| 9234 | PackageChange pc = new PackageChange(); |
| 9235 | pc.mUpdate = false; |
| 9236 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 9237 | dit.mPackageChanges.add(pc); |
| 9238 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9239 | } else { |
| 9240 | Slog.w(TAG, "Unknown element under <item>: " |
| 9241 | + parser.getName()); |
| 9242 | XmlUtils.skipCurrentTag(parser); |
| 9243 | } |
| 9244 | } |
| 9245 | mDailyItems.add(dit); |
| 9246 | } |
| 9247 | |
| 9248 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 9249 | String tag) |
| 9250 | throws NumberFormatException, XmlPullParserException, IOException { |
| 9251 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 9252 | if (numAttr == null) { |
| 9253 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 9254 | XmlUtils.skipCurrentTag(parser); |
| 9255 | return; |
| 9256 | } |
| 9257 | final int num = Integer.parseInt(numAttr); |
| 9258 | LevelStepTracker steps = new LevelStepTracker(num); |
| 9259 | if (isCharge) { |
| 9260 | dit.mChargeSteps = steps; |
| 9261 | } else { |
| 9262 | dit.mDischargeSteps = steps; |
| 9263 | } |
| 9264 | int i = 0; |
| 9265 | int outerDepth = parser.getDepth(); |
| 9266 | int type; |
| 9267 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 9268 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 9269 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 9270 | continue; |
| 9271 | } |
| 9272 | |
| 9273 | String tagName = parser.getName(); |
| 9274 | if ("s".equals(tagName)) { |
| 9275 | if (i < num) { |
| 9276 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 9277 | if (valueAttr != null) { |
| 9278 | steps.decodeEntryAt(i, valueAttr); |
| 9279 | i++; |
| 9280 | } |
| 9281 | } |
| 9282 | } else { |
| 9283 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 9284 | + parser.getName()); |
| 9285 | XmlUtils.skipCurrentTag(parser); |
| 9286 | } |
| 9287 | } |
| 9288 | steps.mNumStepDurations = i; |
| 9289 | } |
| 9290 | |
| 9291 | @Override |
| 9292 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 9293 | int index = mDailyItems.size()-1-daysAgo; |
| 9294 | return index >= 0 ? mDailyItems.get(index) : null; |
| 9295 | } |
| 9296 | |
| 9297 | @Override |
| 9298 | public long getCurrentDailyStartTime() { |
| 9299 | return mDailyStartTime; |
| 9300 | } |
| 9301 | |
| 9302 | @Override |
| 9303 | public long getNextMinDailyDeadline() { |
| 9304 | return mNextMinDailyDeadline; |
| 9305 | } |
| 9306 | |
| 9307 | @Override |
| 9308 | public long getNextMaxDailyDeadline() { |
| 9309 | return mNextMaxDailyDeadline; |
| 9310 | } |
| 9311 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9312 | @Override |
| 9313 | public boolean startIteratingOldHistoryLocked() { |
| 9314 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 9315 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9316 | if ((mHistoryIterator = mHistory) == null) { |
| 9317 | return false; |
| 9318 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9319 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9320 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9321 | mReadOverflow = false; |
| 9322 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9323 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9324 | } |
| 9325 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9326 | @Override |
| 9327 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 9328 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 9329 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9330 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9331 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9332 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9333 | HistoryItem cur = mHistoryIterator; |
| 9334 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9335 | if (!mReadOverflow && !end) { |
| 9336 | Slog.w(TAG, "Old history ends before new history!"); |
| 9337 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9338 | return false; |
| 9339 | } |
| 9340 | out.setTo(cur); |
| 9341 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9342 | if (!mReadOverflow) { |
| 9343 | if (end) { |
| 9344 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9345 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 9346 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9347 | pw.println("Histories differ!"); |
| 9348 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9349 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9350 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9351 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 9352 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 9353 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9354 | } |
| 9355 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9356 | return true; |
| 9357 | } |
| 9358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9360 | public void finishIteratingOldHistoryLocked() { |
| 9361 | mIteratingHistory = false; |
| 9362 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9363 | mHistoryIterator = null; |
| 9364 | } |
| 9365 | |
| 9366 | public int getHistoryTotalSize() { |
| 9367 | return MAX_HISTORY_BUFFER; |
| 9368 | } |
| 9369 | |
| 9370 | public int getHistoryUsedSize() { |
| 9371 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9372 | } |
| 9373 | |
| 9374 | @Override |
| 9375 | public boolean startIteratingHistoryLocked() { |
| 9376 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 9377 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9378 | if (mHistoryBuffer.dataSize() <= 0) { |
| 9379 | return false; |
| 9380 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9381 | mHistoryBuffer.setDataPosition(0); |
| 9382 | mReadOverflow = false; |
| 9383 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9384 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 9385 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 9386 | mReadHistoryChars = 0; |
| 9387 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 9388 | final HistoryTag tag = ent.getKey(); |
| 9389 | final int idx = ent.getValue(); |
| 9390 | mReadHistoryStrings[idx] = tag.string; |
| 9391 | mReadHistoryUids[idx] = tag.uid; |
| 9392 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9393 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9394 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9395 | } |
| 9396 | |
| 9397 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9398 | public int getHistoryStringPoolSize() { |
| 9399 | return mReadHistoryStrings.length; |
| 9400 | } |
| 9401 | |
| 9402 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9403 | public int getHistoryStringPoolBytes() { |
| 9404 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 9405 | // Each string character is 2 bytes. |
| 9406 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 9407 | } |
| 9408 | |
| 9409 | @Override |
| 9410 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9411 | return mReadHistoryStrings[index]; |
| 9412 | } |
| 9413 | |
| 9414 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9415 | public int getHistoryTagPoolUid(int index) { |
| 9416 | return mReadHistoryUids[index]; |
| 9417 | } |
| 9418 | |
| 9419 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9420 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9421 | final int pos = mHistoryBuffer.dataPosition(); |
| 9422 | if (pos == 0) { |
| 9423 | out.clear(); |
| 9424 | } |
| 9425 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9426 | if (end) { |
| 9427 | return false; |
| 9428 | } |
| 9429 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9430 | final long lastRealtime = out.time; |
| 9431 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9432 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9433 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 9434 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9435 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 9436 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9437 | return true; |
| 9438 | } |
| 9439 | |
| 9440 | @Override |
| 9441 | public void finishIteratingHistoryLocked() { |
| 9442 | mIteratingHistory = false; |
| 9443 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9444 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9445 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9446 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9447 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9448 | public long getHistoryBaseTime() { |
| 9449 | return mHistoryBaseTime; |
| 9450 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9451 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9452 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | public int getStartCount() { |
| 9454 | return mStartCount; |
| 9455 | } |
| 9456 | |
| 9457 | public boolean isOnBattery() { |
| 9458 | return mOnBattery; |
| 9459 | } |
| 9460 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9461 | public boolean isCharging() { |
| 9462 | return mCharging; |
| 9463 | } |
| 9464 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9465 | public boolean isScreenOn(int state) { |
| 9466 | return state == Display.STATE_ON; |
| 9467 | } |
| 9468 | |
| 9469 | public boolean isScreenOff(int state) { |
| 9470 | return state == Display.STATE_OFF; |
| 9471 | } |
| 9472 | |
| 9473 | public boolean isScreenDoze(int state) { |
| 9474 | return state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9475 | } |
| 9476 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9477 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9478 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9479 | mOnBatteryTimeBase.init(uptime, realtime); |
| 9480 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9481 | mRealtime = 0; |
| 9482 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9483 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9484 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9485 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9486 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9487 | void initDischarge() { |
| 9488 | mLowDischargeAmountSinceCharge = 0; |
| 9489 | mHighDischargeAmountSinceCharge = 0; |
| 9490 | mDischargeAmountScreenOn = 0; |
| 9491 | mDischargeAmountScreenOnSinceCharge = 0; |
| 9492 | mDischargeAmountScreenOff = 0; |
| 9493 | mDischargeAmountScreenOffSinceCharge = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9494 | mDischargeAmountScreenDoze = 0; |
| 9495 | mDischargeAmountScreenDozeSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9496 | mDischargeStepTracker.init(); |
| 9497 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9498 | mDischargeScreenOffCounter.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9499 | mDischargeScreenDozeCounter.reset(false); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9500 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9501 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9502 | |
| 9503 | public void resetAllStatsCmdLocked() { |
| 9504 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9505 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9506 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9507 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9508 | long realtime = mSecRealtime * 1000; |
| 9509 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 9510 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9511 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9512 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 9513 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9514 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 9515 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 9516 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9517 | if (isScreenOn(mScreenState)) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9518 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9519 | mDischargeScreenDozeUnplugLevel = 0; |
| 9520 | mDischargeScreenOffUnplugLevel = 0; |
| 9521 | } else if (isScreenDoze(mScreenState)) { |
| 9522 | mDischargeScreenOnUnplugLevel = 0; |
| 9523 | mDischargeScreenDozeUnplugLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9524 | mDischargeScreenOffUnplugLevel = 0; |
| 9525 | } else { |
| 9526 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9527 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9528 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 9529 | } |
| 9530 | mDischargeAmountScreenOn = 0; |
| 9531 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9532 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9533 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9534 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9535 | } |
| 9536 | |
| 9537 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 9538 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 9539 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9540 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 9541 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9542 | mScreenOnTimer.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9543 | mScreenDozeTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9544 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9545 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9546 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 9547 | |
| 9548 | if (mPowerProfile != null) { |
| 9549 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 9550 | } else { |
| 9551 | mEstimatedBatteryCapacity = -1; |
| 9552 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 9553 | mMinLearnedBatteryCapacity = -1; |
| 9554 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9555 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9556 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 9557 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 9558 | mLongestLightIdleTime = 0; |
| 9559 | mLongestFullIdleTime = 0; |
| 9560 | mDeviceIdleModeLightTimer.reset(false); |
| 9561 | mDeviceIdleModeFullTimer.reset(false); |
| 9562 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9563 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9564 | mPhoneOnTimer.reset(false); |
| 9565 | mAudioOnTimer.reset(false); |
| 9566 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9567 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9568 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9569 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9570 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9571 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9572 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9573 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9574 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9575 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9576 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9577 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9578 | mNetworkByteActivityCounters[i].reset(false); |
| 9579 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9580 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9581 | mMobileRadioActiveTimer.reset(false); |
| 9582 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9583 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9584 | mMobileRadioActiveUnknownTime.reset(false); |
| 9585 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9586 | mWifiOnTimer.reset(false); |
| 9587 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9588 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9589 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9590 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9591 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9592 | mWifiSupplStateTimer[i].reset(false); |
| 9593 | } |
| 9594 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9595 | mWifiSignalStrengthsTimer[i].reset(false); |
| 9596 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9597 | mWifiActivity.reset(false); |
| 9598 | mBluetoothActivity.reset(false); |
| 9599 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9600 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9601 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9602 | for (int i=0; i<mUidStats.size(); i++) { |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 9603 | if (mUidStats.valueAt(i).reset(uptimeMillis * 1000, elapsedRealtimeMillis * 1000)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9604 | mUidStats.remove(mUidStats.keyAt(i)); |
| 9605 | i--; |
| 9606 | } |
| 9607 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9608 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 9609 | if (mRpmStats.size() > 0) { |
| 9610 | for (SamplingTimer timer : mRpmStats.values()) { |
| 9611 | mOnBatteryTimeBase.remove(timer); |
| 9612 | } |
| 9613 | mRpmStats.clear(); |
| 9614 | } |
| 9615 | if (mScreenOffRpmStats.size() > 0) { |
| 9616 | for (SamplingTimer timer : mScreenOffRpmStats.values()) { |
| 9617 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 9618 | } |
| 9619 | mScreenOffRpmStats.clear(); |
| 9620 | } |
| 9621 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9622 | if (mKernelWakelockStats.size() > 0) { |
| 9623 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9624 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9625 | } |
| 9626 | mKernelWakelockStats.clear(); |
| 9627 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9628 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 9629 | if (mKernelMemoryStats.size() > 0) { |
| 9630 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 9631 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 9632 | } |
| 9633 | mKernelMemoryStats.clear(); |
| 9634 | } |
| 9635 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9636 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9637 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 9638 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9639 | } |
| 9640 | mWakeupReasonStats.clear(); |
| 9641 | } |
| 9642 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9643 | mLastHistoryStepDetails = null; |
| 9644 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 9645 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 9646 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 9647 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 9648 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 9649 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 9650 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 9651 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 9652 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 9653 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 9654 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9655 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9656 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9657 | clearHistoryLocked(); |
| 9658 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9659 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9660 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9661 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9662 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 9663 | // Not recording process starts/stops. |
| 9664 | continue; |
| 9665 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9666 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9667 | if (active == null) { |
| 9668 | continue; |
| 9669 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9670 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 9671 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9672 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9673 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 9674 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9675 | } |
| 9676 | } |
| 9677 | } |
| 9678 | } |
| 9679 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9680 | void updateDischargeScreenLevelsLocked(int oldState, int newState) { |
| 9681 | updateOldDischargeScreenLevelLocked(oldState); |
| 9682 | updateNewDischargeScreenLevelLocked(newState); |
| 9683 | } |
| 9684 | |
| 9685 | private void updateOldDischargeScreenLevelLocked(int state) { |
| 9686 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9687 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 9688 | if (diff > 0) { |
| 9689 | mDischargeAmountScreenOn += diff; |
| 9690 | mDischargeAmountScreenOnSinceCharge += diff; |
| 9691 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9692 | } else if (isScreenDoze(state)) { |
| 9693 | int diff = mDischargeScreenDozeUnplugLevel - mDischargeCurrentLevel; |
| 9694 | if (diff > 0) { |
| 9695 | mDischargeAmountScreenDoze += diff; |
| 9696 | mDischargeAmountScreenDozeSinceCharge += diff; |
| 9697 | } |
| 9698 | } else if (isScreenOff(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9699 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 9700 | if (diff > 0) { |
| 9701 | mDischargeAmountScreenOff += diff; |
| 9702 | mDischargeAmountScreenOffSinceCharge += diff; |
| 9703 | } |
| 9704 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9705 | } |
| 9706 | |
| 9707 | private void updateNewDischargeScreenLevelLocked(int state) { |
| 9708 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9709 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 9710 | mDischargeScreenOffUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9711 | mDischargeScreenDozeUnplugLevel = 0; |
| 9712 | } else if (isScreenDoze(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9713 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9714 | mDischargeScreenDozeUnplugLevel = mDischargeCurrentLevel; |
| 9715 | mDischargeScreenOffUnplugLevel = 0; |
| 9716 | } else if (isScreenOff(state)) { |
| 9717 | mDischargeScreenOnUnplugLevel = 0; |
| 9718 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9719 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 9720 | } |
| 9721 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9722 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9723 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9724 | if (mOnBatteryInternal) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 9725 | updateDischargeScreenLevelsLocked(mScreenState, mScreenState); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9726 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9727 | } |
| 9728 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9729 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 9730 | private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6); |
| 9731 | |
| 9732 | private final Object mWifiNetworkLock = new Object(); |
| 9733 | |
| 9734 | @GuardedBy("mWifiNetworkLock") |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9735 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 9736 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9737 | @GuardedBy("mWifiNetworkLock") |
| 9738 | private NetworkStats mLastWifiNetworkStats = new NetworkStats(0, -1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9739 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9740 | private final Object mModemNetworkLock = new Object(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9741 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9742 | @GuardedBy("mModemNetworkLock") |
| 9743 | private String[] mModemIfaces = EmptyArray.STRING; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9744 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9745 | @GuardedBy("mModemNetworkLock") |
| 9746 | private NetworkStats mLastModemNetworkStats = new NetworkStats(0, -1); |
| 9747 | |
| 9748 | private NetworkStats readNetworkStatsLocked(String[] ifaces) { |
| 9749 | try { |
| 9750 | if (!ArrayUtils.isEmpty(ifaces)) { |
| 9751 | return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, |
| 9752 | NetworkStats.TAG_NONE, mNetworkStatsPool.acquire()); |
| 9753 | } |
| 9754 | } catch (IOException e) { |
| 9755 | Slog.e(TAG, "failed to read network stats for ifaces: " + Arrays.toString(ifaces)); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9756 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9757 | return null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9758 | } |
| 9759 | |
| 9760 | /** |
| 9761 | * Distribute WiFi energy info and network traffic to apps. |
| 9762 | * @param info The energy information from the WiFi controller. |
| 9763 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9764 | public void updateWifiState(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9765 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9766 | Slog.d(TAG, "Updating wifi stats: " + Arrays.toString(mWifiIfaces)); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9767 | } |
| 9768 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9769 | // Grab a separate lock to acquire the network stats, which may do I/O. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9770 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9771 | synchronized (mWifiNetworkLock) { |
| 9772 | final NetworkStats latestStats = readNetworkStatsLocked(mWifiIfaces); |
| 9773 | if (latestStats != null) { |
| 9774 | delta = NetworkStats.subtract(latestStats, mLastWifiNetworkStats, null, null, |
| 9775 | mNetworkStatsPool.acquire()); |
| 9776 | mNetworkStatsPool.release(mLastWifiNetworkStats); |
| 9777 | mLastWifiNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9778 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9779 | } |
| 9780 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9781 | synchronized (this) { |
| 9782 | if (!mOnBatteryInternal) { |
| 9783 | if (delta != null) { |
| 9784 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9785 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9786 | return; |
| 9787 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9788 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9789 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
| 9790 | SparseLongArray rxPackets = new SparseLongArray(); |
| 9791 | SparseLongArray txPackets = new SparseLongArray(); |
| 9792 | long totalTxPackets = 0; |
| 9793 | long totalRxPackets = 0; |
| 9794 | if (delta != null) { |
| 9795 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 9796 | final int size = delta.size(); |
| 9797 | for (int i = 0; i < size; i++) { |
| 9798 | entry = delta.getValues(i, entry); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9799 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9800 | if (DEBUG_ENERGY) { |
| 9801 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 9802 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 9803 | + " txPackets=" + entry.txPackets); |
| 9804 | } |
| 9805 | |
| 9806 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 9807 | // Skip the lookup below since there is no work to do. |
| 9808 | continue; |
| 9809 | } |
| 9810 | |
| 9811 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9812 | if (entry.rxBytes != 0) { |
| 9813 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9814 | entry.rxPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9815 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9816 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 9817 | entry.rxPackets); |
| 9818 | } |
| 9819 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 9820 | entry.rxBytes); |
| 9821 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 9822 | entry.rxPackets); |
| 9823 | |
| 9824 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 9825 | |
| 9826 | // Sum the total number of packets so that the Rx Power can |
| 9827 | // be evenly distributed amongst the apps. |
| 9828 | totalRxPackets += entry.rxPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9829 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9830 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9831 | if (entry.txBytes != 0) { |
| 9832 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9833 | entry.txPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9834 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9835 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 9836 | entry.txPackets); |
| 9837 | } |
| 9838 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 9839 | entry.txBytes); |
| 9840 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 9841 | entry.txPackets); |
| 9842 | |
| 9843 | txPackets.put(u.getUid(), entry.txPackets); |
| 9844 | |
| 9845 | // Sum the total number of packets so that the Tx Power can |
| 9846 | // be evenly distributed amongst the apps. |
| 9847 | totalTxPackets += entry.txPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9848 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9849 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9850 | mNetworkStatsPool.release(delta); |
| 9851 | delta = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9852 | } |
| 9853 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9854 | if (info != null) { |
| 9855 | mHasWifiReporting = true; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9856 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9857 | // Measured in mAms |
| 9858 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 9859 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 9860 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 9861 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9862 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9863 | long leftOverRxTimeMs = rxTimeMs; |
| 9864 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9865 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9866 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9867 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 9868 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 9869 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 9870 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 9871 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9872 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9873 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9874 | long totalWifiLockTimeMs = 0; |
| 9875 | long totalScanTimeMs = 0; |
| 9876 | |
| 9877 | // On the first pass, collect some totals so that we can normalize power |
| 9878 | // calculations if we need to. |
| 9879 | final int uidStatsSize = mUidStats.size(); |
| 9880 | for (int i = 0; i < uidStatsSize; i++) { |
| 9881 | final Uid uid = mUidStats.valueAt(i); |
| 9882 | |
| 9883 | // Sum the total scan power for all apps. |
| 9884 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 9885 | elapsedRealtimeMs * 1000) / 1000; |
| 9886 | |
| 9887 | // Sum the total time holding wifi lock for all apps. |
| 9888 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9889 | elapsedRealtimeMs * 1000) / 1000; |
| 9890 | } |
| 9891 | |
| 9892 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 9893 | Slog.d(TAG, |
| 9894 | " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 9895 | + rxTimeMs + " ms). Normalizing scan time."); |
| 9896 | } |
| 9897 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 9898 | Slog.d(TAG, |
| 9899 | " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 9900 | + txTimeMs + " ms). Normalizing scan time."); |
| 9901 | } |
| 9902 | |
| 9903 | // Actually assign and distribute power usage to apps. |
| 9904 | for (int i = 0; i < uidStatsSize; i++) { |
| 9905 | final Uid uid = mUidStats.valueAt(i); |
| 9906 | |
| 9907 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 9908 | elapsedRealtimeMs * 1000) / 1000; |
| 9909 | if (scanTimeSinceMarkMs > 0) { |
| 9910 | // Set the new mark so that next time we get new data since this point. |
| 9911 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 9912 | |
| 9913 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 9914 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 9915 | |
| 9916 | // Our total scan time is more than the reported Tx/Rx time. |
| 9917 | // This is possible because the cost of a scan is approximate. |
| 9918 | // Let's normalize the result so that we evenly blame each app |
| 9919 | // scanning. |
| 9920 | // |
| 9921 | // This means that we may have apps that transmitted/received packets not be |
| 9922 | // blamed for this, but this is fine as scans are relatively more expensive. |
| 9923 | if (totalScanTimeMs > rxTimeMs) { |
| 9924 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 9925 | totalScanTimeMs; |
| 9926 | } |
| 9927 | if (totalScanTimeMs > txTimeMs) { |
| 9928 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 9929 | totalScanTimeMs; |
| 9930 | } |
| 9931 | |
| 9932 | if (DEBUG_ENERGY) { |
| 9933 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 9934 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 9935 | + scanTxTimeSinceMarkMs + " ms)"); |
| 9936 | } |
| 9937 | |
| 9938 | ControllerActivityCounterImpl activityCounter = |
| 9939 | uid.getOrCreateWifiControllerActivityLocked(); |
| 9940 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 9941 | activityCounter.getTxTimeCounters()[0].addCountLocked( |
| 9942 | scanTxTimeSinceMarkMs); |
| 9943 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 9944 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
| 9945 | } |
| 9946 | |
| 9947 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 9948 | // lock. |
| 9949 | final long wifiLockTimeSinceMarkMs = |
| 9950 | uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9951 | elapsedRealtimeMs * 1000) / 1000; |
| 9952 | if (wifiLockTimeSinceMarkMs > 0) { |
| 9953 | // Set the new mark so that next time we get new data since this point. |
| 9954 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 9955 | |
| 9956 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 9957 | / totalWifiLockTimeMs; |
| 9958 | if (DEBUG_ENERGY) { |
| 9959 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 9960 | + myIdleTimeMs + " ms"); |
| 9961 | } |
| 9962 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 9963 | .addCountLocked(myIdleTimeMs); |
| 9964 | } |
| 9965 | } |
| 9966 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9967 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9968 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 9969 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9970 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9971 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9972 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 9973 | // packets. |
| 9974 | for (int i = 0; i < txPackets.size(); i++) { |
| 9975 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 9976 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) |
| 9977 | / totalTxPackets; |
| 9978 | if (DEBUG_ENERGY) { |
| 9979 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 9980 | } |
| 9981 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 9982 | .addCountLocked(myTxTimeMs); |
| 9983 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9984 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9985 | // Distribute the remaining Rx power appropriately between all apps that received |
| 9986 | // packets. |
| 9987 | for (int i = 0; i < rxPackets.size(); i++) { |
| 9988 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 9989 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) |
| 9990 | / totalRxPackets; |
| 9991 | if (DEBUG_ENERGY) { |
| 9992 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 9993 | } |
| 9994 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 9995 | .addCountLocked(myRxTimeMs); |
| 9996 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9997 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9998 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 9999 | |
| 10000 | |
| 10001 | // Update WiFi controller stats. |
| 10002 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 10003 | mWifiActivity.getTxTimeCounters()[0].addCountLocked( |
| 10004 | info.getControllerTxTimeMillis()); |
| 10005 | mWifiActivity.getIdleTimeCounter().addCountLocked( |
| 10006 | info.getControllerIdleTimeMillis()); |
| 10007 | |
| 10008 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 10009 | final double opVolt = mPowerProfile.getAveragePower( |
| 10010 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 10011 | if (opVolt != 0) { |
| 10012 | // We store the power drain as mAms. |
| 10013 | mWifiActivity.getPowerCounter().addCountLocked( |
| 10014 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 10015 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10016 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10017 | } |
| 10018 | } |
| 10019 | |
| 10020 | /** |
| 10021 | * Distribute Cell radio energy info and network traffic to apps. |
| 10022 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10023 | public void updateMobileRadioState(@Nullable final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10024 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10025 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10026 | } |
| 10027 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10028 | // Grab a separate lock to acquire the network stats, which may do I/O. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10029 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10030 | synchronized (mModemNetworkLock) { |
| 10031 | final NetworkStats latestStats = readNetworkStatsLocked(mModemIfaces); |
| 10032 | if (latestStats != null) { |
| 10033 | delta = NetworkStats.subtract(latestStats, mLastModemNetworkStats, null, null, |
| 10034 | mNetworkStatsPool.acquire()); |
| 10035 | mNetworkStatsPool.release(mLastModemNetworkStats); |
| 10036 | mLastModemNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10037 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10038 | } |
| 10039 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10040 | synchronized (this) { |
| 10041 | if (!mOnBatteryInternal) { |
| 10042 | if (delta != null) { |
| 10043 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10044 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10045 | return; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10046 | } |
| 10047 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10048 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10049 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 10050 | elapsedRealtimeMs * 1000); |
| 10051 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
| 10052 | |
| 10053 | long totalRxPackets = 0; |
| 10054 | long totalTxPackets = 0; |
| 10055 | if (delta != null) { |
| 10056 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 10057 | final int size = delta.size(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10058 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10059 | entry = delta.getValues(i, entry); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10060 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 10061 | continue; |
| 10062 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10063 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10064 | if (DEBUG_ENERGY) { |
| 10065 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 10066 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 10067 | + " txPackets=" + entry.txPackets); |
| 10068 | } |
| 10069 | |
| 10070 | totalRxPackets += entry.rxPackets; |
| 10071 | totalTxPackets += entry.txPackets; |
| 10072 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10073 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10074 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 10075 | entry.rxPackets); |
| 10076 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 10077 | entry.txPackets); |
| 10078 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 10079 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 10080 | entry.rxBytes, entry.rxPackets); |
| 10081 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 10082 | entry.txBytes, entry.txPackets); |
| 10083 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10084 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10085 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 10086 | entry.rxBytes); |
| 10087 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 10088 | entry.txBytes); |
| 10089 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 10090 | entry.rxPackets); |
| 10091 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 10092 | entry.txPackets); |
| 10093 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10094 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10095 | // Now distribute proportional blame to the apps that did networking. |
| 10096 | long totalPackets = totalRxPackets + totalTxPackets; |
| 10097 | if (totalPackets > 0) { |
| 10098 | for (int i = 0; i < size; i++) { |
| 10099 | entry = delta.getValues(i, entry); |
| 10100 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 10101 | continue; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10102 | } |
| 10103 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10104 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 10105 | |
| 10106 | // Distribute total radio active time in to this app. |
| 10107 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 10108 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 10109 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 10110 | |
| 10111 | // Remove this app from the totals, so that we don't lose any time |
| 10112 | // due to rounding. |
| 10113 | radioTime -= appRadioTime; |
| 10114 | totalPackets -= appPackets; |
| 10115 | |
| 10116 | if (activityInfo != null) { |
| 10117 | ControllerActivityCounterImpl activityCounter = |
| 10118 | u.getOrCreateModemControllerActivityLocked(); |
| 10119 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
| 10120 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 10121 | / totalRxPackets; |
| 10122 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 10123 | } |
| 10124 | |
| 10125 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
| 10126 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 10127 | long txMs = |
| 10128 | entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 10129 | txMs /= totalTxPackets; |
| 10130 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 10131 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10132 | } |
| 10133 | } |
| 10134 | } |
| 10135 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10136 | |
| 10137 | if (radioTime > 0) { |
| 10138 | // Whoops, there is some radio time we can't blame on an app! |
| 10139 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 10140 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 10141 | } |
| 10142 | |
| 10143 | mNetworkStatsPool.release(delta); |
| 10144 | delta = null; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10145 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10146 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10147 | if (activityInfo != null) { |
| 10148 | mHasModemReporting = true; |
| 10149 | mModemActivity.getIdleTimeCounter().addCountLocked( |
| 10150 | activityInfo.getIdleTimeMillis()); |
| 10151 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 10152 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 10153 | mModemActivity.getTxTimeCounters()[lvl] |
| 10154 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 10155 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10156 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10157 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 10158 | final double opVolt = mPowerProfile.getAveragePower( |
| 10159 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 10160 | if (opVolt != 0) { |
| 10161 | // We store the power drain as mAms. |
| 10162 | mModemActivity.getPowerCounter().addCountLocked( |
| 10163 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 10164 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10165 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10166 | } |
| 10167 | } |
| 10168 | |
| 10169 | /** |
| 10170 | * Distribute Bluetooth energy info and network traffic to apps. |
| 10171 | * @param info The energy information from the bluetooth controller. |
| 10172 | */ |
| 10173 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10174 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 10175 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10176 | } |
| 10177 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10178 | if (info == null || !mOnBatteryInternal) { |
| 10179 | return; |
| 10180 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 10181 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10182 | mHasBluetoothReporting = true; |
| 10183 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10184 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10185 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 10186 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 10187 | |
| 10188 | if (DEBUG_ENERGY) { |
| 10189 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 10190 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 10191 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 10192 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 10193 | } |
| 10194 | |
| 10195 | long totalScanTimeMs = 0; |
| 10196 | |
| 10197 | final int uidCount = mUidStats.size(); |
| 10198 | for (int i = 0; i < uidCount; i++) { |
| 10199 | final Uid u = mUidStats.valueAt(i); |
| 10200 | if (u.mBluetoothScanTimer == null) { |
| 10201 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 10202 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 10203 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10204 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10205 | elapsedRealtimeMs * 1000) / 1000; |
| 10206 | } |
| 10207 | |
| 10208 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 10209 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 10210 | |
| 10211 | if (DEBUG_ENERGY) { |
| 10212 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 10213 | + " TX=" + normalizeScanTxTime); |
| 10214 | } |
| 10215 | |
| 10216 | long leftOverRxTimeMs = rxTimeMs; |
| 10217 | long leftOverTxTimeMs = txTimeMs; |
| 10218 | |
| 10219 | for (int i = 0; i < uidCount; i++) { |
| 10220 | final Uid u = mUidStats.valueAt(i); |
| 10221 | if (u.mBluetoothScanTimer == null) { |
| 10222 | continue; |
| 10223 | } |
| 10224 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10225 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10226 | elapsedRealtimeMs * 1000) / 1000; |
| 10227 | if (scanTimeSinceMarkMs > 0) { |
| 10228 | // Set the new mark so that next time we get new data since this point. |
| 10229 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 10230 | |
| 10231 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 10232 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 10233 | |
| 10234 | if (normalizeScanRxTime) { |
| 10235 | // Scan time is longer than the total rx time in the controller, |
| 10236 | // so distribute the scan time proportionately. This means regular traffic |
| 10237 | // will not blamed, but scans are more expensive anyways. |
| 10238 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 10239 | } |
| 10240 | |
| 10241 | if (normalizeScanTxTime) { |
| 10242 | // Scan time is longer than the total tx time in the controller, |
| 10243 | // so distribute the scan time proportionately. This means regular traffic |
| 10244 | // will not blamed, but scans are more expensive anyways. |
| 10245 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 10246 | } |
| 10247 | |
| 10248 | final ControllerActivityCounterImpl counter = |
| 10249 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 10250 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 10251 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 10252 | |
| 10253 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 10254 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 10255 | } |
| 10256 | } |
| 10257 | |
| 10258 | if (DEBUG_ENERGY) { |
| 10259 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 10260 | + " TX=" + leftOverTxTimeMs); |
| 10261 | } |
| 10262 | |
| 10263 | // |
| 10264 | // Now distribute blame to apps that did bluetooth traffic. |
| 10265 | // |
| 10266 | |
| 10267 | long totalTxBytes = 0; |
| 10268 | long totalRxBytes = 0; |
| 10269 | |
| 10270 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 10271 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 10272 | for (int i = 0; i < numUids; i++) { |
| 10273 | final UidTraffic traffic = uidTraffic[i]; |
| 10274 | |
| 10275 | // Add to the global counters. |
| 10276 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 10277 | traffic.getRxBytes()); |
| 10278 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 10279 | traffic.getTxBytes()); |
| 10280 | |
| 10281 | // Add to the UID counters. |
| 10282 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 10283 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 10284 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 10285 | |
| 10286 | // Calculate the total traffic. |
| 10287 | totalTxBytes += traffic.getTxBytes(); |
| 10288 | totalRxBytes += traffic.getRxBytes(); |
| 10289 | } |
| 10290 | |
| 10291 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 10292 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 10293 | for (int i = 0; i < numUids; i++) { |
| 10294 | final UidTraffic traffic = uidTraffic[i]; |
| 10295 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 10296 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10297 | final ControllerActivityCounterImpl counter = |
| 10298 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 10299 | |
| 10300 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 10301 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 10302 | |
| 10303 | if (DEBUG_ENERGY) { |
| 10304 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 10305 | + " rx_time=" + timeRxMs); |
| 10306 | } |
| 10307 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 10308 | leftOverRxTimeMs -= timeRxMs; |
| 10309 | } |
| 10310 | |
| 10311 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 10312 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 10313 | |
| 10314 | if (DEBUG_ENERGY) { |
| 10315 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 10316 | + " tx_time=" + timeTxMs); |
| 10317 | } |
| 10318 | |
| 10319 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 10320 | leftOverTxTimeMs -= timeTxMs; |
| 10321 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 10322 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10323 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10324 | |
| 10325 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 10326 | info.getControllerRxTimeMillis()); |
| 10327 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 10328 | info.getControllerTxTimeMillis()); |
| 10329 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 10330 | info.getControllerIdleTimeMillis()); |
| 10331 | |
| 10332 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 10333 | final double opVolt = mPowerProfile.getAveragePower( |
| 10334 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 10335 | if (opVolt != 0) { |
| 10336 | // We store the power drain as mAms. |
| 10337 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 10338 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 10339 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10340 | } |
| 10341 | |
| 10342 | /** |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 10343 | * Read and record Resource Power Manager (RPM) state and voter times. |
| 10344 | * If RPM stats were fetched more recently than RPM_STATS_UPDATE_FREQ_MS ago, uses the old data |
| 10345 | * instead of fetching it anew. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10346 | */ |
| 10347 | public void updateRpmStatsLocked() { |
| 10348 | if (mPlatformIdleStateCallback == null) return; |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 10349 | long now = SystemClock.elapsedRealtime(); |
| 10350 | if (now - mLastRpmStatsUpdateTimeMs >= RPM_STATS_UPDATE_FREQ_MS) { |
| 10351 | mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats); |
| 10352 | mLastRpmStatsUpdateTimeMs = now; |
| 10353 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10354 | |
| 10355 | for (Map.Entry<String, RpmStats.PowerStatePlatformSleepState> pstate |
| 10356 | : mTmpRpmStats.mPlatformLowPowerStats.entrySet()) { |
| 10357 | |
| 10358 | // Update values for this platform state. |
| 10359 | final String pName = pstate.getKey(); |
| 10360 | final long pTimeUs = pstate.getValue().mTimeMs * 1000; |
| 10361 | final int pCount = pstate.getValue().mCount; |
| 10362 | getRpmTimerLocked(pName).update(pTimeUs, pCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 10363 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 10364 | getScreenOffRpmTimerLocked(pName).update(pTimeUs, pCount); |
| 10365 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10366 | |
| 10367 | // Update values for each voter of this platform state. |
| 10368 | for (Map.Entry<String, RpmStats.PowerStateElement> voter |
| 10369 | : pstate.getValue().mVoters.entrySet()) { |
| 10370 | final String vName = pName + "." + voter.getKey(); |
| 10371 | final long vTimeUs = voter.getValue().mTimeMs * 1000; |
| 10372 | final int vCount = voter.getValue().mCount; |
| 10373 | getRpmTimerLocked(vName).update(vTimeUs, vCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 10374 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 10375 | getScreenOffRpmTimerLocked(vName).update(vTimeUs, vCount); |
| 10376 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10377 | } |
| 10378 | } |
| 10379 | |
| 10380 | for (Map.Entry<String, RpmStats.PowerStateSubsystem> subsys |
| 10381 | : mTmpRpmStats.mSubsystemLowPowerStats.entrySet()) { |
| 10382 | |
| 10383 | final String subsysName = subsys.getKey(); |
| 10384 | for (Map.Entry<String, RpmStats.PowerStateElement> sstate |
| 10385 | : subsys.getValue().mStates.entrySet()) { |
| 10386 | final String name = subsysName + "." + sstate.getKey(); |
| 10387 | final long timeUs = sstate.getValue().mTimeMs * 1000; |
| 10388 | final int count = sstate.getValue().mCount; |
| 10389 | getRpmTimerLocked(name).update(timeUs, count); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 10390 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 10391 | getScreenOffRpmTimerLocked(name).update(timeUs, count); |
| 10392 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10393 | } |
| 10394 | } |
| 10395 | } |
| 10396 | |
| 10397 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10398 | * Read and distribute kernel wake lock use across apps. |
| 10399 | */ |
| 10400 | public void updateKernelWakelocksLocked() { |
| 10401 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 10402 | mTmpWakelockStats); |
| 10403 | if (wakelockStats == null) { |
| 10404 | // Not crashing might make board bringup easier. |
| 10405 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 10406 | return; |
| 10407 | } |
| 10408 | |
| 10409 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 10410 | String name = ent.getKey(); |
| 10411 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 10412 | |
| 10413 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 10414 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 10415 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10416 | mKernelWakelockStats.put(name, kwlt); |
| 10417 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 10418 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 10419 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10420 | kwlt.setUpdateVersion(kws.mVersion); |
| 10421 | } |
| 10422 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 10423 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 10424 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 10425 | // this time. |
| 10426 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10427 | SamplingTimer st = ent.getValue(); |
| 10428 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 10429 | st.endSample(); |
| 10430 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10431 | } |
| 10432 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 10433 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 10434 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 10435 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 10436 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 10437 | } |
| 10438 | |
| 10439 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 10440 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 10441 | wakelockStats.kernelWakelockVersion); |
| 10442 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10443 | } |
| 10444 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10445 | // We use an anonymous class to access these variables, |
| 10446 | // so they can't live on the stack or they'd have to be |
| 10447 | // final MutableLong objects (more allocations). |
| 10448 | // Used in updateCpuTimeLocked(). |
| 10449 | long mTempTotalCpuUserTimeUs; |
| 10450 | long mTempTotalCpuSystemTimeUs; |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10451 | long[][] mWakeLockAllocationsUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10452 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10453 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10454 | * Reads the newest memory stats from the kernel. |
| 10455 | */ |
| 10456 | public void updateKernelMemoryBandwidthLocked() { |
| 10457 | mKernelMemoryBandwidthStats.updateStats(); |
| 10458 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 10459 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 10460 | int index; |
| 10461 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 10462 | SamplingTimer timer; |
| 10463 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 10464 | timer = mKernelMemoryStats.valueAt(index); |
| 10465 | } else { |
| 10466 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 10467 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 10468 | } |
| 10469 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 10470 | if (DEBUG_MEMORY) { |
| 10471 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 10472 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 10473 | mKernelMemoryStats.get( |
| 10474 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 10475 | mKernelMemoryStats.size())); |
| 10476 | } |
| 10477 | } |
| 10478 | } |
| 10479 | |
| 10480 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10481 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 10482 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 10483 | * 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] | 10484 | */ |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10485 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 10486 | if (mPowerProfile == null) { |
| 10487 | return; |
| 10488 | } |
| 10489 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10490 | if (DEBUG_ENERGY_CPU) { |
| 10491 | Slog.d(TAG, "!Cpu updating!"); |
| 10492 | } |
| 10493 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10494 | if (mCpuFreqs == null) { |
| 10495 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 10496 | } |
| 10497 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10498 | // Calculate the wakelocks we have to distribute amongst. The system is excluded as it is |
| 10499 | // usually holding the wakelock on behalf of an app. |
| 10500 | // And Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 10501 | ArrayList<StopwatchTimer> partialTimersToConsider = null; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10502 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10503 | partialTimersToConsider = new ArrayList<>(); |
| 10504 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10505 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10506 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 10507 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 10508 | // the newly added timer for past cpu time, so we only consider timers that |
| 10509 | // were present for one round of collection. Once a timer has gone through |
| 10510 | // a round of collection, its mInList field is set to true. |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10511 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10512 | partialTimersToConsider.add(timer); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10513 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10514 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10515 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10516 | markPartialTimersAsEligible(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10517 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10518 | // When the battery is not on, we don't attribute the cpu times to any timers but we still |
| 10519 | // need to take the snapshots. |
| 10520 | if (!mOnBatteryInternal) { |
| 10521 | mKernelUidCpuTimeReader.readDelta(null); |
| 10522 | mKernelUidCpuFreqTimeReader.readDelta(null); |
| 10523 | for (int cluster = mKernelCpuSpeedReaders.length - 1; cluster >= 0; --cluster) { |
| 10524 | mKernelCpuSpeedReaders[cluster].readDelta(); |
| 10525 | } |
| 10526 | return; |
| 10527 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10528 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10529 | mUserInfoProvider.refreshUserIds(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10530 | final SparseLongArray updatedUids = mKernelUidCpuFreqTimeReader.perClusterTimesAvailable() |
| 10531 | ? null : new SparseLongArray(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10532 | readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10533 | // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu |
| 10534 | // freqs, so no need to approximate these values. |
| 10535 | if (updatedUids != null) { |
| 10536 | updateClusterSpeedTimes(updatedUids); |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 10537 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10538 | readKernelUidCpuFreqTimesLocked(partialTimersToConsider); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10539 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10540 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10541 | /** |
| 10542 | * Mark the current partial timers as gone through a collection so that they will be |
| 10543 | * considered in the next cpu times distribution to wakelock holders. |
| 10544 | */ |
| 10545 | @VisibleForTesting |
| 10546 | public void markPartialTimersAsEligible() { |
| 10547 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 10548 | // No difference, so each timer is now considered for the next collection. |
| 10549 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
| 10550 | mPartialTimers.get(i).mInList = true; |
| 10551 | } |
| 10552 | } else { |
| 10553 | // The lists are different, meaning we added (or removed a timer) since the last |
| 10554 | // collection. |
| 10555 | for (int i = mLastPartialTimers.size() - 1; i >= 0; --i) { |
| 10556 | mLastPartialTimers.get(i).mInList = false; |
| 10557 | } |
| 10558 | mLastPartialTimers.clear(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10559 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10560 | // Mark the current timers as gone through a collection. |
| 10561 | final int numPartialTimers = mPartialTimers.size(); |
| 10562 | for (int i = 0; i < numPartialTimers; ++i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10563 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10564 | timer.mInList = true; |
| 10565 | mLastPartialTimers.add(timer); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10566 | } |
| 10567 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10568 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10569 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10570 | /** |
| 10571 | * Take snapshot of cpu times (aggregated over all uids) at different frequencies and |
| 10572 | * calculate cpu times spent by each uid at different frequencies. |
| 10573 | * |
| 10574 | * @param updatedUids The uids for which times spent at different frequencies are calculated. |
| 10575 | */ |
| 10576 | @VisibleForTesting |
| 10577 | public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10578 | long totalCpuClustersTimeMs = 0; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10579 | // Read the time spent for each cluster at various cpu frequencies. |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10580 | final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10581 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10582 | clusterSpeedTimesMs[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 10583 | if (clusterSpeedTimesMs[cluster] != null) { |
| 10584 | for (int speed = clusterSpeedTimesMs[cluster].length - 1; speed >= 0; --speed) { |
| 10585 | totalCpuClustersTimeMs += clusterSpeedTimesMs[cluster][speed]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10586 | } |
| 10587 | } |
| 10588 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10589 | if (totalCpuClustersTimeMs != 0) { |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10590 | // We have cpu times per freq aggregated over all uids but we need the times per uid. |
| 10591 | // So, we distribute total time spent by an uid to different cpu freqs based on the |
| 10592 | // amount of time cpu was running at that freq. |
| 10593 | final int updatedUidsCount = updatedUids.size(); |
| 10594 | for (int i = 0; i < updatedUidsCount; ++i) { |
| 10595 | final Uid u = getUidStatsLocked(updatedUids.keyAt(i)); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10596 | final long appCpuTimeUs = updatedUids.valueAt(i); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10597 | // Add the cpu speeds to this UID. |
| 10598 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10599 | if (u.mCpuClusterSpeedTimesUs == null || |
| 10600 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10601 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10602 | } |
| 10603 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10604 | for (int cluster = 0; cluster < clusterSpeedTimesMs.length; cluster++) { |
| 10605 | final int speedsInCluster = clusterSpeedTimesMs[cluster].length; |
| 10606 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || speedsInCluster != |
| 10607 | u.mCpuClusterSpeedTimesUs[cluster].length) { |
| 10608 | u.mCpuClusterSpeedTimesUs[cluster] |
| 10609 | = new LongSamplingCounter[speedsInCluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10610 | } |
| 10611 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10612 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeedTimesUs[cluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10613 | for (int speed = 0; speed < speedsInCluster; speed++) { |
| 10614 | if (cpuSpeeds[speed] == null) { |
| 10615 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10616 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 10617 | cpuSpeeds[speed].addCountLocked(appCpuTimeUs |
| 10618 | * clusterSpeedTimesMs[cluster][speed] |
| 10619 | / totalCpuClustersTimeMs); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10620 | } |
| 10621 | } |
| 10622 | } |
| 10623 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10624 | } |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 10625 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10626 | /** |
| 10627 | * Take a snapshot of the cpu times spent by each uid and update the corresponding counters. |
| 10628 | * If {@param partialTimers} is not null and empty, then we assign a portion of cpu times to |
| 10629 | * wakelock holders. |
| 10630 | * |
| 10631 | * @param partialTimers The wakelock holders among which the cpu times will be distributed. |
| 10632 | * @param updatedUids If not null, then the uids found in the snapshot will be added to this. |
| 10633 | */ |
| 10634 | @VisibleForTesting |
| 10635 | public void readKernelUidCpuTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
| 10636 | @Nullable SparseLongArray updatedUids) { |
| 10637 | mTempTotalCpuUserTimeUs = mTempTotalCpuSystemTimeUs = 0; |
| 10638 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 10639 | final long startTimeMs = mClocks.uptimeMillis(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10640 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10641 | mKernelUidCpuTimeReader.readDelta((uid, userTimeUs, systemTimeUs) -> { |
| 10642 | uid = mapUid(uid); |
| 10643 | if (Process.isIsolated(uid)) { |
| 10644 | // This could happen if the isolated uid mapping was removed before that process |
| 10645 | // was actually killed. |
| 10646 | mKernelUidCpuTimeReader.removeUid(uid); |
| 10647 | Slog.d(TAG, "Got readings for an isolated uid with no mapping: " + uid); |
| 10648 | return; |
| 10649 | } |
| 10650 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 10651 | Slog.d(TAG, "Got readings for an invalid user's uid " + uid); |
| 10652 | mKernelUidCpuTimeReader.removeUid(uid); |
| 10653 | return; |
| 10654 | } |
| 10655 | final Uid u = getUidStatsLocked(uid); |
| 10656 | |
| 10657 | // Accumulate the total system and user time. |
| 10658 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 10659 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 10660 | |
| 10661 | StringBuilder sb = null; |
| 10662 | if (DEBUG_ENERGY_CPU) { |
| 10663 | sb = new StringBuilder(); |
| 10664 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 10665 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 10666 | sb.append(" s="); |
| 10667 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 10668 | sb.append("\n"); |
| 10669 | } |
| 10670 | |
| 10671 | if (numWakelocks > 0) { |
| 10672 | // We have wakelocks being held, so only give a portion of the |
| 10673 | // time to the process. The rest will be distributed among wakelock |
| 10674 | // holders. |
| 10675 | userTimeUs = (userTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 10676 | systemTimeUs = (systemTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 10677 | } |
| 10678 | |
| 10679 | if (sb != null) { |
| 10680 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 10681 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 10682 | sb.append(" s="); |
| 10683 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 10684 | Slog.d(TAG, sb.toString()); |
| 10685 | } |
| 10686 | |
| 10687 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 10688 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 10689 | if (updatedUids != null) { |
| 10690 | updatedUids.put(u.getUid(), userTimeUs + systemTimeUs); |
| 10691 | } |
| 10692 | }); |
| 10693 | |
| 10694 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 10695 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 10696 | Slog.d(TAG, "Reading cpu stats took " + elapsedTimeMs + "ms"); |
| 10697 | } |
| 10698 | |
| 10699 | if (numWakelocks > 0) { |
| 10700 | // Distribute a portion of the total cpu time to wakelock holders. |
| 10701 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 10702 | mTempTotalCpuSystemTimeUs = |
| 10703 | (mTempTotalCpuSystemTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 10704 | |
| 10705 | for (int i = 0; i < numWakelocks; ++i) { |
| 10706 | final StopwatchTimer timer = partialTimers.get(i); |
| 10707 | final int userTimeUs = (int) (mTempTotalCpuUserTimeUs / (numWakelocks - i)); |
| 10708 | final int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / (numWakelocks - i)); |
| 10709 | |
| 10710 | if (DEBUG_ENERGY_CPU) { |
| 10711 | final StringBuilder sb = new StringBuilder(); |
| 10712 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 10713 | .append(": u="); |
| 10714 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 10715 | sb.append(" s="); |
| 10716 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 10717 | Slog.d(TAG, sb.toString()); |
| 10718 | } |
| 10719 | |
| 10720 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 10721 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 10722 | if (updatedUids != null) { |
| 10723 | final int uid = timer.mUid.getUid(); |
| 10724 | updatedUids.put(uid, updatedUids.get(uid, 0) + userTimeUs + systemTimeUs); |
| 10725 | } |
| 10726 | |
| 10727 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
| 10728 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
| 10729 | |
| 10730 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 10731 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10732 | } |
| 10733 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10734 | } |
| 10735 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10736 | /** |
| 10737 | * Take a snapshot of the cpu times spent by each uid in each freq and update the |
| 10738 | * corresponding counters. |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10739 | * |
| 10740 | * @param partialTimers The wakelock holders among which the cpu freq times will be distributed. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10741 | */ |
| 10742 | @VisibleForTesting |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10743 | public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers) { |
| 10744 | final boolean perClusterTimesAvailable = |
| 10745 | mKernelUidCpuFreqTimeReader.perClusterTimesAvailable(); |
| 10746 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 10747 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 10748 | mWakeLockAllocationsUs = null; |
| 10749 | mKernelUidCpuFreqTimeReader.readDelta((uid, cpuFreqTimeMs) -> { |
| 10750 | uid = mapUid(uid); |
| 10751 | if (Process.isIsolated(uid)) { |
| 10752 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 10753 | Slog.d(TAG, "Got freq readings for an isolated uid with no mapping: " + uid); |
| 10754 | return; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10755 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10756 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 10757 | Slog.d(TAG, "Got freq readings for an invalid user's uid " + uid); |
| 10758 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 10759 | return; |
| 10760 | } |
| 10761 | final Uid u = getUidStatsLocked(uid); |
| 10762 | if (u.mCpuFreqTimeMs == null || u.mCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 10763 | u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase); |
| 10764 | } |
| 10765 | u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs); |
| 10766 | if (u.mScreenOffCpuFreqTimeMs == null || |
| 10767 | u.mScreenOffCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 10768 | u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray( |
| 10769 | mOnBatteryScreenOffTimeBase); |
| 10770 | } |
| 10771 | u.mScreenOffCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10772 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10773 | if (perClusterTimesAvailable) { |
| 10774 | if (u.mCpuClusterSpeedTimesUs == null || |
| 10775 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 10776 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10777 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10778 | if (numWakelocks > 0 && mWakeLockAllocationsUs == null) { |
| 10779 | mWakeLockAllocationsUs = new long[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10780 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10781 | |
| 10782 | int freqIndex = 0; |
| 10783 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 10784 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 10785 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 10786 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 10787 | u.mCpuClusterSpeedTimesUs[cluster] |
| 10788 | = new LongSamplingCounter[speedsInCluster]; |
| 10789 | } |
| 10790 | if (numWakelocks > 0 && mWakeLockAllocationsUs[cluster] == null) { |
| 10791 | mWakeLockAllocationsUs[cluster] = new long[speedsInCluster]; |
| 10792 | } |
| 10793 | final LongSamplingCounter[] cpuTimesUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 10794 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 10795 | if (cpuTimesUs[speed] == null) { |
| 10796 | cpuTimesUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10797 | } |
| 10798 | final long appAllocationUs; |
| 10799 | if (mWakeLockAllocationsUs != null) { |
| 10800 | appAllocationUs = |
| 10801 | (cpuFreqTimeMs[freqIndex] * 1000 * WAKE_LOCK_WEIGHT) / 100; |
| 10802 | mWakeLockAllocationsUs[cluster][speed] += |
| 10803 | (cpuFreqTimeMs[freqIndex] * 1000 - appAllocationUs); |
| 10804 | } else { |
| 10805 | appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000; |
| 10806 | } |
| 10807 | cpuTimesUs[speed].addCountLocked(appAllocationUs); |
| 10808 | freqIndex++; |
| 10809 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10810 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 10811 | } |
| 10812 | }); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 10813 | |
| 10814 | if (mWakeLockAllocationsUs != null) { |
| 10815 | for (int i = 0; i < numWakelocks; ++i) { |
| 10816 | final Uid u = partialTimers.get(i).mUid; |
| 10817 | if (u.mCpuClusterSpeedTimesUs == null || |
| 10818 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 10819 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
| 10820 | } |
| 10821 | |
| 10822 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 10823 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 10824 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 10825 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 10826 | u.mCpuClusterSpeedTimesUs[cluster] |
| 10827 | = new LongSamplingCounter[speedsInCluster]; |
| 10828 | } |
| 10829 | final LongSamplingCounter[] cpuTimeUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 10830 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 10831 | if (cpuTimeUs[speed] == null) { |
| 10832 | cpuTimeUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10833 | } |
| 10834 | final long allocationUs = |
| 10835 | mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i); |
| 10836 | cpuTimeUs[speed].addCountLocked(allocationUs); |
| 10837 | mWakeLockAllocationsUs[cluster][speed] -= allocationUs; |
| 10838 | } |
| 10839 | } |
| 10840 | } |
| 10841 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10842 | } |
| 10843 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10844 | boolean setChargingLocked(boolean charging) { |
| 10845 | if (mCharging != charging) { |
| 10846 | mCharging = charging; |
| 10847 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10848 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10849 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10850 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10851 | } |
| 10852 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 10853 | return true; |
| 10854 | } |
| 10855 | return false; |
| 10856 | } |
| 10857 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10858 | protected void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, |
| 10859 | final boolean onBattery, final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10860 | boolean doWrite = false; |
| 10861 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 10862 | m.arg1 = onBattery ? 1 : 0; |
| 10863 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10864 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10865 | final long uptime = mSecUptime * 1000; |
| 10866 | final long realtime = mSecRealtime * 1000; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10867 | final int screenState = mScreenState; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10868 | if (onBattery) { |
| 10869 | // We will reset our status if we are unplugging after the |
| 10870 | // battery was last full, or the level is at 100, or |
| 10871 | // we have gone through a significant charge (from a very low |
| 10872 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10873 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 10874 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10875 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 10876 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 10877 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 10878 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 10879 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 10880 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 10881 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 10882 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10883 | // Before we write, collect a snapshot of the final aggregated |
| 10884 | // stats to be reported in the next checkin. Only do this if we have |
| 10885 | // a sufficient amount of data to make it interesting. |
| 10886 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 10887 | final Parcel parcel = Parcel.obtain(); |
| 10888 | writeSummaryToParcel(parcel, true); |
| 10889 | BackgroundThread.getHandler().post(new Runnable() { |
| 10890 | @Override public void run() { |
| 10891 | synchronized (mCheckinFile) { |
| 10892 | FileOutputStream stream = null; |
| 10893 | try { |
| 10894 | stream = mCheckinFile.startWrite(); |
| 10895 | stream.write(parcel.marshall()); |
| 10896 | stream.flush(); |
| 10897 | FileUtils.sync(stream); |
| 10898 | stream.close(); |
| 10899 | mCheckinFile.finishWrite(stream); |
| 10900 | } catch (IOException e) { |
| 10901 | Slog.w("BatteryStats", |
| 10902 | "Error writing checkin battery statistics", e); |
| 10903 | mCheckinFile.failWrite(stream); |
| 10904 | } finally { |
| 10905 | parcel.recycle(); |
| 10906 | } |
| 10907 | } |
| 10908 | } |
| 10909 | }); |
| 10910 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10911 | doWrite = true; |
| 10912 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 10913 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10914 | // Only use the reported coulomb charge value if it is supported and reported. |
Ying Wai (Daniel) Fan | 9238b61 | 2017-01-18 15:50:19 -0800 | [diff] [blame] | 10915 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10916 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10917 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10918 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10919 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10920 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10921 | if (mCharging) { |
| 10922 | setChargingLocked(false); |
| 10923 | } |
| 10924 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10925 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10926 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10927 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10928 | mDischargeStepTracker.clearTime(); |
| 10929 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10930 | mInitStepMode = mCurStepMode; |
| 10931 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10932 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10933 | mHistoryCur.batteryLevel = (byte)level; |
| 10934 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 10935 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 10936 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10937 | if (reset) { |
| 10938 | mRecordingHistory = true; |
| 10939 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 10940 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10941 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10942 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10943 | if (isScreenOn(screenState)) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10944 | mDischargeScreenOnUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10945 | mDischargeScreenDozeUnplugLevel = 0; |
| 10946 | mDischargeScreenOffUnplugLevel = 0; |
| 10947 | } else if (isScreenDoze(screenState)) { |
| 10948 | mDischargeScreenOnUnplugLevel = 0; |
| 10949 | mDischargeScreenDozeUnplugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10950 | mDischargeScreenOffUnplugLevel = 0; |
| 10951 | } else { |
| 10952 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10953 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10954 | mDischargeScreenOffUnplugLevel = level; |
| 10955 | } |
| 10956 | mDischargeAmountScreenOn = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10957 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10958 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10959 | updateTimeBasesLocked(true, screenState, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10960 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10961 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10962 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10963 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10964 | mHistoryCur.batteryLevel = (byte)level; |
| 10965 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 10966 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 10967 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10968 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10969 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10970 | if (level < mDischargeUnplugLevel) { |
| 10971 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 10972 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 10973 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10974 | updateDischargeScreenLevelsLocked(screenState, screenState); |
| 10975 | updateTimeBasesLocked(false, screenState, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10976 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10977 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10978 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10979 | mInitStepMode = mCurStepMode; |
| 10980 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10981 | } |
| 10982 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 10983 | if (mFile != null) { |
| 10984 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10985 | } |
| 10986 | } |
| 10987 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10988 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10989 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 10990 | boolean reset) { |
| 10991 | mRecordingHistory = true; |
| 10992 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10993 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 10994 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10995 | mHistoryCur); |
| 10996 | mHistoryCur.currentTime = 0; |
| 10997 | if (reset) { |
| 10998 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 10999 | } |
| 11000 | } |
| 11001 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11002 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 11003 | final long uptimeMs) { |
| 11004 | if (mRecordingHistory) { |
| 11005 | mHistoryCur.currentTime = currentTime; |
| 11006 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 11007 | mHistoryCur); |
| 11008 | mHistoryCur.currentTime = 0; |
| 11009 | } |
| 11010 | } |
| 11011 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 11012 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 11013 | if (mRecordingHistory) { |
| 11014 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 11015 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 11016 | mHistoryCur); |
| 11017 | mHistoryCur.currentTime = 0; |
| 11018 | } |
| 11019 | } |
| 11020 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11021 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11022 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11023 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11024 | } |
| 11025 | } |
| 11026 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11027 | // 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] | 11028 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11029 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11030 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 11031 | int temp, int volt, int chargeUAh, int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 11032 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 11033 | temp = Math.max(0, temp); |
| 11034 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11035 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11036 | final long uptime = mClocks.uptimeMillis(); |
| 11037 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11038 | if (!mHaveBatteryLevel) { |
| 11039 | mHaveBatteryLevel = true; |
| 11040 | // We start out assuming that the device is plugged in (not |
| 11041 | // on battery). If our first report is now that we are indeed |
| 11042 | // plugged in, then twiddle our state to correctly reflect that |
| 11043 | // since we won't be going through the full setOnBattery(). |
| 11044 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11045 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11046 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11047 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11048 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11049 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11050 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 11051 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11052 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11053 | mHistoryCur.batteryStatus = (byte)status; |
| 11054 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11055 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11056 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 11057 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 11058 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11059 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 11060 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 11061 | } |
| 11062 | int oldStatus = mHistoryCur.batteryStatus; |
| 11063 | if (onBattery) { |
| 11064 | mDischargeCurrentLevel = level; |
| 11065 | if (!mRecordingHistory) { |
| 11066 | mRecordingHistory = true; |
| 11067 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 11068 | } |
| 11069 | } else if (level < 96) { |
| 11070 | if (!mRecordingHistory) { |
| 11071 | mRecordingHistory = true; |
| 11072 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11073 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11074 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11075 | mCurrentBatteryLevel = level; |
| 11076 | if (mDischargePlugLevel < 0) { |
| 11077 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 11078 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 11079 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11080 | if (onBattery != mOnBattery) { |
| 11081 | mHistoryCur.batteryLevel = (byte)level; |
| 11082 | mHistoryCur.batteryStatus = (byte)status; |
| 11083 | mHistoryCur.batteryHealth = (byte)health; |
| 11084 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 11085 | mHistoryCur.batteryTemperature = (short)temp; |
| 11086 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11087 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 11088 | // Only record discharges |
| 11089 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 11090 | mDischargeCounter.addCountLocked(chargeDiff); |
| 11091 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11092 | if (isScreenDoze(mScreenState)) { |
| 11093 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 11094 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11095 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 11096 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11097 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11098 | } else { |
| 11099 | boolean changed = false; |
| 11100 | if (mHistoryCur.batteryLevel != level) { |
| 11101 | mHistoryCur.batteryLevel = (byte)level; |
| 11102 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 11103 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11104 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 11105 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11106 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11107 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11108 | if (mHistoryCur.batteryStatus != status) { |
| 11109 | mHistoryCur.batteryStatus = (byte)status; |
| 11110 | changed = true; |
| 11111 | } |
| 11112 | if (mHistoryCur.batteryHealth != health) { |
| 11113 | mHistoryCur.batteryHealth = (byte)health; |
| 11114 | changed = true; |
| 11115 | } |
| 11116 | if (mHistoryCur.batteryPlugType != plugType) { |
| 11117 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 11118 | changed = true; |
| 11119 | } |
| 11120 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 11121 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 11122 | mHistoryCur.batteryTemperature = (short)temp; |
| 11123 | changed = true; |
| 11124 | } |
| 11125 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 11126 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 11127 | mHistoryCur.batteryVoltage = (char)volt; |
| 11128 | changed = true; |
| 11129 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 11130 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 11131 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11132 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 11133 | // Only record discharges |
| 11134 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 11135 | mDischargeCounter.addCountLocked(chargeDiff); |
| 11136 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11137 | if (isScreenDoze(mScreenState)) { |
| 11138 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 11139 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11140 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 11141 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 11142 | changed = true; |
| 11143 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11144 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 11145 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 11146 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 11147 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 11148 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11149 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 11150 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 11151 | modeBits, elapsedRealtime); |
| 11152 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 11153 | modeBits, elapsedRealtime); |
| 11154 | mLastDischargeStepLevel = level; |
| 11155 | mMinDischargeStepLevel = level; |
| 11156 | mInitStepMode = mCurStepMode; |
| 11157 | mModStepMode = 0; |
| 11158 | } |
| 11159 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 11160 | if (level >= 90) { |
| 11161 | // If the battery level is at least 90%, always consider the device to be |
| 11162 | // charging even if it happens to go down a level. |
| 11163 | changed |= setChargingLocked(true); |
| 11164 | mLastChargeStepLevel = level; |
| 11165 | } if (!mCharging) { |
| 11166 | if (mLastChargeStepLevel < level) { |
| 11167 | // We have not reporting that we are charging, but the level has now |
| 11168 | // gone up, so consider the state to be charging. |
| 11169 | changed |= setChargingLocked(true); |
| 11170 | mLastChargeStepLevel = level; |
| 11171 | } |
| 11172 | } else { |
| 11173 | if (mLastChargeStepLevel > level) { |
| 11174 | // We had reported that the device was charging, but here we are with |
| 11175 | // power connected and the level going down. Looks like the current |
| 11176 | // power supplied isn't enough, so consider the device to now be |
| 11177 | // discharging. |
| 11178 | changed |= setChargingLocked(false); |
| 11179 | mLastChargeStepLevel = level; |
| 11180 | } |
| 11181 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11182 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 11183 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 11184 | modeBits, elapsedRealtime); |
| 11185 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 11186 | modeBits, elapsedRealtime); |
| 11187 | mLastChargeStepLevel = level; |
| 11188 | mMaxChargeStepLevel = level; |
| 11189 | mInitStepMode = mCurStepMode; |
| 11190 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11191 | } |
| 11192 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 11193 | if (changed) { |
| 11194 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11195 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11196 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11197 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 11198 | // We don't record history while we are plugged in and fully charged. |
| 11199 | // The next time we are unplugged, history will be cleared. |
| 11200 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 11201 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 11202 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 11203 | if (mMinLearnedBatteryCapacity == -1) { |
| 11204 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 11205 | } else { |
| 11206 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 11207 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 11208 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 11209 | } |
| 11210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11211 | public long getAwakeTimeBattery() { |
| 11212 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 11213 | } |
| 11214 | |
| 11215 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11216 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11217 | } |
| 11218 | |
| 11219 | @Override |
| 11220 | public long computeUptime(long curTime, int which) { |
| 11221 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11222 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11223 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 11224 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11225 | } |
| 11226 | return 0; |
| 11227 | } |
| 11228 | |
| 11229 | @Override |
| 11230 | public long computeRealtime(long curTime, int which) { |
| 11231 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11232 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11233 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 11234 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11235 | } |
| 11236 | return 0; |
| 11237 | } |
| 11238 | |
| 11239 | @Override |
| 11240 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11241 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11242 | } |
| 11243 | |
| 11244 | @Override |
| 11245 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11246 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11247 | } |
| 11248 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11249 | @Override |
| 11250 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 11251 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 11252 | } |
| 11253 | |
| 11254 | @Override |
| 11255 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 11256 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11257 | } |
| 11258 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11259 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 11260 | // For now we'll do a simple average across all steps. |
| 11261 | if (numSteps <= 0) { |
| 11262 | return -1; |
| 11263 | } |
| 11264 | long total = 0; |
| 11265 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11266 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11267 | } |
| 11268 | return total / numSteps; |
| 11269 | /* |
| 11270 | long[] buckets = new long[numSteps]; |
| 11271 | int numBuckets = 0; |
| 11272 | int numToAverage = 4; |
| 11273 | int i = 0; |
| 11274 | while (i < numSteps) { |
| 11275 | long totalTime = 0; |
| 11276 | int num = 0; |
| 11277 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11278 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11279 | num++; |
| 11280 | } |
| 11281 | buckets[numBuckets] = totalTime / num; |
| 11282 | numBuckets++; |
| 11283 | numToAverage *= 2; |
| 11284 | i += num; |
| 11285 | } |
| 11286 | if (numBuckets < 1) { |
| 11287 | return -1; |
| 11288 | } |
| 11289 | long averageTime = buckets[numBuckets-1]; |
| 11290 | for (i=numBuckets-2; i>=0; i--) { |
| 11291 | averageTime = (averageTime + buckets[i]) / 2; |
| 11292 | } |
| 11293 | return averageTime; |
| 11294 | */ |
| 11295 | } |
| 11296 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11297 | @Override |
| 11298 | public long computeBatteryTimeRemaining(long curTime) { |
| 11299 | if (!mOnBattery) { |
| 11300 | return -1; |
| 11301 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11302 | /* Simple implementation just looks at the average discharge per level across the |
| 11303 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11304 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 11305 | if (discharge < 2) { |
| 11306 | return -1; |
| 11307 | } |
| 11308 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 11309 | if (duration < 1000*1000) { |
| 11310 | return -1; |
| 11311 | } |
| 11312 | long usPerLevel = duration/discharge; |
| 11313 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11314 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11315 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11316 | return -1; |
| 11317 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11318 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11319 | if (msPerLevel <= 0) { |
| 11320 | return -1; |
| 11321 | } |
| 11322 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11323 | } |
| 11324 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11325 | @Override |
| 11326 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 11327 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 11328 | } |
| 11329 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11330 | @Override |
| 11331 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 11332 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 11333 | } |
| 11334 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11335 | @Override |
| 11336 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11337 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11338 | // Not yet working. |
| 11339 | return -1; |
| 11340 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11341 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11342 | int curLevel = mCurrentBatteryLevel; |
| 11343 | int plugLevel = mDischargePlugLevel; |
| 11344 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 11345 | return -1; |
| 11346 | } |
| 11347 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 11348 | if (duration < 1000*1000) { |
| 11349 | return -1; |
| 11350 | } |
| 11351 | long usPerLevel = duration/(curLevel-plugLevel); |
| 11352 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11353 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11354 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11355 | return -1; |
| 11356 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11357 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 11358 | if (msPerLevel <= 0) { |
| 11359 | return -1; |
| 11360 | } |
| 11361 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11362 | } |
| 11363 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11364 | @Override |
| 11365 | public LevelStepTracker getChargeLevelStepTracker() { |
| 11366 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 11367 | } |
| 11368 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11369 | @Override |
| 11370 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 11371 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 11372 | } |
| 11373 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11374 | @Override |
| 11375 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 11376 | return mDailyPackageChanges; |
| 11377 | } |
| 11378 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 11379 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11380 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11381 | } |
| 11382 | |
| 11383 | @Override |
| 11384 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11385 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11386 | } |
| 11387 | |
| 11388 | @Override |
| 11389 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11390 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11391 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 11392 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11393 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11394 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11395 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11396 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11397 | } |
| 11398 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11399 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11400 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11401 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11402 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11403 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11404 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11405 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11406 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11407 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11408 | } |
| 11409 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11410 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11411 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 11412 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11413 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11414 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11415 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11416 | public int getLowDischargeAmountSinceCharge() { |
| 11417 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 11418 | int val = mLowDischargeAmountSinceCharge; |
| 11419 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 11420 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 11421 | } |
| 11422 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11423 | } |
| 11424 | } |
| 11425 | |
| 11426 | @Override |
| 11427 | public int getHighDischargeAmountSinceCharge() { |
| 11428 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 11429 | int val = mHighDischargeAmountSinceCharge; |
| 11430 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 11431 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 11432 | } |
| 11433 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11434 | } |
| 11435 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11436 | |
| 11437 | @Override |
| 11438 | public int getDischargeAmount(int which) { |
| 11439 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 11440 | ? getHighDischargeAmountSinceCharge() |
| 11441 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 11442 | if (dischargeAmount < 0) { |
| 11443 | dischargeAmount = 0; |
| 11444 | } |
| 11445 | return dischargeAmount; |
| 11446 | } |
| 11447 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11448 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11449 | public int getDischargeAmountScreenOn() { |
| 11450 | synchronized(this) { |
| 11451 | int val = mDischargeAmountScreenOn; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11452 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11453 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 11454 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 11455 | } |
| 11456 | return val; |
| 11457 | } |
| 11458 | } |
| 11459 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11460 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11461 | public int getDischargeAmountScreenOnSinceCharge() { |
| 11462 | synchronized(this) { |
| 11463 | int val = mDischargeAmountScreenOnSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11464 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11465 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 11466 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 11467 | } |
| 11468 | return val; |
| 11469 | } |
| 11470 | } |
| 11471 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11472 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11473 | public int getDischargeAmountScreenOff() { |
| 11474 | synchronized(this) { |
| 11475 | int val = mDischargeAmountScreenOff; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11476 | if (mOnBattery && isScreenOff(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11477 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 11478 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 11479 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11480 | // For backward compatibility, doze discharge is counted into screen off. |
| 11481 | return val + getDischargeAmountScreenDoze(); |
| 11482 | } |
| 11483 | } |
| 11484 | |
| 11485 | @Override |
| 11486 | public int getDischargeAmountScreenOffSinceCharge() { |
| 11487 | synchronized(this) { |
| 11488 | int val = mDischargeAmountScreenOffSinceCharge; |
| 11489 | if (mOnBattery && isScreenOff(mScreenState) |
| 11490 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 11491 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 11492 | } |
| 11493 | // For backward compatibility, doze discharge is counted into screen off. |
| 11494 | return val + getDischargeAmountScreenDozeSinceCharge(); |
| 11495 | } |
| 11496 | } |
| 11497 | |
| 11498 | @Override |
| 11499 | public int getDischargeAmountScreenDoze() { |
| 11500 | synchronized(this) { |
| 11501 | int val = mDischargeAmountScreenDoze; |
| 11502 | if (mOnBattery && isScreenDoze(mScreenState) |
| 11503 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 11504 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
| 11505 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11506 | return val; |
| 11507 | } |
| 11508 | } |
| 11509 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11510 | @Override |
| 11511 | public int getDischargeAmountScreenDozeSinceCharge() { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11512 | synchronized(this) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11513 | int val = mDischargeAmountScreenDozeSinceCharge; |
| 11514 | if (mOnBattery && isScreenDoze(mScreenState) |
| 11515 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 11516 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11517 | } |
| 11518 | return val; |
| 11519 | } |
| 11520 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11522 | /** |
| 11523 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 11524 | */ |
| 11525 | public Uid getUidStatsLocked(int uid) { |
| 11526 | Uid u = mUidStats.get(uid); |
| 11527 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11528 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11529 | mUidStats.put(uid, u); |
| 11530 | } |
| 11531 | return u; |
| 11532 | } |
| 11533 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 11534 | public void onCleanupUserLocked(int userId) { |
| 11535 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 11536 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 11537 | mKernelUidCpuFreqTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 11538 | mKernelUidCpuTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 11539 | } |
| 11540 | |
| 11541 | public void onUserRemovedLocked(int userId) { |
| 11542 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 11543 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 11544 | mUidStats.put(firstUidForUser, null); |
| 11545 | mUidStats.put(lastUidForUser, null); |
| 11546 | final int firstIndex = mUidStats.indexOfKey(firstUidForUser); |
| 11547 | final int lastIndex = mUidStats.indexOfKey(lastUidForUser); |
| 11548 | mUidStats.removeAtRange(firstIndex, lastIndex - firstIndex + 1); |
| 11549 | } |
| 11550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11551 | /** |
| 11552 | * Remove the statistics object for a particular uid. |
| 11553 | */ |
| 11554 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 11555 | mKernelUidCpuTimeReader.removeUid(uid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 11556 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11557 | mUidStats.remove(uid); |
| 11558 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 11559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11560 | /** |
| 11561 | * Retrieve the statistics object for a particular process, creating |
| 11562 | * if needed. |
| 11563 | */ |
| 11564 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 11565 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11566 | Uid u = getUidStatsLocked(uid); |
| 11567 | return u.getProcessStatsLocked(name); |
| 11568 | } |
| 11569 | |
| 11570 | /** |
| 11571 | * Retrieve the statistics object for a particular process, creating |
| 11572 | * if needed. |
| 11573 | */ |
| 11574 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 11575 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11576 | Uid u = getUidStatsLocked(uid); |
| 11577 | return u.getPackageStatsLocked(pkg); |
| 11578 | } |
| 11579 | |
| 11580 | /** |
| 11581 | * Retrieve the statistics object for a particular service, creating |
| 11582 | * if needed. |
| 11583 | */ |
| 11584 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 11585 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11586 | Uid u = getUidStatsLocked(uid); |
| 11587 | return u.getServiceStatsLocked(pkg, name); |
| 11588 | } |
| 11589 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11590 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11591 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11592 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11593 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11594 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11595 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11596 | Parcel mPendingWrite = null; |
| 11597 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 11598 | |
| 11599 | public void writeAsyncLocked() { |
| 11600 | writeLocked(false); |
| 11601 | } |
| 11602 | |
| 11603 | public void writeSyncLocked() { |
| 11604 | writeLocked(true); |
| 11605 | } |
| 11606 | |
| 11607 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11608 | if (mFile == null) { |
| 11609 | 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] | 11610 | return; |
| 11611 | } |
| 11612 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11613 | if (mShuttingDown) { |
| 11614 | return; |
| 11615 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11616 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11617 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11618 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11619 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11620 | |
| 11621 | if (mPendingWrite != null) { |
| 11622 | mPendingWrite.recycle(); |
| 11623 | } |
| 11624 | mPendingWrite = out; |
| 11625 | |
| 11626 | if (sync) { |
| 11627 | commitPendingDataToDisk(); |
| 11628 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11629 | BackgroundThread.getHandler().post(new Runnable() { |
| 11630 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11631 | commitPendingDataToDisk(); |
| 11632 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11633 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11634 | } |
| 11635 | } |
| 11636 | |
| 11637 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 11638 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11639 | synchronized (this) { |
| 11640 | next = mPendingWrite; |
| 11641 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 11642 | if (next == null) { |
| 11643 | return; |
| 11644 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11645 | } |
| 11646 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 11647 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11648 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11649 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11650 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11651 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 11652 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11653 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11654 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11655 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11656 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11657 | mFile.rollback(); |
| 11658 | } finally { |
| 11659 | next.recycle(); |
| 11660 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 11661 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11662 | } |
| 11663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11664 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11665 | if (mDailyFile != null) { |
| 11666 | readDailyStatsLocked(); |
| 11667 | } |
| 11668 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11669 | if (mFile == null) { |
| 11670 | 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] | 11671 | return; |
| 11672 | } |
| 11673 | |
| 11674 | mUidStats.clear(); |
| 11675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11676 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11677 | File file = mFile.chooseForRead(); |
| 11678 | if (!file.exists()) { |
| 11679 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11680 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11681 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11682 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11683 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11684 | Parcel in = Parcel.obtain(); |
| 11685 | in.unmarshall(raw, 0, raw.length); |
| 11686 | in.setDataPosition(0); |
| 11687 | stream.close(); |
| 11688 | |
| 11689 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 11690 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11691 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11692 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11693 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11694 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11695 | mEndPlatformVersion = Build.ID; |
| 11696 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 11697 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11698 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11699 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 11700 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 11701 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11702 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 11703 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11704 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 11705 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 11706 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11707 | |
| 11708 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11709 | } |
| 11710 | |
| 11711 | public int describeContents() { |
| 11712 | return 0; |
| 11713 | } |
| 11714 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11715 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11716 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11717 | |
| 11718 | mHistoryBuffer.setDataSize(0); |
| 11719 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11720 | mHistoryTagPool.clear(); |
| 11721 | mNextHistoryTagIdx = 0; |
| 11722 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11723 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11724 | int numTags = in.readInt(); |
| 11725 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11726 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11727 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11728 | if (str == null) { |
| 11729 | throw new ParcelFormatException("null history tag string"); |
| 11730 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11731 | int uid = in.readInt(); |
| 11732 | HistoryTag tag = new HistoryTag(); |
| 11733 | tag.string = str; |
| 11734 | tag.uid = uid; |
| 11735 | tag.poolIdx = idx; |
| 11736 | mHistoryTagPool.put(tag, idx); |
| 11737 | if (idx >= mNextHistoryTagIdx) { |
| 11738 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11739 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11740 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11741 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11742 | |
| 11743 | int bufSize = in.readInt(); |
| 11744 | int curPos = in.dataPosition(); |
| 11745 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11746 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 11747 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11748 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11749 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 11750 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11751 | } else { |
| 11752 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 11753 | + " bytes at " + curPos); |
| 11754 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 11755 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11756 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11757 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11758 | if (andOldHistory) { |
| 11759 | readOldHistory(in); |
| 11760 | } |
| 11761 | |
| 11762 | if (DEBUG_HISTORY) { |
| 11763 | StringBuilder sb = new StringBuilder(128); |
| 11764 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 11765 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 11766 | Slog.i(TAG, sb.toString()); |
| 11767 | } |
| 11768 | mHistoryBaseTime = historyBaseTime; |
| 11769 | if (DEBUG_HISTORY) { |
| 11770 | StringBuilder sb = new StringBuilder(128); |
| 11771 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 11772 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 11773 | Slog.i(TAG, sb.toString()); |
| 11774 | } |
| 11775 | |
| 11776 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 11777 | // the last run until samples in this run. |
| 11778 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11779 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11780 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11781 | if (DEBUG_HISTORY) { |
| 11782 | StringBuilder sb = new StringBuilder(128); |
| 11783 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 11784 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 11785 | Slog.i(TAG, sb.toString()); |
| 11786 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 11787 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11788 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11789 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11790 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 11791 | if (!USE_OLD_HISTORY) { |
| 11792 | return; |
| 11793 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11794 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 11795 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 11796 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11797 | HistoryItem rec = new HistoryItem(time, in); |
| 11798 | addHistoryRecordLocked(rec); |
| 11799 | } |
| 11800 | } |
| 11801 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11802 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11803 | if (DEBUG_HISTORY) { |
| 11804 | StringBuilder sb = new StringBuilder(128); |
| 11805 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 11806 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11807 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 11808 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11809 | Slog.i(TAG, sb.toString()); |
| 11810 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11811 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11812 | if (!inclData) { |
| 11813 | out.writeInt(0); |
| 11814 | out.writeInt(0); |
| 11815 | return; |
| 11816 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11817 | out.writeInt(mHistoryTagPool.size()); |
| 11818 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 11819 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11820 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11821 | out.writeString(tag.string); |
| 11822 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11823 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11824 | out.writeInt(mHistoryBuffer.dataSize()); |
| 11825 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 11826 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 11827 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11828 | |
| 11829 | if (andOldHistory) { |
| 11830 | writeOldHistory(out); |
| 11831 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11832 | } |
| 11833 | |
| 11834 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 11835 | if (!USE_OLD_HISTORY) { |
| 11836 | return; |
| 11837 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11838 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11839 | while (rec != null) { |
| 11840 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 11841 | rec = rec.next; |
| 11842 | } |
| 11843 | out.writeLong(-1); |
| 11844 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11845 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11846 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11847 | final int version = in.readInt(); |
| 11848 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11849 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11850 | + ", expected " + VERSION + "; erasing old stats"); |
| 11851 | return; |
| 11852 | } |
| 11853 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11854 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11856 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11857 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11858 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11859 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11860 | mStartPlatformVersion = in.readString(); |
| 11861 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11862 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 11863 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11864 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11865 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11866 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11867 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11868 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 11869 | mMinLearnedBatteryCapacity = in.readInt(); |
| 11870 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11871 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 11872 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11873 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 11874 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11875 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11876 | mDischargeStepTracker.readFromParcel(in); |
| 11877 | mChargeStepTracker.readFromParcel(in); |
| 11878 | mDailyDischargeStepTracker.readFromParcel(in); |
| 11879 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11880 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 11881 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11882 | mDischargeScreenDozeCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11883 | int NPKG = in.readInt(); |
| 11884 | if (NPKG > 0) { |
| 11885 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 11886 | while (NPKG > 0) { |
| 11887 | NPKG--; |
| 11888 | PackageChange pc = new PackageChange(); |
| 11889 | pc.mPackageName = in.readString(); |
| 11890 | pc.mUpdate = in.readInt() != 0; |
| 11891 | pc.mVersionCode = in.readInt(); |
| 11892 | mDailyPackageChanges.add(pc); |
| 11893 | } |
| 11894 | } else { |
| 11895 | mDailyPackageChanges = null; |
| 11896 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11897 | mDailyStartTime = in.readLong(); |
| 11898 | mNextMinDailyDeadline = in.readLong(); |
| 11899 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11901 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11902 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11903 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11904 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11905 | mScreenDozeTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11906 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 11907 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 11908 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11909 | mInteractive = false; |
| 11910 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11911 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11912 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11913 | mLongestLightIdleTime = in.readLong(); |
| 11914 | mLongestFullIdleTime = in.readLong(); |
| 11915 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 11916 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 11917 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11918 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11919 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11920 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11921 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 11922 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11923 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11924 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 11925 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 11926 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11927 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11928 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 11929 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11930 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11931 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11932 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11933 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11934 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11935 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 11936 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11937 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11938 | mWifiOn = false; |
| 11939 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11940 | mGlobalWifiRunning = false; |
| 11941 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11942 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11943 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 11944 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11945 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11946 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 11947 | } |
| 11948 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11949 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 11950 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11951 | mWifiActivity.readSummaryFromParcel(in); |
| 11952 | mBluetoothActivity.readSummaryFromParcel(in); |
| 11953 | mModemActivity.readSummaryFromParcel(in); |
| 11954 | mHasWifiReporting = in.readInt() != 0; |
| 11955 | mHasBluetoothReporting = in.readInt() != 0; |
| 11956 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 11957 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11958 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11959 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11960 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11961 | mCameraOnNesting = 0; |
| 11962 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11963 | mBluetoothScanNesting = 0; |
| 11964 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11965 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11966 | int NRPMS = in.readInt(); |
| 11967 | if (NRPMS > 10000) { |
| 11968 | throw new ParcelFormatException("File corrupt: too many rpm stats " + NRPMS); |
| 11969 | } |
| 11970 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 11971 | if (in.readInt() != 0) { |
| 11972 | String rpmName = in.readString(); |
| 11973 | getRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 11974 | } |
| 11975 | } |
| 11976 | int NSORPMS = in.readInt(); |
| 11977 | if (NSORPMS > 10000) { |
| 11978 | throw new ParcelFormatException("File corrupt: too many screen-off rpm stats " + NSORPMS); |
| 11979 | } |
| 11980 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 11981 | if (in.readInt() != 0) { |
| 11982 | String rpmName = in.readString(); |
| 11983 | getScreenOffRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 11984 | } |
| 11985 | } |
| 11986 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11987 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11988 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11989 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11990 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11991 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 11992 | if (in.readInt() != 0) { |
| 11993 | String kwltName = in.readString(); |
| 11994 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 11995 | } |
| 11996 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11997 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11998 | int NWR = in.readInt(); |
| 11999 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12000 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12001 | } |
| 12002 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 12003 | if (in.readInt() != 0) { |
| 12004 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12005 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12006 | } |
| 12007 | } |
| 12008 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 12009 | int NMS = in.readInt(); |
| 12010 | for (int ims = 0; ims < NMS; ims++) { |
| 12011 | if (in.readInt() != 0) { |
| 12012 | long kmstName = in.readLong(); |
| 12013 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 12014 | } |
| 12015 | } |
| 12016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12017 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12018 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12019 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12020 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12021 | for (int iu = 0; iu < NU; iu++) { |
| 12022 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12023 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12024 | mUidStats.put(uid, u); |
| 12025 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 12026 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 12027 | u.mOnBatteryScreenOffBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 12028 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12029 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12030 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12031 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12032 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12033 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12034 | if (in.readInt() != 0) { |
| 12035 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 12036 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 12037 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12038 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 12039 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12040 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 12041 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 12042 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 12043 | if (in.readInt() != 0) { |
| 12044 | u.makeWifiBatchedScanBin(i, null); |
| 12045 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 12046 | } |
| 12047 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 12048 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12049 | if (in.readInt() != 0) { |
| 12050 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 12051 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12052 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 12053 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12054 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12055 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 12056 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 12057 | } |
| 12058 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12059 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 12060 | } |
| 12061 | if (in.readInt() != 0) { |
| 12062 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 12063 | } |
| 12064 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 12065 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 12066 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12067 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 12068 | u.createForegroundServiceTimerLocked().readSummaryFromParcelLocked(in); |
| 12069 | } |
| 12070 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 12071 | u.createAggregatedPartialWakelockTimerLocked().readSummaryFromParcelLocked(in); |
| 12072 | } |
| 12073 | if (in.readInt() != 0) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12074 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 12075 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 12076 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 12077 | u.createBluetoothUnoptimizedScanTimerLocked().readSummaryFromParcelLocked(in); |
| 12078 | } |
| 12079 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 12080 | u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in); |
| 12081 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 12082 | if (in.readInt() != 0) { |
| 12083 | u.createBluetoothScanResultBgCounterLocked().readSummaryFromParcelLocked(in); |
| 12084 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 12085 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12086 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 12087 | if (in.readInt() != 0) { |
| 12088 | u.makeProcessState(i, null); |
| 12089 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 12090 | } |
| 12091 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 12092 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 12093 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12094 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 12095 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 12096 | if (in.readInt() != 0) { |
| 12097 | if (u.mUserActivityCounters == null) { |
| 12098 | u.initUserActivityLocked(); |
| 12099 | } |
| 12100 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 12101 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 12102 | } |
| 12103 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12104 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12105 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 12106 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12107 | u.initNetworkActivityLocked(); |
| 12108 | } |
| 12109 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 12110 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 12111 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12112 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 12113 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 12114 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12115 | } |
| 12116 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12117 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 12118 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 12119 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12120 | if (in.readInt() != 0) { |
| 12121 | final int numClusters = in.readInt(); |
| 12122 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 12123 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12124 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12125 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12126 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12127 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12128 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 12129 | final int NSB = in.readInt(); |
| 12130 | if (mPowerProfile != null && |
| 12131 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 12132 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 12133 | NSB); |
| 12134 | } |
| 12135 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12136 | u.mCpuClusterSpeedTimesUs[cluster] = new LongSamplingCounter[NSB]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12137 | for (int speed = 0; speed < NSB; speed++) { |
| 12138 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12139 | u.mCpuClusterSpeedTimesUs[cluster][speed] = new LongSamplingCounter( |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12140 | mOnBatteryTimeBase); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12141 | u.mCpuClusterSpeedTimesUs[cluster][speed].readSummaryFromParcelLocked(in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12142 | } |
| 12143 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 12144 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12145 | u.mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12146 | } |
| 12147 | } |
| 12148 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12149 | u.mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12150 | } |
| 12151 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 12152 | u.mCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 12153 | in, mOnBatteryTimeBase); |
| 12154 | u.mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 12155 | in, mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12156 | |
| 12157 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 12158 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12159 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 12160 | } else { |
| 12161 | u.mMobileRadioApWakeupCount = null; |
| 12162 | } |
| 12163 | |
| 12164 | if (in.readInt() != 0) { |
| 12165 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12166 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 12167 | } else { |
| 12168 | u.mWifiRadioApWakeupCount = null; |
| 12169 | } |
| 12170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12171 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 12172 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12173 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12175 | for (int iw = 0; iw < NW; iw++) { |
| 12176 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12177 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12178 | } |
| 12179 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12180 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 12181 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12182 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12183 | } |
| 12184 | for (int is = 0; is < NS; is++) { |
| 12185 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12186 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12187 | } |
| 12188 | |
| 12189 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 12190 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12191 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12192 | } |
| 12193 | for (int ij = 0; ij < NJ; ij++) { |
| 12194 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12195 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12196 | } |
| 12197 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 12198 | u.readJobCompletionsFromParcelLocked(in); |
| 12199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12200 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 12201 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12202 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12203 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12204 | for (int is = 0; is < NP; is++) { |
| 12205 | int seNumber = in.readInt(); |
| 12206 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 12207 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12208 | } |
| 12209 | } |
| 12210 | |
| 12211 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 12212 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12213 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12215 | for (int ip = 0; ip < NP; ip++) { |
| 12216 | String procName = in.readString(); |
| 12217 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 12218 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12219 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 12220 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12221 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12222 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 12223 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12224 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12225 | } |
| 12226 | |
| 12227 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12228 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12229 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 12230 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12231 | for (int ip = 0; ip < NP; ip++) { |
| 12232 | String pkgName = in.readString(); |
| 12233 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12234 | final int NWA = in.readInt(); |
| 12235 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12236 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12237 | } |
| 12238 | p.mWakeupAlarms.clear(); |
| 12239 | for (int iwa=0; iwa<NWA; iwa++) { |
| 12240 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 12241 | Counter c = new Counter(mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12242 | c.readSummaryFromParcelLocked(in); |
| 12243 | p.mWakeupAlarms.put(tag, c); |
| 12244 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12245 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 12246 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 12247 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 12248 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12249 | for (int is = 0; is < NS; is++) { |
| 12250 | String servName = in.readString(); |
| 12251 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 12252 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12253 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12254 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12255 | } |
| 12256 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12257 | } |
| 12258 | } |
| 12259 | |
| 12260 | /** |
| 12261 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 12262 | * disk. This format does not allow a lossless round-trip. |
| 12263 | * |
| 12264 | * @param out the Parcel to be written to. |
| 12265 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12266 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 12267 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12268 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12269 | // Pull the clock time. This may update the time and make a new history entry |
| 12270 | // if we had originally pulled a time before the RTC was set. |
| 12271 | long startClockTime = getStartClockTime(); |
| 12272 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12273 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 12274 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12275 | |
| 12276 | out.writeInt(VERSION); |
| 12277 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12278 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12280 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12281 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12282 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12283 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 12284 | out.writeString(mStartPlatformVersion); |
| 12285 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12286 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 12287 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12288 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12289 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12290 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12291 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12292 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12293 | out.writeInt(mMinLearnedBatteryCapacity); |
| 12294 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 12295 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 12296 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 12297 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 12298 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12299 | out.writeInt(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12300 | mDischargeStepTracker.writeToParcel(out); |
| 12301 | mChargeStepTracker.writeToParcel(out); |
| 12302 | mDailyDischargeStepTracker.writeToParcel(out); |
| 12303 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 12304 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 12305 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12306 | mDischargeScreenDozeCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 12307 | if (mDailyPackageChanges != null) { |
| 12308 | final int NPKG = mDailyPackageChanges.size(); |
| 12309 | out.writeInt(NPKG); |
| 12310 | for (int i=0; i<NPKG; i++) { |
| 12311 | PackageChange pc = mDailyPackageChanges.get(i); |
| 12312 | out.writeString(pc.mPackageName); |
| 12313 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 12314 | out.writeInt(pc.mVersionCode); |
| 12315 | } |
| 12316 | } else { |
| 12317 | out.writeInt(0); |
| 12318 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12319 | out.writeLong(mDailyStartTime); |
| 12320 | out.writeLong(mNextMinDailyDeadline); |
| 12321 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12322 | |
| 12323 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12324 | mScreenDozeTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 12325 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12326 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 12327 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 12328 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 12329 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 12330 | out.writeLong(mLongestLightIdleTime); |
| 12331 | out.writeLong(mLongestFullIdleTime); |
| 12332 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12333 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12334 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 12335 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12336 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 12337 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12338 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 12339 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12340 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 12341 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12342 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 12343 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12344 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 12345 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 12346 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12347 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12348 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12349 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12350 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 12351 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 12352 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12353 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12354 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 12355 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12356 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 12357 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12358 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 12359 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12360 | } |
| 12361 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 12362 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12363 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 12364 | mWifiActivity.writeSummaryToParcel(out); |
| 12365 | mBluetoothActivity.writeSummaryToParcel(out); |
| 12366 | mModemActivity.writeSummaryToParcel(out); |
| 12367 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 12368 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 12369 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 12370 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12371 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 12372 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12373 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12374 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12375 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 12376 | out.writeInt(mRpmStats.size()); |
| 12377 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 12378 | Timer rpmt = ent.getValue(); |
| 12379 | if (rpmt != null) { |
| 12380 | out.writeInt(1); |
| 12381 | out.writeString(ent.getKey()); |
| 12382 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12383 | } else { |
| 12384 | out.writeInt(0); |
| 12385 | } |
| 12386 | } |
| 12387 | out.writeInt(mScreenOffRpmStats.size()); |
| 12388 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 12389 | Timer rpmt = ent.getValue(); |
| 12390 | if (rpmt != null) { |
| 12391 | out.writeInt(1); |
| 12392 | out.writeString(ent.getKey()); |
| 12393 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12394 | } else { |
| 12395 | out.writeInt(0); |
| 12396 | } |
| 12397 | } |
| 12398 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12399 | out.writeInt(mKernelWakelockStats.size()); |
| 12400 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 12401 | Timer kwlt = ent.getValue(); |
| 12402 | if (kwlt != null) { |
| 12403 | out.writeInt(1); |
| 12404 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12405 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12406 | } else { |
| 12407 | out.writeInt(0); |
| 12408 | } |
| 12409 | } |
| 12410 | |
| 12411 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12412 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 12413 | SamplingTimer timer = ent.getValue(); |
| 12414 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12415 | out.writeInt(1); |
| 12416 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12417 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12418 | } else { |
| 12419 | out.writeInt(0); |
| 12420 | } |
| 12421 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12422 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 12423 | out.writeInt(mKernelMemoryStats.size()); |
| 12424 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 12425 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 12426 | if (kmt != null) { |
| 12427 | out.writeInt(1); |
| 12428 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 12429 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12430 | } else { |
| 12431 | out.writeInt(0); |
| 12432 | } |
| 12433 | } |
| 12434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12435 | final int NU = mUidStats.size(); |
| 12436 | out.writeInt(NU); |
| 12437 | for (int iu = 0; iu < NU; iu++) { |
| 12438 | out.writeInt(mUidStats.keyAt(iu)); |
| 12439 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12440 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 12441 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 12442 | u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 12443 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12444 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12445 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12446 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12447 | } else { |
| 12448 | out.writeInt(0); |
| 12449 | } |
| 12450 | if (u.mFullWifiLockTimer != null) { |
| 12451 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12452 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12453 | } else { |
| 12454 | out.writeInt(0); |
| 12455 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 12456 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12457 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12458 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12459 | } else { |
| 12460 | out.writeInt(0); |
| 12461 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 12462 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 12463 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 12464 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12465 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 12466 | } else { |
| 12467 | out.writeInt(0); |
| 12468 | } |
| 12469 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12470 | if (u.mWifiMulticastTimer != null) { |
| 12471 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12472 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12473 | } else { |
| 12474 | out.writeInt(0); |
| 12475 | } |
| 12476 | if (u.mAudioTurnedOnTimer != null) { |
| 12477 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12478 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12479 | } else { |
| 12480 | out.writeInt(0); |
| 12481 | } |
| 12482 | if (u.mVideoTurnedOnTimer != null) { |
| 12483 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12484 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12485 | } else { |
| 12486 | out.writeInt(0); |
| 12487 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12488 | if (u.mFlashlightTurnedOnTimer != null) { |
| 12489 | out.writeInt(1); |
| 12490 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12491 | } else { |
| 12492 | out.writeInt(0); |
| 12493 | } |
| 12494 | if (u.mCameraTurnedOnTimer != null) { |
| 12495 | out.writeInt(1); |
| 12496 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12497 | } else { |
| 12498 | out.writeInt(0); |
| 12499 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 12500 | if (u.mForegroundActivityTimer != null) { |
| 12501 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12502 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 12503 | } else { |
| 12504 | out.writeInt(0); |
| 12505 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 12506 | if (u.mForegroundServiceTimer != null) { |
| 12507 | out.writeInt(1); |
| 12508 | u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12509 | } else { |
| 12510 | out.writeInt(0); |
| 12511 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 12512 | if (u.mAggregatedPartialWakelockTimer != null) { |
| 12513 | out.writeInt(1); |
| 12514 | u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12515 | } else { |
| 12516 | out.writeInt(0); |
| 12517 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12518 | if (u.mBluetoothScanTimer != null) { |
| 12519 | out.writeInt(1); |
| 12520 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12521 | } else { |
| 12522 | out.writeInt(0); |
| 12523 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 12524 | if (u.mBluetoothUnoptimizedScanTimer != null) { |
| 12525 | out.writeInt(1); |
| 12526 | u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12527 | } else { |
| 12528 | out.writeInt(0); |
| 12529 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 12530 | if (u.mBluetoothScanResultCounter != null) { |
| 12531 | out.writeInt(1); |
| 12532 | u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out); |
| 12533 | } else { |
| 12534 | out.writeInt(0); |
| 12535 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 12536 | if (u.mBluetoothScanResultBgCounter != null) { |
| 12537 | out.writeInt(1); |
| 12538 | u.mBluetoothScanResultBgCounter.writeSummaryFromParcelLocked(out); |
| 12539 | } else { |
| 12540 | out.writeInt(0); |
| 12541 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12542 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 12543 | if (u.mProcessStateTimer[i] != null) { |
| 12544 | out.writeInt(1); |
| 12545 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12546 | } else { |
| 12547 | out.writeInt(0); |
| 12548 | } |
| 12549 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 12550 | if (u.mVibratorOnTimer != null) { |
| 12551 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12552 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 12553 | } else { |
| 12554 | out.writeInt(0); |
| 12555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12556 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 12557 | if (u.mUserActivityCounters == null) { |
| 12558 | out.writeInt(0); |
| 12559 | } else { |
| 12560 | out.writeInt(1); |
| 12561 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 12562 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 12563 | } |
| 12564 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12565 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 12566 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12567 | out.writeInt(0); |
| 12568 | } else { |
| 12569 | out.writeInt(1); |
| 12570 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 12571 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 12572 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12573 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 12574 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 12575 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 12576 | } |
| 12577 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12578 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 12579 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 12580 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12581 | if (u.mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12582 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12583 | out.writeInt(u.mCpuClusterSpeedTimesUs.length); |
| 12584 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12585 | if (cpuSpeeds != null) { |
| 12586 | out.writeInt(1); |
| 12587 | out.writeInt(cpuSpeeds.length); |
| 12588 | for (LongSamplingCounter c : cpuSpeeds) { |
| 12589 | if (c != null) { |
| 12590 | out.writeInt(1); |
| 12591 | c.writeSummaryFromParcelLocked(out); |
| 12592 | } else { |
| 12593 | out.writeInt(0); |
| 12594 | } |
| 12595 | } |
| 12596 | } else { |
| 12597 | out.writeInt(0); |
| 12598 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12599 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12600 | } else { |
| 12601 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12602 | } |
| 12603 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 12604 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mCpuFreqTimeMs); |
| 12605 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12606 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 12607 | if (u.mMobileRadioApWakeupCount != null) { |
| 12608 | out.writeInt(1); |
| 12609 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 12610 | } else { |
| 12611 | out.writeInt(0); |
| 12612 | } |
| 12613 | |
| 12614 | if (u.mWifiRadioApWakeupCount != null) { |
| 12615 | out.writeInt(1); |
| 12616 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 12617 | } else { |
| 12618 | out.writeInt(0); |
| 12619 | } |
| 12620 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12621 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 12622 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12623 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12624 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12625 | out.writeString(wakeStats.keyAt(iw)); |
| 12626 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12627 | if (wl.mTimerFull != null) { |
| 12628 | out.writeInt(1); |
| 12629 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12630 | } else { |
| 12631 | out.writeInt(0); |
| 12632 | } |
| 12633 | if (wl.mTimerPartial != null) { |
| 12634 | out.writeInt(1); |
| 12635 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12636 | } else { |
| 12637 | out.writeInt(0); |
| 12638 | } |
| 12639 | if (wl.mTimerWindow != null) { |
| 12640 | out.writeInt(1); |
| 12641 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12642 | } else { |
| 12643 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12644 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 12645 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 12646 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 12647 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 12648 | } else { |
| 12649 | out.writeInt(0); |
| 12650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12651 | } |
| 12652 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 12653 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12654 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12655 | out.writeInt(NS); |
| 12656 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12657 | out.writeString(syncStats.keyAt(is)); |
| 12658 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12659 | } |
| 12660 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 12661 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12662 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12663 | out.writeInt(NJ); |
| 12664 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12665 | out.writeString(jobStats.keyAt(ij)); |
| 12666 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12667 | } |
| 12668 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 12669 | u.writeJobCompletionsToParcelLocked(out); |
| 12670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12671 | int NSE = u.mSensorStats.size(); |
| 12672 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12673 | for (int ise=0; ise<NSE; ise++) { |
| 12674 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 12675 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 12676 | if (se.mTimer != null) { |
| 12677 | out.writeInt(1); |
| 12678 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12679 | } else { |
| 12680 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12681 | } |
| 12682 | } |
| 12683 | |
| 12684 | int NP = u.mProcessStats.size(); |
| 12685 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12686 | for (int ip=0; ip<NP; ip++) { |
| 12687 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 12688 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 12689 | out.writeLong(ps.mUserTime); |
| 12690 | out.writeLong(ps.mSystemTime); |
| 12691 | out.writeLong(ps.mForegroundTime); |
| 12692 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12693 | out.writeInt(ps.mNumCrashes); |
| 12694 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12695 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12696 | } |
| 12697 | |
| 12698 | NP = u.mPackageStats.size(); |
| 12699 | out.writeInt(NP); |
| 12700 | if (NP > 0) { |
| 12701 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 12702 | : u.mPackageStats.entrySet()) { |
| 12703 | out.writeString(ent.getKey()); |
| 12704 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12705 | final int NWA = ps.mWakeupAlarms.size(); |
| 12706 | out.writeInt(NWA); |
| 12707 | for (int iwa=0; iwa<NWA; iwa++) { |
| 12708 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 12709 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 12710 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12711 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12712 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12713 | for (int is=0; is<NS; is++) { |
| 12714 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 12715 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 12716 | long time = ss.getStartTimeToNowLocked( |
| 12717 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 12718 | out.writeLong(time); |
| 12719 | out.writeInt(ss.mStarts); |
| 12720 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12721 | } |
| 12722 | } |
| 12723 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12724 | } |
| 12725 | } |
| 12726 | |
| 12727 | public void readFromParcel(Parcel in) { |
| 12728 | readFromParcelLocked(in); |
| 12729 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12731 | void readFromParcelLocked(Parcel in) { |
| 12732 | int magic = in.readInt(); |
| 12733 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12734 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12735 | } |
| 12736 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 12737 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12739 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 12740 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 12741 | mStartPlatformVersion = in.readString(); |
| 12742 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12743 | mUptime = in.readLong(); |
| 12744 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12745 | mRealtime = in.readLong(); |
| 12746 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12747 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12748 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12749 | mMinLearnedBatteryCapacity = in.readInt(); |
| 12750 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12751 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12752 | mOnBatteryTimeBase.readFromParcel(in); |
| 12753 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 12754 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 12755 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12756 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12757 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12758 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12759 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 12760 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12761 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12762 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12763 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12764 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12765 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 12766 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 12767 | mLongestLightIdleTime = in.readLong(); |
| 12768 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12769 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 12770 | mOnBatteryTimeBase, in); |
| 12771 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 12772 | mOnBatteryTimeBase, in); |
| 12773 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 12774 | mOnBatteryTimeBase, in); |
| 12775 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 12776 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12777 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12778 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12779 | null, mOnBatteryTimeBase, in); |
| 12780 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12781 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 12782 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12783 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12784 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12785 | null, mOnBatteryTimeBase, in); |
| 12786 | } |
| 12787 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 12788 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12789 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12790 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12791 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12792 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 12793 | mOnBatteryTimeBase, in); |
| 12794 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 12795 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12796 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12797 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12798 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12799 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12800 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12801 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12802 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12803 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 12804 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12805 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12806 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12807 | null, mOnBatteryTimeBase, in); |
| 12808 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12809 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12810 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12811 | null, mOnBatteryTimeBase, in); |
| 12812 | } |
| 12813 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12814 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12815 | null, mOnBatteryTimeBase, in); |
| 12816 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 12817 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 12818 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 12819 | NUM_WIFI_TX_LEVELS, in); |
| 12820 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 12821 | NUM_BT_TX_LEVELS, in); |
| 12822 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 12823 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 12824 | mHasWifiReporting = in.readInt() != 0; |
| 12825 | mHasBluetoothReporting = in.readInt() != 0; |
| 12826 | mHasModemReporting = in.readInt() != 0; |
| 12827 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12828 | mNumConnectivityChange = in.readInt(); |
| 12829 | mLoadedNumConnectivityChange = in.readInt(); |
| 12830 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 12831 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12832 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 12833 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12834 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12835 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12836 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12837 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12838 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12839 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12840 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12841 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12842 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12843 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12844 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12845 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 12846 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 12847 | mDischargeAmountScreenOn = in.readInt(); |
| 12848 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 12849 | mDischargeAmountScreenOff = in.readInt(); |
| 12850 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12851 | mDischargeAmountScreenDoze = in.readInt(); |
| 12852 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12853 | mDischargeStepTracker.readFromParcel(in); |
| 12854 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12855 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12856 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, in); |
| 12857 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12858 | mLastWriteTime = in.readLong(); |
| 12859 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 12860 | mRpmStats.clear(); |
| 12861 | int NRPMS = in.readInt(); |
| 12862 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 12863 | if (in.readInt() != 0) { |
| 12864 | String rpmName = in.readString(); |
| 12865 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 12866 | mRpmStats.put(rpmName, rpmt); |
| 12867 | } |
| 12868 | } |
| 12869 | mScreenOffRpmStats.clear(); |
| 12870 | int NSORPMS = in.readInt(); |
| 12871 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 12872 | if (in.readInt() != 0) { |
| 12873 | String rpmName = in.readString(); |
| 12874 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
| 12875 | mScreenOffRpmStats.put(rpmName, rpmt); |
| 12876 | } |
| 12877 | } |
| 12878 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12879 | mKernelWakelockStats.clear(); |
| 12880 | int NKW = in.readInt(); |
| 12881 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 12882 | if (in.readInt() != 0) { |
| 12883 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12884 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12885 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 12886 | } |
| 12887 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12888 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12889 | mWakeupReasonStats.clear(); |
| 12890 | int NWR = in.readInt(); |
| 12891 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 12892 | if (in.readInt() != 0) { |
| 12893 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12894 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12895 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12896 | } |
| 12897 | } |
| 12898 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 12899 | mKernelMemoryStats.clear(); |
| 12900 | int nmt = in.readInt(); |
| 12901 | for (int imt = 0; imt < nmt; imt++) { |
| 12902 | if (in.readInt() != 0) { |
| 12903 | Long bucket = in.readLong(); |
| 12904 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 12905 | mKernelMemoryStats.put(bucket, kmt); |
| 12906 | } |
| 12907 | } |
| 12908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12909 | mPartialTimers.clear(); |
| 12910 | mFullTimers.clear(); |
| 12911 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12912 | mWifiRunningTimers.clear(); |
| 12913 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 12914 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 12915 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12916 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 12917 | mAudioTurnedOnTimers.clear(); |
| 12918 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12919 | mFlashlightTurnedOnTimers.clear(); |
| 12920 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12921 | |
| 12922 | int numUids = in.readInt(); |
| 12923 | mUidStats.clear(); |
| 12924 | for (int i = 0; i < numUids; i++) { |
| 12925 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12926 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12927 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12928 | mUidStats.append(uid, u); |
| 12929 | } |
| 12930 | } |
| 12931 | |
| 12932 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12933 | writeToParcelLocked(out, true, flags); |
| 12934 | } |
| 12935 | |
| 12936 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 12937 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12938 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12939 | |
| 12940 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12941 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12942 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12943 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12944 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12945 | // Pull the clock time. This may update the time and make a new history entry |
| 12946 | // if we had originally pulled a time before the RTC was set. |
| 12947 | long startClockTime = getStartClockTime(); |
| 12948 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12949 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 12950 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12951 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 12952 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12954 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12955 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12956 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12958 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12959 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 12960 | out.writeString(mStartPlatformVersion); |
| 12961 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12962 | out.writeLong(mUptime); |
| 12963 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12964 | out.writeLong(mRealtime); |
| 12965 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12966 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12967 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12968 | out.writeInt(mMinLearnedBatteryCapacity); |
| 12969 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12970 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 12971 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 12972 | |
| 12973 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12974 | mScreenDozeTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12975 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 12976 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 12977 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 12978 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 12979 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 12980 | out.writeLong(mLongestLightIdleTime); |
| 12981 | out.writeLong(mLongestFullIdleTime); |
| 12982 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 12983 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 12984 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 12985 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12986 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 12987 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 12988 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 12989 | } |
| 12990 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 12991 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 12992 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 12993 | } |
| 12994 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 12995 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 12996 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 12997 | } |
| 12998 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 12999 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13000 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13001 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 13002 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 13003 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 13004 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 13005 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13006 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 13007 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13008 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13009 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 13010 | } |
| 13011 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13012 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 13013 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 13014 | mWifiActivity.writeToParcel(out, 0); |
| 13015 | mBluetoothActivity.writeToParcel(out, 0); |
| 13016 | mModemActivity.writeToParcel(out, 0); |
| 13017 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 13018 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 13019 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 13020 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 13021 | out.writeInt(mNumConnectivityChange); |
| 13022 | out.writeInt(mLoadedNumConnectivityChange); |
| 13023 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 13024 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13025 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13026 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13027 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13028 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13029 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13030 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13031 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 13032 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13033 | out.writeInt(mDischargeAmountScreenOn); |
| 13034 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 13035 | out.writeInt(mDischargeAmountScreenOff); |
| 13036 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13037 | out.writeInt(mDischargeAmountScreenDoze); |
| 13038 | out.writeInt(mDischargeAmountScreenDozeSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13039 | mDischargeStepTracker.writeToParcel(out); |
| 13040 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 13041 | mDischargeCounter.writeToParcel(out); |
| 13042 | mDischargeScreenOffCounter.writeToParcel(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13043 | mDischargeScreenDozeCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13044 | out.writeLong(mLastWriteTime); |
| 13045 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 13046 | out.writeInt(mRpmStats.size()); |
| 13047 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 13048 | SamplingTimer rpmt = ent.getValue(); |
| 13049 | if (rpmt != null) { |
| 13050 | out.writeInt(1); |
| 13051 | out.writeString(ent.getKey()); |
| 13052 | rpmt.writeToParcel(out, uSecRealtime); |
| 13053 | } else { |
| 13054 | out.writeInt(0); |
| 13055 | } |
| 13056 | } |
| 13057 | out.writeInt(mScreenOffRpmStats.size()); |
| 13058 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 13059 | SamplingTimer rpmt = ent.getValue(); |
| 13060 | if (rpmt != null) { |
| 13061 | out.writeInt(1); |
| 13062 | out.writeString(ent.getKey()); |
| 13063 | rpmt.writeToParcel(out, uSecRealtime); |
| 13064 | } else { |
| 13065 | out.writeInt(0); |
| 13066 | } |
| 13067 | } |
| 13068 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13069 | if (inclUids) { |
| 13070 | out.writeInt(mKernelWakelockStats.size()); |
| 13071 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 13072 | SamplingTimer kwlt = ent.getValue(); |
| 13073 | if (kwlt != null) { |
| 13074 | out.writeInt(1); |
| 13075 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13076 | kwlt.writeToParcel(out, uSecRealtime); |
| 13077 | } else { |
| 13078 | out.writeInt(0); |
| 13079 | } |
| 13080 | } |
| 13081 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 13082 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 13083 | SamplingTimer timer = ent.getValue(); |
| 13084 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13085 | out.writeInt(1); |
| 13086 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 13087 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13088 | } else { |
| 13089 | out.writeInt(0); |
| 13090 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13091 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13092 | } else { |
Bookatz | ba78b2b | 2017-10-10 11:06:33 -0700 | [diff] [blame^] | 13093 | out.writeInt(0); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13094 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13095 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13096 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 13097 | out.writeInt(mKernelMemoryStats.size()); |
| 13098 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 13099 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 13100 | if (kmt != null) { |
| 13101 | out.writeInt(1); |
| 13102 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 13103 | kmt.writeToParcel(out, uSecRealtime); |
| 13104 | } else { |
| 13105 | out.writeInt(0); |
| 13106 | } |
| 13107 | } |
| 13108 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13109 | if (inclUids) { |
| 13110 | int size = mUidStats.size(); |
| 13111 | out.writeInt(size); |
| 13112 | for (int i = 0; i < size; i++) { |
| 13113 | out.writeInt(mUidStats.keyAt(i)); |
| 13114 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13115 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13116 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13117 | } |
| 13118 | } else { |
| 13119 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13120 | } |
| 13121 | } |
| 13122 | |
| 13123 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 13124 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 13125 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 13126 | return new BatteryStatsImpl(in); |
| 13127 | } |
| 13128 | |
| 13129 | public BatteryStatsImpl[] newArray(int size) { |
| 13130 | return new BatteryStatsImpl[size]; |
| 13131 | } |
| 13132 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13133 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13134 | public void prepareForDumpLocked() { |
| 13135 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 13136 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 13137 | |
| 13138 | // Pull the clock time. This may update the time and make a new history entry |
| 13139 | // if we had originally pulled a time before the RTC was set. |
| 13140 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13141 | } |
| 13142 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 13143 | 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] | 13144 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13145 | pw.println("mOnBatteryTimeBase:"); |
| 13146 | mOnBatteryTimeBase.dump(pw, " "); |
| 13147 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 13148 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13149 | Printer pr = new PrintWriterPrinter(pw); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13150 | pr.println("*** Screen on timer:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13151 | mScreenOnTimer.logState(pr, " "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13152 | pr.println("*** Screen doze timer:"); |
| 13153 | mScreenDozeTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13154 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13155 | pr.println("*** Screen brightness #" + i + ":"); |
| 13156 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13157 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13158 | pr.println("*** Interactive timer:"); |
| 13159 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 13160 | pr.println("*** Power save mode timer:"); |
| 13161 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 13162 | pr.println("*** Device idle mode light timer:"); |
| 13163 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 13164 | pr.println("*** Device idle mode full timer:"); |
| 13165 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 13166 | pr.println("*** Device light idling timer:"); |
| 13167 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13168 | pr.println("*** Device idling timer:"); |
| 13169 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13170 | pr.println("*** Phone timer:"); |
| 13171 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 13172 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13173 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13174 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13175 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 13176 | pr.println("*** Signal scanning :"); |
| 13177 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13178 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13179 | pr.println("*** Data connection type #" + i + ":"); |
| 13180 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13181 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13182 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 13183 | pr.println("*** Mobile network active timer:"); |
| 13184 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13185 | pr.println("*** Mobile network active adjusted timer:"); |
| 13186 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 13187 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 13188 | pr.println("*** Wifi timer:"); |
| 13189 | mWifiOnTimer.logState(pr, " "); |
| 13190 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13191 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 13192 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13193 | pr.println("*** Wifi state #" + i + ":"); |
| 13194 | mWifiStateTimer[i].logState(pr, " "); |
| 13195 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13196 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13197 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 13198 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 13199 | } |
| 13200 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13201 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 13202 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 13203 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 13204 | pr.println("*** Flashlight timer:"); |
| 13205 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13206 | pr.println("*** Camera timer:"); |
| 13207 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13208 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 13209 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13211 | } |